@o3co/create-auth-provider 0.16.0 → 0.17.0-rc.2
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 -29
- package/templates/standalone/Dockerfile +6 -2
- package/templates/standalone/README.ja.md +324 -169
- package/templates/standalone/README.md +618 -208
- package/templates/standalone/config/application.conf +211 -352
- 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 +418 -0
- package/templates/standalone/docker-compose.mailpit.yml +36 -0
- package/templates/standalone/docker-compose.production.yml +63 -32
- 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__/adapters.test.mts +419 -0
- package/templates/standalone/src/__tests__/admission-lifecycle.test.mts +87 -0
- package/templates/standalone/src/__tests__/all-modules-composition.fixture.mts +287 -198
- package/templates/standalone/src/__tests__/all-modules-composition.multi.test.mts +71 -35
- package/templates/standalone/src/__tests__/all-modules-composition.test.mts +148 -94
- package/templates/standalone/src/__tests__/audit-sink.test.mts +84 -81
- package/templates/standalone/src/__tests__/config-notices.test.mts +154 -0
- package/templates/standalone/src/__tests__/configPath.test.mts +13 -11
- package/templates/standalone/src/__tests__/core-federations.test.mts +249 -0
- package/templates/standalone/src/__tests__/core-sections.test.mts +190 -0
- package/templates/standalone/src/__tests__/device-code-store-client-module.test.mts +10 -15
- package/templates/standalone/src/__tests__/documented-env-overrides.test.mts +970 -288
- package/templates/standalone/src/__tests__/federation-grants-composition.test.mts +421 -86
- package/templates/standalone/src/__tests__/federation-grants-survive-logout.test.mts +87 -72
- package/templates/standalone/src/__tests__/federation-token-refresh-outage.test.mts +16 -8
- package/templates/standalone/src/__tests__/federation-types.test.mts +239 -0
- package/templates/standalone/src/__tests__/google-session.fixture.mts +97 -93
- package/templates/standalone/src/__tests__/host-routes.test.mts +4 -11
- package/templates/standalone/src/__tests__/library-reference-resolution.smoke.test.mts +1 -1
- package/templates/standalone/src/__tests__/library-references.fixture.mts +188 -0
- package/templates/standalone/src/__tests__/lifecycle-pending-close.test.mts +216 -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 +326 -0
- package/templates/standalone/src/__tests__/metrics.test.mts +4 -9
- package/templates/standalone/src/__tests__/mfa-routes-budget.test.mts +122 -0
- package/templates/standalone/src/__tests__/mfa-switch.redis.test.mts +123 -0
- package/templates/standalone/src/__tests__/mfa-switch.test.mts +825 -0
- package/templates/standalone/src/__tests__/own-modules.test.mts +1486 -0
- package/templates/standalone/src/__tests__/post-logout-redirect.test.mts +10 -14
- 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 +116 -81
- package/templates/standalone/src/__tests__/refresh-token-family-client-module.test.mts +25 -31
- package/templates/standalone/src/__tests__/replica-safety.test.mts +265 -146
- package/templates/standalone/src/__tests__/router-error-answers.test.mts +4 -7
- package/templates/standalone/src/__tests__/scaffold-assets.test.mts +278 -103
- package/templates/standalone/src/__tests__/sections.test.mts +480 -0
- package/templates/standalone/src/__tests__/session-lifecycle.test.mts +215 -0
- package/templates/standalone/src/__tests__/session-logout-invalidates-token.test.mts +69 -61
- package/templates/standalone/src/__tests__/session-logout-lifecycle.test.mts +130 -0
- package/templates/standalone/src/__tests__/session-requirements.test.mts +382 -0
- package/templates/standalone/src/__tests__/shipped-config-notices.test.mts +270 -0
- package/templates/standalone/src/__tests__/shutdown.test.mts +163 -96
- package/templates/standalone/src/__tests__/smoke.test.mts +176 -258
- package/templates/standalone/src/__tests__/store-credential.test.mts +88 -52
- package/templates/standalone/src/__tests__/supertest-loopback.test.mts +182 -11
- package/templates/standalone/src/__tests__/three-tier-resolution.test.mts +131 -102
- package/templates/standalone/src/__tests__/two-phase-config.test.mts +604 -0
- package/templates/standalone/src/__tests__/upstream-amr.acceptance.test.mts +382 -0
- package/templates/standalone/src/adapters.mts +162 -0
- package/templates/standalone/src/app.mts +65 -79
- package/templates/standalone/src/bootRefusal.mts +117 -0
- package/templates/standalone/src/buildModules.mts +220 -309
- package/templates/standalone/src/configPath.mts +449 -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 +285 -0
- package/templates/standalone/src/modules.mts +423 -629
- package/templates/standalone/src/rootRenames.mts +96 -0
- package/templates/standalone/src/routes.mts +8 -14
- package/templates/standalone/src/sections.mts +367 -0
- package/templates/standalone/src/shutdown.mts +45 -123
- package/templates/standalone/tests/index.test.js +6 -5
- 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
- package/templates/standalone/src/__tests__/access-token-lifetime-alias.test.mts +0 -135
- package/templates/standalone/src/__tests__/google-federation-config-module.test.mts +0 -199
- package/templates/standalone/src/__tests__/oidc-federation-config-module.test.mts +0 -138
|
@@ -0,0 +1,249 @@
|
|
|
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 federations the template ships, in core's own section:
|
|
19
|
+
* `core.federations.google` and `core.federations.oidc`, each naming its
|
|
20
|
+
* type and bound to the variables named after its paths
|
|
21
|
+
* (`CORE_FEDERATIONS_<NAME>_<KEY>`). The federation types the template
|
|
22
|
+
* bundles are listed whatever the map says (`federation-types.test.mts`
|
|
23
|
+
* boots them). A variable the
|
|
24
|
+
* template bound before, `FEDERATIONS_<NAME>_<KEY>`, set alone or beside its
|
|
25
|
+
* new name at a different value is refused before any module is chosen,
|
|
26
|
+
* naming the new variable and path and never a value; the two at one value
|
|
27
|
+
* are accepted. The map written at the top level refuses boot, naming its
|
|
28
|
+
* paths under `core.federations`.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
32
|
+
import { tmpdir } from "node:os";
|
|
33
|
+
import { join } from "node:path";
|
|
34
|
+
import { fileURLToPath } from "node:url";
|
|
35
|
+
import { BootError, createApp } from "@o3co/auth-provider-core";
|
|
36
|
+
import { afterAll, describe, expect, it } from "vitest";
|
|
37
|
+
import { buildModules } from "#/buildModules.mjs";
|
|
38
|
+
import { readOwnLayers, readSwitches, resolveConfigPaths, resolveForBoot } from "#/configPath.mjs";
|
|
39
|
+
|
|
40
|
+
const configDir = fileURLToPath(new URL("../../config", import.meta.url));
|
|
41
|
+
|
|
42
|
+
/** The directories the operator layers are written to, removed after the suite. */
|
|
43
|
+
const operatorDirs: string[] = [];
|
|
44
|
+
afterAll(() => {
|
|
45
|
+
for (const dir of operatorDirs) rmSync(dir, { recursive: true, force: true });
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
/** The template's own files for the production environment, under an operator's layer when given. */
|
|
49
|
+
function ownFiles(hocon?: string): string[] {
|
|
50
|
+
const { applicationConfPath, envConfPath } = resolveConfigPaths(configDir, "production");
|
|
51
|
+
if (hocon === undefined) return [envConfPath, applicationConfPath];
|
|
52
|
+
const dir = mkdtempSync(join(tmpdir(), "core-federations-"));
|
|
53
|
+
operatorDirs.push(dir);
|
|
54
|
+
const file = join(dir, "operator.conf");
|
|
55
|
+
writeFileSync(file, hocon);
|
|
56
|
+
return [file, envConfPath, applicationConfPath];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** MFA, on by default, switched off: these are about the federations. */
|
|
60
|
+
const MFA_OFF: Readonly<Record<string, string>> = { MFA_MODE: "off" };
|
|
61
|
+
|
|
62
|
+
/** Phase one under `env` and an operator's `hocon`. */
|
|
63
|
+
const switchesFrom = (env: Record<string, string> = {}, hocon?: string) =>
|
|
64
|
+
readSwitches(readOwnLayers(ownFiles(hocon), { env: { ...MFA_OFF, ...env } }));
|
|
65
|
+
|
|
66
|
+
/** What phase one refuses under `env`. */
|
|
67
|
+
function refusal(env: Record<string, string>): Error {
|
|
68
|
+
try {
|
|
69
|
+
switchesFrom(env);
|
|
70
|
+
} catch (err) {
|
|
71
|
+
return err as Error;
|
|
72
|
+
}
|
|
73
|
+
throw new Error("phase one read the switches");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** The federations the composition hands boot under `env`, by name: phase one, then phase two. */
|
|
77
|
+
function federationsOf(env: Record<string, string> = {}) {
|
|
78
|
+
const own = readOwnLayers(ownFiles(), { env: { ...MFA_OFF, ...env } });
|
|
79
|
+
const switches = readSwitches(own);
|
|
80
|
+
const modules = buildModules(switches, { environment: "production" });
|
|
81
|
+
const resolved = resolveForBoot(own, modules, switches) as unknown as {
|
|
82
|
+
readonly core?: { readonly federations?: Record<string, Record<string, unknown>> };
|
|
83
|
+
};
|
|
84
|
+
return resolved.core?.federations ?? {};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** The modules phase one chooses under `env`, by name. */
|
|
88
|
+
const moduleNames = (env: Record<string, string>) =>
|
|
89
|
+
buildModules(switchesFrom(env), { environment: "production" }).map((module) => module.name);
|
|
90
|
+
|
|
91
|
+
/** Each variable the template binds: its key under the federation, the old name and the new. */
|
|
92
|
+
const RENAMED = [
|
|
93
|
+
["google", "enabled", "FEDERATIONS_GOOGLE_ENABLED", "CORE_FEDERATIONS_GOOGLE_ENABLED", "true"],
|
|
94
|
+
[
|
|
95
|
+
"google",
|
|
96
|
+
"clientId",
|
|
97
|
+
"FEDERATIONS_GOOGLE_CLIENT_ID",
|
|
98
|
+
"CORE_FEDERATIONS_GOOGLE_CLIENT_ID",
|
|
99
|
+
"g-id",
|
|
100
|
+
],
|
|
101
|
+
[
|
|
102
|
+
"google",
|
|
103
|
+
"clientSecret",
|
|
104
|
+
"FEDERATIONS_GOOGLE_CLIENT_SECRET",
|
|
105
|
+
"CORE_FEDERATIONS_GOOGLE_CLIENT_SECRET",
|
|
106
|
+
"g-secret",
|
|
107
|
+
],
|
|
108
|
+
[
|
|
109
|
+
"google",
|
|
110
|
+
"callbackURL",
|
|
111
|
+
"FEDERATIONS_GOOGLE_CALLBACK_URL",
|
|
112
|
+
"CORE_FEDERATIONS_GOOGLE_CALLBACK_URL",
|
|
113
|
+
"https://auth.test/session/oauth/federation/google/callback",
|
|
114
|
+
],
|
|
115
|
+
[
|
|
116
|
+
"google",
|
|
117
|
+
"accessType",
|
|
118
|
+
"FEDERATIONS_GOOGLE_ACCESS_TYPE",
|
|
119
|
+
"CORE_FEDERATIONS_GOOGLE_ACCESS_TYPE",
|
|
120
|
+
"online",
|
|
121
|
+
],
|
|
122
|
+
["oidc", "enabled", "FEDERATIONS_OIDC_ENABLED", "CORE_FEDERATIONS_OIDC_ENABLED", "true"],
|
|
123
|
+
["oidc", "issuer", "FEDERATIONS_OIDC_ISSUER", "CORE_FEDERATIONS_OIDC_ISSUER", "https://idp.test"],
|
|
124
|
+
["oidc", "clientId", "FEDERATIONS_OIDC_CLIENT_ID", "CORE_FEDERATIONS_OIDC_CLIENT_ID", "o-id"],
|
|
125
|
+
[
|
|
126
|
+
"oidc",
|
|
127
|
+
"clientSecret",
|
|
128
|
+
"FEDERATIONS_OIDC_CLIENT_SECRET",
|
|
129
|
+
"CORE_FEDERATIONS_OIDC_CLIENT_SECRET",
|
|
130
|
+
"o-secret",
|
|
131
|
+
],
|
|
132
|
+
[
|
|
133
|
+
"oidc",
|
|
134
|
+
"callbackURL",
|
|
135
|
+
"FEDERATIONS_OIDC_CALLBACK_URL",
|
|
136
|
+
"CORE_FEDERATIONS_OIDC_CALLBACK_URL",
|
|
137
|
+
"https://auth.test/session/oauth/federation/oidc/callback",
|
|
138
|
+
],
|
|
139
|
+
] as const;
|
|
140
|
+
|
|
141
|
+
describe("the federations the template ships, under core.federations", () => {
|
|
142
|
+
it("ships google and oidc disabled, each of the type of its name", () => {
|
|
143
|
+
const federations = federationsOf();
|
|
144
|
+
expect(federations.google).toMatchObject({ enabled: false, type: "google" });
|
|
145
|
+
expect(federations.oidc).toMatchObject({ enabled: false, type: "oidc" });
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it.each(RENAMED)(
|
|
149
|
+
"reads core.federations.%s.%s from %s's new name",
|
|
150
|
+
(name, key, _old, variable, value) => {
|
|
151
|
+
expect(String(federationsOf({ [variable]: value })[name]?.[key])).toBe(value);
|
|
152
|
+
},
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
it("lists the same federation modules whether CORE_FEDERATIONS_GOOGLE_ENABLED is true or not", () => {
|
|
156
|
+
const federationModules = (env: Record<string, string>) =>
|
|
157
|
+
moduleNames(env).filter((name) => name === "federation-oidc" || name.endsWith("-type"));
|
|
158
|
+
expect(federationModules({ CORE_FEDERATIONS_GOOGLE_ENABLED: "true" })).toEqual([
|
|
159
|
+
"federation-google-type",
|
|
160
|
+
"federation-oidc",
|
|
161
|
+
]);
|
|
162
|
+
expect(federationModules({})).toEqual(
|
|
163
|
+
federationModules({ CORE_FEDERATIONS_GOOGLE_ENABLED: "true" }),
|
|
164
|
+
);
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
describe("a variable the template bound before, FEDERATIONS_<NAME>_<KEY>", () => {
|
|
169
|
+
it.each(RENAMED)(
|
|
170
|
+
"core.federations.%s.%s: %s set alone is refused before any module is chosen, naming %s",
|
|
171
|
+
(name, key, old, variable, value) => {
|
|
172
|
+
const err = refusal({ [old]: value });
|
|
173
|
+
expect(err).toBeInstanceOf(BootError);
|
|
174
|
+
expect(err.message).toContain(`${old} was renamed ${variable}`);
|
|
175
|
+
expect(err.message).toContain(`core.federations.${name}.${key}`);
|
|
176
|
+
expect(err).toMatchObject({
|
|
177
|
+
reason: "environment-variable-renamed",
|
|
178
|
+
details: {
|
|
179
|
+
reason: "environment-variable-renamed",
|
|
180
|
+
renamed: [
|
|
181
|
+
{
|
|
182
|
+
module: "core",
|
|
183
|
+
from: old,
|
|
184
|
+
to: variable,
|
|
185
|
+
path: `core.federations.${name}.${key}`,
|
|
186
|
+
state: "unset",
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
},
|
|
190
|
+
});
|
|
191
|
+
},
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
it.each(RENAMED)(
|
|
195
|
+
"core.federations.%s.%s: %s beside its new name at a different value is refused, quoting neither",
|
|
196
|
+
(_name, _key, old, variable) => {
|
|
197
|
+
const err = refusal({ [old]: "old-value-5e2d", [variable]: "new-value-c81a" });
|
|
198
|
+
expect(err).toMatchObject({
|
|
199
|
+
reason: "environment-variable-renamed",
|
|
200
|
+
details: { renamed: [{ from: old, state: "different" }] },
|
|
201
|
+
});
|
|
202
|
+
expect(err.message).toContain(old);
|
|
203
|
+
expect(err.message).not.toContain("old-value-5e2d");
|
|
204
|
+
expect(err.message).not.toContain("new-value-c81a");
|
|
205
|
+
},
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
it.each(RENAMED)(
|
|
209
|
+
"core.federations.%s.%s: %s beside its new name at the same value is read",
|
|
210
|
+
(name, key, old, variable, value) => {
|
|
211
|
+
expect(String(federationsOf({ [old]: value, [variable]: value })[name]?.[key])).toBe(value);
|
|
212
|
+
},
|
|
213
|
+
);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
describe("the map written at the top level", () => {
|
|
217
|
+
it("refuses boot, naming its paths under core.federations", async () => {
|
|
218
|
+
const own = readOwnLayers(ownFiles("federations.okta.enabled = false\n"), {
|
|
219
|
+
env: {
|
|
220
|
+
...MFA_OFF,
|
|
221
|
+
KEY_STORE_LOCAL_SECRET: "core-federations-secret.at-least-32-bytes.ok",
|
|
222
|
+
OAUTH_JWT_ISSUER: "https://auth.test",
|
|
223
|
+
SESSION_STORE_SECRET: "core-federations-session.at-least-32-bytes.ok",
|
|
224
|
+
},
|
|
225
|
+
});
|
|
226
|
+
const switches = readSwitches(own);
|
|
227
|
+
const modules = buildModules(switches, { environment: "production" });
|
|
228
|
+
await expect(
|
|
229
|
+
createApp({
|
|
230
|
+
modules,
|
|
231
|
+
bootstrapComponents: {
|
|
232
|
+
config: resolveForBoot(own, modules, switches),
|
|
233
|
+
pathResolver: (s: string) => s,
|
|
234
|
+
} as never,
|
|
235
|
+
}),
|
|
236
|
+
).rejects.toMatchObject({
|
|
237
|
+
reason: "config-path-relocated",
|
|
238
|
+
details: {
|
|
239
|
+
relocated: [
|
|
240
|
+
expect.objectContaining({
|
|
241
|
+
from: "federations.okta.enabled",
|
|
242
|
+
to: "core.federations.okta.enabled",
|
|
243
|
+
environmentVariable: "CORE_FEDERATIONS_OKTA_ENABLED",
|
|
244
|
+
}),
|
|
245
|
+
],
|
|
246
|
+
},
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
});
|
|
@@ -0,0 +1,190 @@
|
|
|
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
|
+
* Core's own settings under `core {}` and the JWKS module's under `jwks {}`,
|
|
19
|
+
* through the template's own reading: its layers read once under one
|
|
20
|
+
* environment, phase one's switches, then the layers over every loaded
|
|
21
|
+
* package's `reference.conf` handed to boot. A path they moved from, written
|
|
22
|
+
* in the operator's own layer, refuses boot naming the new one;
|
|
23
|
+
* `DEPLOYMENT_MODE`, renamed `CORE_DEPLOYMENT_MODE`, refuses boot unless the
|
|
24
|
+
* new name carries the same value.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
import { BootError } from "@o3co/auth-provider-core";
|
|
28
|
+
import request from "supertest";
|
|
29
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
30
|
+
import {
|
|
31
|
+
type ComposeOptions,
|
|
32
|
+
type Composition,
|
|
33
|
+
compose,
|
|
34
|
+
ISSUER,
|
|
35
|
+
SINGLE_ENV,
|
|
36
|
+
} from "./all-modules-composition.fixture.mjs";
|
|
37
|
+
|
|
38
|
+
/** The fixture's single-replica environment, with neither name of the replica count set. */
|
|
39
|
+
const BASE: Readonly<Record<string, string>> = Object.fromEntries(
|
|
40
|
+
Object.entries(SINGLE_ENV).filter(
|
|
41
|
+
([name]) => name !== "DEPLOYMENT_MODE" && name !== "CORE_DEPLOYMENT_MODE",
|
|
42
|
+
),
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
let current: Composition | undefined;
|
|
46
|
+
|
|
47
|
+
afterEach(async () => {
|
|
48
|
+
await current?.handle.dispose();
|
|
49
|
+
current = undefined;
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
/** Boots under `env` beside `BASE`, and remembers the composition so `afterEach` disposes it. */
|
|
53
|
+
async function boot(env: Record<string, string>, more: ComposeOptions = {}): Promise<Composition> {
|
|
54
|
+
current = await compose({ env: { ...BASE, ...env }, ...more });
|
|
55
|
+
return current;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** What boot refused with. */
|
|
59
|
+
async function refused(env: Record<string, string>, more: ComposeOptions = {}): Promise<BootError> {
|
|
60
|
+
try {
|
|
61
|
+
await boot(env, more);
|
|
62
|
+
} catch (err) {
|
|
63
|
+
if (err instanceof BootError) return err;
|
|
64
|
+
throw err;
|
|
65
|
+
}
|
|
66
|
+
throw new Error("the composition booted");
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
describe("core's own settings and the JWKS module's, as the template reads them", () => {
|
|
70
|
+
it("boots the shipped configuration: core.sessionRequirements.expected is [], the replica count what CORE_DEPLOYMENT_MODE sets", async () => {
|
|
71
|
+
const composition = await boot({ CORE_DEPLOYMENT_MODE: "single" });
|
|
72
|
+
|
|
73
|
+
const config = composition.config as unknown as Record<string, unknown>;
|
|
74
|
+
expect(config.core).toMatchObject({ sessionRequirements: { expected: [] } });
|
|
75
|
+
expect(config).not.toHaveProperty("sessionRequirements");
|
|
76
|
+
expect(config).not.toHaveProperty("deployment");
|
|
77
|
+
expect(composition.handle.components.deploymentMode).toBe("single");
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("serves the JWKS at the path JWKS_PATH sets, for the max-age JWKS_CACHE_MAX_AGE sets, and advertises it as jwks_uri", async () => {
|
|
81
|
+
const composition = await boot({
|
|
82
|
+
CORE_DEPLOYMENT_MODE: "single",
|
|
83
|
+
JWKS_PATH: "/keys/jwks.json",
|
|
84
|
+
JWKS_CACHE_MAX_AGE: "600",
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const jwks = await request(composition.app).get("/keys/jwks.json");
|
|
88
|
+
expect(jwks.status).toBe(200);
|
|
89
|
+
expect(jwks.headers["cache-control"]).toBe("public, max-age=600");
|
|
90
|
+
const discovery = await request(composition.app).get("/.well-known/openid-configuration");
|
|
91
|
+
expect(discovery.body.jwks_uri).toBe(`${ISSUER}/keys/jwks.json`);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe("a path core's or the JWKS module's settings moved from, written in the operator's own layer", () => {
|
|
96
|
+
it.each([
|
|
97
|
+
[
|
|
98
|
+
'deployment.mode = "single"',
|
|
99
|
+
"core",
|
|
100
|
+
"deployment.mode",
|
|
101
|
+
"core.deployment.mode",
|
|
102
|
+
"CORE_DEPLOYMENT_MODE",
|
|
103
|
+
],
|
|
104
|
+
[
|
|
105
|
+
"sessionRequirements.expected = []",
|
|
106
|
+
"core",
|
|
107
|
+
"sessionRequirements.expected",
|
|
108
|
+
"core.sessionRequirements.expected",
|
|
109
|
+
undefined,
|
|
110
|
+
],
|
|
111
|
+
[
|
|
112
|
+
'oauth.jwt.jwksPath = "/keys/jwks.json"',
|
|
113
|
+
"jwks",
|
|
114
|
+
"oauth.jwt.jwksPath",
|
|
115
|
+
"jwks.path",
|
|
116
|
+
"JWKS_PATH",
|
|
117
|
+
],
|
|
118
|
+
[
|
|
119
|
+
"oauth.jwt.jwksCacheMaxAge = 60",
|
|
120
|
+
"jwks",
|
|
121
|
+
"oauth.jwt.jwksCacheMaxAge",
|
|
122
|
+
"jwks.cacheMaxAge",
|
|
123
|
+
"JWKS_CACHE_MAX_AGE",
|
|
124
|
+
],
|
|
125
|
+
])(
|
|
126
|
+
"%s: refused, naming %s's new path and the variable that binds it, if any",
|
|
127
|
+
async (hocon, module, from, to, variable) => {
|
|
128
|
+
const err = await refused(
|
|
129
|
+
{ CORE_DEPLOYMENT_MODE: "single" },
|
|
130
|
+
{ operatorHocon: `${hocon}\n` },
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
expect(err.details).toEqual({
|
|
134
|
+
reason: "config-path-relocated",
|
|
135
|
+
relocated: [
|
|
136
|
+
{
|
|
137
|
+
module,
|
|
138
|
+
from,
|
|
139
|
+
to,
|
|
140
|
+
...(variable === undefined ? {} : { environmentVariable: variable }),
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
});
|
|
144
|
+
},
|
|
145
|
+
);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
describe("DEPLOYMENT_MODE, renamed CORE_DEPLOYMENT_MODE, through the template's reading", () => {
|
|
149
|
+
it("set alone: refused, naming the new variable and core.deployment.mode", async () => {
|
|
150
|
+
const err = await refused({ DEPLOYMENT_MODE: "single" });
|
|
151
|
+
|
|
152
|
+
expect(err.details).toEqual({
|
|
153
|
+
reason: "environment-variable-renamed",
|
|
154
|
+
renamed: [
|
|
155
|
+
{
|
|
156
|
+
module: "core",
|
|
157
|
+
from: "DEPLOYMENT_MODE",
|
|
158
|
+
to: "CORE_DEPLOYMENT_MODE",
|
|
159
|
+
path: "core.deployment.mode",
|
|
160
|
+
state: "unset",
|
|
161
|
+
},
|
|
162
|
+
],
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it("set beside the new name at a different value: refused, naming neither value", async () => {
|
|
167
|
+
const err = await refused({
|
|
168
|
+
DEPLOYMENT_MODE: "old-mode-5e2d",
|
|
169
|
+
CORE_DEPLOYMENT_MODE: "new-mode-c81a",
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
expect(err.details).toMatchObject({
|
|
173
|
+
renamed: [{ from: "DEPLOYMENT_MODE", to: "CORE_DEPLOYMENT_MODE", state: "different" }],
|
|
174
|
+
});
|
|
175
|
+
expect(err.message).not.toContain("old-mode-5e2d");
|
|
176
|
+
expect(err.message).not.toContain("new-mode-c81a");
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it("set beside the new name at the same value: boots with that mode", async () => {
|
|
180
|
+
const composition = await boot({ DEPLOYMENT_MODE: "single", CORE_DEPLOYMENT_MODE: "single" });
|
|
181
|
+
|
|
182
|
+
expect(composition.handle.components.deploymentMode).toBe("single");
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it("unset, with the new name set: boots with its mode", async () => {
|
|
186
|
+
const composition = await boot({ CORE_DEPLOYMENT_MODE: "single" });
|
|
187
|
+
|
|
188
|
+
expect(composition.handle.components.deploymentMode).toBe("single");
|
|
189
|
+
});
|
|
190
|
+
});
|
|
@@ -15,16 +15,14 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
* `standaloneRedisClientsModule` provides `deviceCodeStoreClient
|
|
18
|
+
* `standaloneRedisClientsModule` provides `deviceCodeStoreClient`.
|
|
19
19
|
*
|
|
20
20
|
* The template does not mount the device grant, so nothing in `buildModules`
|
|
21
|
-
* selects `redisDeviceCodeStoreModule`
|
|
21
|
+
* selects `redisDeviceCodeStoreModule` and the smoke test's client-slot
|
|
22
22
|
* invariant cannot see it. This pins the slot directly: a deployment that adds
|
|
23
|
-
* `
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* client slot the shared clients module did not provide, caught only by the
|
|
27
|
-
* umbrella e2e.
|
|
23
|
+
* `deviceAuthorizationGrantModule` to this manifest and picks the Redis store must not hit
|
|
24
|
+
* `missing-required-component` for a client slot the shared clients module
|
|
25
|
+
* does not provide.
|
|
28
26
|
*/
|
|
29
27
|
|
|
30
28
|
import type { LifecycleRegistrar } from "@o3co/auth-provider-core";
|
|
@@ -52,13 +50,10 @@ vi.mock("ioredis", () => {
|
|
|
52
50
|
|
|
53
51
|
const importModule = async () => await import("../modules.mjs");
|
|
54
52
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
redis: { url: "redis://example.com:6379" },
|
|
58
|
-
},
|
|
59
|
-
};
|
|
53
|
+
/** The module's own section, `redis-clients`, as boot hands it over. */
|
|
54
|
+
const baseSection = { url: "redis://example.com:6379" };
|
|
60
55
|
|
|
61
|
-
describe("
|
|
56
|
+
describe("standaloneRedisClientsModule.deviceCodeStoreClient", () => {
|
|
62
57
|
beforeEach(() => {
|
|
63
58
|
redisCtorCalls.length = 0;
|
|
64
59
|
});
|
|
@@ -87,10 +82,10 @@ describe("#433 / standaloneRedisClientsModule.deviceCodeStoreClient", () => {
|
|
|
87
82
|
const lifecycleRegistrar: LifecycleRegistrar = { register: () => {} };
|
|
88
83
|
|
|
89
84
|
const client = (await provides.deviceCodeStoreClient?.({
|
|
90
|
-
|
|
85
|
+
section: { ...baseSection },
|
|
91
86
|
lifecycleRegistrar,
|
|
92
87
|
})) as Record<string, unknown>;
|
|
93
|
-
await provides.rateLimiterClient?.({
|
|
88
|
+
await provides.rateLimiterClient?.({ section: { ...baseSection }, lifecycleRegistrar });
|
|
94
89
|
|
|
95
90
|
expect(redisCtorCalls).toHaveLength(1);
|
|
96
91
|
for (const method of ["create", "findPending", "decide", "poll", "remove"]) {
|