@o3co/create-auth-provider 0.16.0 → 0.17.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +66 -21
- package/README.md +76 -31
- package/dist/index.d.mts +33 -10
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +118 -59
- package/dist/internal/template-filter.d.mts +7 -10
- package/dist/internal/template-filter.d.mts.map +1 -1
- package/dist/internal/template-filter.mjs +7 -10
- package/package.json +6 -4
- package/templates/standalone/.dockerignore +15 -2
- package/templates/standalone/.env.example +59 -26
- package/templates/standalone/Dockerfile +6 -2
- package/templates/standalone/README.ja.md +293 -162
- package/templates/standalone/README.md +533 -199
- package/templates/standalone/config/application.conf +196 -341
- package/templates/standalone/config/clients.yaml +2 -0
- package/templates/standalone/config/clients.yaml.example +4 -0
- package/templates/standalone/config/development.conf +13 -4
- package/templates/standalone/config/mailpit.conf +8 -0
- package/templates/standalone/config/production.conf +5 -6
- package/templates/standalone/config/reference.conf +399 -0
- package/templates/standalone/docker-compose.mailpit.yml +36 -0
- package/templates/standalone/docker-compose.production.yml +58 -30
- package/templates/standalone/docker-compose.yml +13 -3
- package/templates/standalone/gitignore +1 -0
- package/templates/standalone/package.json +9 -6
- package/templates/standalone/src/__tests__/access-token-lifetime-alias.test.mts +19 -20
- package/templates/standalone/src/__tests__/adapters.test.mts +358 -0
- package/templates/standalone/src/__tests__/all-modules-composition.fixture.mts +216 -141
- package/templates/standalone/src/__tests__/all-modules-composition.multi.test.mts +48 -33
- package/templates/standalone/src/__tests__/all-modules-composition.test.mts +77 -58
- package/templates/standalone/src/__tests__/audit-sink.test.mts +78 -76
- package/templates/standalone/src/__tests__/configPath.test.mts +13 -11
- package/templates/standalone/src/__tests__/core-federations.test.mts +226 -0
- package/templates/standalone/src/__tests__/core-sections.test.mts +190 -0
- package/templates/standalone/src/__tests__/device-code-store-client-module.test.mts +9 -14
- package/templates/standalone/src/__tests__/documented-env-overrides.test.mts +656 -269
- package/templates/standalone/src/__tests__/federation-grants-composition.test.mts +425 -84
- package/templates/standalone/src/__tests__/federation-grants-survive-logout.test.mts +91 -70
- package/templates/standalone/src/__tests__/federation-token-refresh-outage.test.mts +7 -5
- package/templates/standalone/src/__tests__/google-federation-config-module.test.mts +22 -19
- package/templates/standalone/src/__tests__/google-session.fixture.mts +53 -42
- package/templates/standalone/src/__tests__/host-routes.test.mts +4 -11
- package/templates/standalone/src/__tests__/library-references.fixture.mts +183 -0
- package/templates/standalone/src/__tests__/listen.test.mts +6 -13
- package/templates/standalone/src/__tests__/logger-projection.test.mts +1 -1
- package/templates/standalone/src/__tests__/mail-sender.test.mts +134 -0
- package/templates/standalone/src/__tests__/mailpit-compose.test.mts +328 -0
- package/templates/standalone/src/__tests__/metrics.test.mts +4 -9
- package/templates/standalone/src/__tests__/mfa-switch.redis.test.mts +123 -0
- package/templates/standalone/src/__tests__/mfa-switch.test.mts +780 -0
- package/templates/standalone/src/__tests__/oidc-federation-config-module.test.mts +52 -46
- package/templates/standalone/src/__tests__/own-modules.test.mts +1457 -0
- package/templates/standalone/src/__tests__/post-logout-redirect.test.mts +7 -11
- package/templates/standalone/src/__tests__/redis-connection-error-log.test.mts +1 -5
- package/templates/standalone/src/__tests__/redis-rate-limiter-config-survives.test.mts +112 -81
- package/templates/standalone/src/__tests__/refresh-token-family-client-module.test.mts +25 -31
- package/templates/standalone/src/__tests__/replica-safety.test.mts +153 -142
- package/templates/standalone/src/__tests__/router-error-answers.test.mts +4 -7
- package/templates/standalone/src/__tests__/scaffold-assets.test.mts +275 -95
- package/templates/standalone/src/__tests__/sections.test.mts +480 -0
- package/templates/standalone/src/__tests__/session-logout-invalidates-token.test.mts +67 -55
- package/templates/standalone/src/__tests__/session-requirements.test.mts +299 -0
- package/templates/standalone/src/__tests__/shutdown.test.mts +163 -96
- package/templates/standalone/src/__tests__/smoke.test.mts +179 -252
- package/templates/standalone/src/__tests__/store-credential.test.mts +91 -50
- package/templates/standalone/src/__tests__/supertest-loopback.test.mts +182 -11
- package/templates/standalone/src/__tests__/three-tier-resolution.test.mts +108 -95
- package/templates/standalone/src/__tests__/two-phase-config.test.mts +438 -0
- package/templates/standalone/src/__tests__/upstream-amr.acceptance.test.mts +390 -0
- package/templates/standalone/src/adapters.mts +149 -0
- package/templates/standalone/src/app.mts +64 -79
- package/templates/standalone/src/buildModules.mts +212 -251
- package/templates/standalone/src/configPath.mts +422 -29
- package/templates/standalone/src/listen.mts +12 -18
- package/templates/standalone/src/logger.mts +31 -60
- package/templates/standalone/src/metrics.mts +24 -47
- package/templates/standalone/src/mfaSwitch.mts +262 -0
- package/templates/standalone/src/modules.mts +458 -476
- package/templates/standalone/src/rootRenames.mts +79 -0
- package/templates/standalone/src/routes.mts +8 -14
- package/templates/standalone/src/sections.mts +366 -0
- package/templates/standalone/src/shutdown.mts +45 -123
- package/templates/standalone/tests/index.test.js +2 -2
- package/templates/standalone/tests/package-lock.json +1615 -2223
- package/templates/standalone/tests/package.json +2 -2
- package/templates/standalone/tests/vitest.config.mjs +26 -0
- package/templates/standalone/vitest.config.mts +8 -7
- package/templates/standalone/vitest.supertest-loopback.mts +97 -69
- package/templates/versions.json +18 -15
|
@@ -41,7 +41,7 @@ function buildApp(probes: Parameters<ReturnType<typeof createMetrics>["route"]>[
|
|
|
41
41
|
* Starts `app` on 127.0.0.1, the address the raw-socket tests dial. A hostless
|
|
42
42
|
* `listen(0)` binds `[::]`, and on macOS the port it gets can be one another
|
|
43
43
|
* process holds on 127.0.0.1 — the request then reaches that process and can
|
|
44
|
-
* hang until the test times out
|
|
44
|
+
* hang until the test times out.
|
|
45
45
|
*/
|
|
46
46
|
function listenOnLoopback(app: express.Express): Promise<ReturnType<express.Express["listen"]>> {
|
|
47
47
|
return new Promise((resolve) => {
|
|
@@ -137,14 +137,9 @@ describe("GET /metrics", () => {
|
|
|
137
137
|
it("counts a request whose client disconnects before the response finishes", async () => {
|
|
138
138
|
// `close` fires without `finish` when a client or proxy gives up
|
|
139
139
|
// mid-handler, and those are disproportionately the slow and failing
|
|
140
|
-
// requests RED metrics exist to surface.
|
|
141
|
-
//
|
|
142
|
-
//
|
|
143
|
-
// goes out once the handler holds the request, and /metrics is read once
|
|
144
|
-
// the response has closed. A 30 ms sleep either side raced a loaded
|
|
145
|
-
// machine — an abort sent before the request reached its route was
|
|
146
|
-
// counted as `unmatched`, or not at all, and one whose close had not yet
|
|
147
|
-
// been processed was read as nothing.
|
|
140
|
+
// requests RED metrics exist to surface. Sequenced on the server's own
|
|
141
|
+
// events, never on a fixed wait: the abort goes out once the handler
|
|
142
|
+
// holds the request, and /metrics is read once the response has closed.
|
|
148
143
|
const metrics = createMetrics();
|
|
149
144
|
const app = express();
|
|
150
145
|
app.use(metrics.middleware);
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 1o1 Co. Ltd.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The template's MFA switch under the name production, where the MFA stores
|
|
19
|
+
* must be shared: both on Redis, as a production deployment selects them.
|
|
20
|
+
* ioredis is a stand-in, as in `all-modules-composition.multi.test.mts`:
|
|
21
|
+
* nothing here issues a command, and the stores' durability check names what
|
|
22
|
+
* it could not read and goes on. `packages/redis` runs the stores against a
|
|
23
|
+
* real server.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { BootError } from "@o3co/auth-provider-core";
|
|
27
|
+
import { MFA_DEVELOPMENT_SAMPLE_KEY } from "@o3co/auth-provider-mfa";
|
|
28
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
29
|
+
import { type Composition, compose, SINGLE_ENV } from "./all-modules-composition.fixture.mjs";
|
|
30
|
+
|
|
31
|
+
vi.mock("ioredis", () => {
|
|
32
|
+
// Constructible, quits cleanly, answers the readiness probe's `ping`;
|
|
33
|
+
// every other command resolves to nothing.
|
|
34
|
+
const explicit: Record<string, unknown> = {
|
|
35
|
+
on: () => undefined,
|
|
36
|
+
quit: async () => "OK",
|
|
37
|
+
disconnect: () => undefined,
|
|
38
|
+
ping: async () => "PONG",
|
|
39
|
+
};
|
|
40
|
+
const makeMockRedis = (): object =>
|
|
41
|
+
new Proxy(
|
|
42
|
+
{},
|
|
43
|
+
{
|
|
44
|
+
get(_target, prop) {
|
|
45
|
+
// A function-valued `then` would make the instance a thenable.
|
|
46
|
+
if (typeof prop !== "string" || prop === "then") return undefined;
|
|
47
|
+
if (prop === "duplicate") return makeMockRedis;
|
|
48
|
+
if (prop in explicit) return explicit[prop];
|
|
49
|
+
return async () => null;
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
);
|
|
53
|
+
function MockRedis(): object {
|
|
54
|
+
return makeMockRedis();
|
|
55
|
+
}
|
|
56
|
+
return { Redis: MockRedis, default: MockRedis };
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
let current: Composition | undefined;
|
|
60
|
+
|
|
61
|
+
afterEach(async () => {
|
|
62
|
+
await current?.handle.dispose();
|
|
63
|
+
current = undefined;
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
/** MFA required in production, both MFA stores on Redis, a key of the deployment's own and an SMTP relay. */
|
|
67
|
+
const PRODUCTION_ENV: Readonly<Record<string, string>> = {
|
|
68
|
+
...SINGLE_ENV,
|
|
69
|
+
MFA_MODE: "required",
|
|
70
|
+
ADAPTERS_MFA_FACTOR_STORE: "redis",
|
|
71
|
+
ADAPTERS_MFA_TRANSACTION_STORE: "redis",
|
|
72
|
+
REDIS_CLIENTS_URL: "redis://redis.test:6379",
|
|
73
|
+
MFA_ENCRYPTION_KEY: Buffer.alloc(32, 9).toString("base64"),
|
|
74
|
+
STANDARD_SMTP_MAIL_SENDER_HOST: "smtp.auth.test",
|
|
75
|
+
STANDARD_SMTP_MAIL_SENDER_FROM: "auth@auth.test",
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/** An error's message with every cause's under it. */
|
|
79
|
+
const textOf = (err: unknown): string => {
|
|
80
|
+
const parts: string[] = [];
|
|
81
|
+
for (let at: unknown = err; at instanceof Error; at = at.cause) parts.push(at.message);
|
|
82
|
+
return parts.join(" <- ");
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const refusal = (composing: Promise<Composition>): Promise<unknown> =>
|
|
86
|
+
composing.then(
|
|
87
|
+
(composition) => {
|
|
88
|
+
current = composition;
|
|
89
|
+
return undefined;
|
|
90
|
+
},
|
|
91
|
+
(caught: unknown) => caught,
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
describe("MFA_MODE=required under the name production, the MFA stores on Redis", () => {
|
|
95
|
+
it("boots, the requirement registered as the second-factor authority", async () => {
|
|
96
|
+
current = await compose({ env: PRODUCTION_ENV, environment: "production" });
|
|
97
|
+
const names = current.modules.map((m) => m.name);
|
|
98
|
+
expect(names).toContain("redis-mfa-factor-store");
|
|
99
|
+
expect(names).toContain("redis-mfa-transaction-store");
|
|
100
|
+
expect(
|
|
101
|
+
current.handle.components.sessionRequirementResolver?.get("mfa")?.secondFactorAuthority,
|
|
102
|
+
).toBe(true);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("refuses the development sample key, naming MFA_ENCRYPTION_KEY and quoting no key", async () => {
|
|
106
|
+
const err = await refusal(
|
|
107
|
+
compose({
|
|
108
|
+
env: { ...PRODUCTION_ENV, MFA_ENCRYPTION_KEY: MFA_DEVELOPMENT_SAMPLE_KEY },
|
|
109
|
+
environment: "production",
|
|
110
|
+
}),
|
|
111
|
+
);
|
|
112
|
+
expect(err).toBeInstanceOf(BootError);
|
|
113
|
+
expect(textOf(err)).toContain("MFA_ENCRYPTION_KEY");
|
|
114
|
+
expect(textOf(err)).not.toContain(MFA_DEVELOPMENT_SAMPLE_KEY);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("refuses without an SMTP relay, naming STANDARD_SMTP_MAIL_SENDER_HOST", async () => {
|
|
118
|
+
const { STANDARD_SMTP_MAIL_SENDER_HOST: _host, ...env } = PRODUCTION_ENV;
|
|
119
|
+
const err = await refusal(compose({ env, environment: "production" }));
|
|
120
|
+
expect(err).toBeInstanceOf(BootError);
|
|
121
|
+
expect(textOf(err)).toContain("STANDARD_SMTP_MAIL_SENDER_HOST");
|
|
122
|
+
});
|
|
123
|
+
});
|