@grow-codes/oidc 0.0.0-stage → 0.1.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/AGENTS.md +122 -0
- package/LICENSE +202 -0
- package/NOTICE +61 -0
- package/README.md +30 -2
- package/lib/chunk-2PTQBDJ6.cjs +890 -0
- package/lib/chunk-2PTQBDJ6.cjs.map +1 -0
- package/lib/chunk-HB2FEHOY.js +843 -0
- package/lib/chunk-HB2FEHOY.js.map +1 -0
- package/lib/index.cjs +1378 -0
- package/lib/index.cjs.map +1 -0
- package/lib/index.d.cts +717 -0
- package/lib/index.d.ts +717 -0
- package/lib/index.js +1152 -0
- package/lib/index.js.map +1 -0
- package/lib/testing/index.cjs +591 -0
- package/lib/testing/index.cjs.map +1 -0
- package/lib/testing/index.d.cts +283 -0
- package/lib/testing/index.d.ts +283 -0
- package/lib/testing/index.js +569 -0
- package/lib/testing/index.js.map +1 -0
- package/lib/verifier-AJ2o8XWA.d.cts +219 -0
- package/lib/verifier-AJ2o8XWA.d.ts +219 -0
- package/package.json +106 -4
|
@@ -0,0 +1,569 @@
|
|
|
1
|
+
import { pollUntil, TimeoutError, DEFAULT_ALGORITHMS } from '../chunk-HB2FEHOY.js';
|
|
2
|
+
import { isDeepStrictEqual, inspect } from 'util';
|
|
3
|
+
import { readdirSync, readFileSync } from 'fs';
|
|
4
|
+
import { join } from 'path';
|
|
5
|
+
import { createServer } from 'http';
|
|
6
|
+
import { generateKeyPair, exportJWK, SignJWT } from 'jose';
|
|
7
|
+
|
|
8
|
+
// src/testing/core-ops.ts
|
|
9
|
+
var coreOps = {
|
|
10
|
+
ops: {
|
|
11
|
+
health: (client) => client.health(),
|
|
12
|
+
ping: (client) => client.ping(),
|
|
13
|
+
serverVersion: (client) => client.serverVersion(),
|
|
14
|
+
close: (client) => client.close()
|
|
15
|
+
},
|
|
16
|
+
dispose: (client) => client.close()
|
|
17
|
+
};
|
|
18
|
+
function toPlain(value) {
|
|
19
|
+
if (value instanceof Map) {
|
|
20
|
+
return Object.fromEntries([...value.entries()].map(([k, v]) => [String(k), toPlain(v)]));
|
|
21
|
+
}
|
|
22
|
+
if (value instanceof Set) return [...value].map(toPlain);
|
|
23
|
+
if (Array.isArray(value)) return value.map(toPlain);
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
function subsetEquals(actual, expected) {
|
|
27
|
+
const a = toPlain(actual);
|
|
28
|
+
if (Array.isArray(expected)) {
|
|
29
|
+
return Array.isArray(a) && a.length === expected.length && expected.every((e, i) => subsetEquals(a[i], e));
|
|
30
|
+
}
|
|
31
|
+
if (expected !== null && typeof expected === "object") {
|
|
32
|
+
if (a === null || typeof a !== "object" || Array.isArray(a)) return false;
|
|
33
|
+
const obj = a;
|
|
34
|
+
return Object.entries(expected).every(([k, v]) => subsetEquals(obj[k], v));
|
|
35
|
+
}
|
|
36
|
+
return isDeepStrictEqual(a, expected);
|
|
37
|
+
}
|
|
38
|
+
function sizeOf(value) {
|
|
39
|
+
if (Array.isArray(value)) return value.length;
|
|
40
|
+
if (value instanceof Map || value instanceof Set) return value.size;
|
|
41
|
+
if (typeof value === "string") return value.length;
|
|
42
|
+
if (value !== null && typeof value === "object") {
|
|
43
|
+
const obj = value;
|
|
44
|
+
if (Array.isArray(obj.spans)) return obj.spans.length;
|
|
45
|
+
if (Array.isArray(obj.records)) return obj.records.length;
|
|
46
|
+
return Object.keys(obj).length;
|
|
47
|
+
}
|
|
48
|
+
throw new Error(`cannot count a ${value === null ? "null" : typeof value}`);
|
|
49
|
+
}
|
|
50
|
+
function stringForms(value) {
|
|
51
|
+
const forms = [];
|
|
52
|
+
try {
|
|
53
|
+
forms.push(String(value));
|
|
54
|
+
} catch {
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
const json = JSON.stringify(toPlain(value));
|
|
58
|
+
if (typeof json === "string") forms.push(json);
|
|
59
|
+
} catch {
|
|
60
|
+
}
|
|
61
|
+
forms.push(inspect(value, { depth: 20, maxArrayLength: null, maxStringLength: null }));
|
|
62
|
+
return forms;
|
|
63
|
+
}
|
|
64
|
+
function sortKey(item) {
|
|
65
|
+
if (typeof item === "string") return item;
|
|
66
|
+
if (item !== null && typeof item === "object") {
|
|
67
|
+
const obj = item;
|
|
68
|
+
if (typeof obj.name === "string") return obj.name;
|
|
69
|
+
if (typeof obj.id === "string") return obj.id;
|
|
70
|
+
}
|
|
71
|
+
return String(item);
|
|
72
|
+
}
|
|
73
|
+
function containsValue(actual, needle) {
|
|
74
|
+
if (typeof actual === "string") return typeof needle === "string" && actual.includes(needle);
|
|
75
|
+
const list = actual instanceof Map ? [...actual.keys()] : actual instanceof Set ? [...actual] : actual;
|
|
76
|
+
if (Array.isArray(list))
|
|
77
|
+
return list.some(
|
|
78
|
+
(item) => isDeepStrictEqual(item, needle) || needle !== null && typeof needle === "object" && subsetEquals(item, needle)
|
|
79
|
+
);
|
|
80
|
+
if (actual !== null && typeof actual === "object" && typeof needle === "string")
|
|
81
|
+
return needle in actual;
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
function typeName(value) {
|
|
85
|
+
if (Array.isArray(value)) return "array";
|
|
86
|
+
if (value === null) return "null";
|
|
87
|
+
return typeof value;
|
|
88
|
+
}
|
|
89
|
+
function checkTree(value, tree) {
|
|
90
|
+
const spans = value?.spans;
|
|
91
|
+
if (!Array.isArray(spans)) throw new Error("tree: result has no spans");
|
|
92
|
+
const list = spans;
|
|
93
|
+
for (const [parentName, children] of Object.entries(tree)) {
|
|
94
|
+
const parents = list.filter((s) => s.name === parentName);
|
|
95
|
+
if (parents.length === 0) throw new Error(`tree: no span named "${parentName}"`);
|
|
96
|
+
const ids = new Set(parents.map((p) => p.spanId));
|
|
97
|
+
const actual = list.filter((s) => s.parentSpanId !== void 0 && ids.has(s.parentSpanId)).map((s) => s.name);
|
|
98
|
+
const absent = children.filter((c) => !actual.includes(c));
|
|
99
|
+
if (absent.length > 0) {
|
|
100
|
+
throw new Error(
|
|
101
|
+
`tree: "${parentName}" lacks children ${JSON.stringify(absent)} (has ${JSON.stringify(actual)})`
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function describe(value) {
|
|
107
|
+
return inspect(value, { depth: 4, breakLength: Infinity });
|
|
108
|
+
}
|
|
109
|
+
function checkExpectations(value, expect) {
|
|
110
|
+
if (expect.reveal !== void 0) {
|
|
111
|
+
const v = value;
|
|
112
|
+
if (typeof v?.reveal !== "function") throw new Error("reveal: result is not a SecretValue");
|
|
113
|
+
if (v.reveal() !== expect.reveal)
|
|
114
|
+
throw new Error("reveal: value differs from the expected text");
|
|
115
|
+
}
|
|
116
|
+
if ("equals" in expect && !subsetEquals(value, expect.equals)) {
|
|
117
|
+
throw new Error(`equals: expected ${describe(expect.equals)}, got ${describe(value)}`);
|
|
118
|
+
}
|
|
119
|
+
if (expect.null === true && value !== null && value !== void 0)
|
|
120
|
+
throw new Error(`null: got ${describe(value)}`);
|
|
121
|
+
if (expect.notNull === true && (value === null || value === void 0))
|
|
122
|
+
throw new Error("notNull: got null");
|
|
123
|
+
if (expect.true === true && value !== true) throw new Error(`true: got ${describe(value)}`);
|
|
124
|
+
if (expect.false === true && value !== false) throw new Error(`false: got ${describe(value)}`);
|
|
125
|
+
if ("contains" in expect && !containsValue(value, expect.contains)) {
|
|
126
|
+
throw new Error(`contains: ${describe(expect.contains)} not found in ${describe(value)}`);
|
|
127
|
+
}
|
|
128
|
+
if ("notContains" in expect && containsValue(value, expect.notContains)) {
|
|
129
|
+
throw new Error(`notContains: ${describe(expect.notContains)} found`);
|
|
130
|
+
}
|
|
131
|
+
if (expect.count !== void 0 && sizeOf(value) !== expect.count) {
|
|
132
|
+
throw new Error(`count: expected ${expect.count}, got ${sizeOf(value)}`);
|
|
133
|
+
}
|
|
134
|
+
if (expect.minCount !== void 0 && sizeOf(value) < expect.minCount) {
|
|
135
|
+
throw new Error(`minCount: expected >= ${expect.minCount}, got ${sizeOf(value)}`);
|
|
136
|
+
}
|
|
137
|
+
if (expect.sorted === true) {
|
|
138
|
+
if (!Array.isArray(value)) throw new Error("sorted: result is not an array");
|
|
139
|
+
const keys = value.map(sortKey);
|
|
140
|
+
for (let i = 1; i < keys.length; i++) {
|
|
141
|
+
if (keys[i - 1] > keys[i])
|
|
142
|
+
throw new Error(`sorted: "${keys[i - 1]}" before "${keys[i]}"`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (expect.type !== void 0 && typeName(value) !== expect.type) {
|
|
146
|
+
throw new Error(`type: expected ${expect.type}, got ${typeName(value)}`);
|
|
147
|
+
}
|
|
148
|
+
if (expect.stringForm !== void 0) {
|
|
149
|
+
const forms = stringForms(value);
|
|
150
|
+
const { contains, notContains } = expect.stringForm;
|
|
151
|
+
if (notContains !== void 0 && forms.some((f) => f.includes(notContains))) {
|
|
152
|
+
throw new Error("stringForm: the string form contains a forbidden value");
|
|
153
|
+
}
|
|
154
|
+
if (contains !== void 0 && !forms.some((f) => f.includes(contains))) {
|
|
155
|
+
throw new Error(`stringForm: no string form contains ${JSON.stringify(contains)}`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (expect.tree !== void 0) checkTree(value, expect.tree);
|
|
159
|
+
}
|
|
160
|
+
async function pollForExpectation(fn, args, context, options = {}) {
|
|
161
|
+
const expect = context.step.expect;
|
|
162
|
+
if (expect === void 0 || expect.error !== void 0) return fn();
|
|
163
|
+
const expectation = context.substitute(expect);
|
|
164
|
+
let last;
|
|
165
|
+
try {
|
|
166
|
+
return await pollUntil(
|
|
167
|
+
async () => {
|
|
168
|
+
last = { value: await fn() };
|
|
169
|
+
return last.value;
|
|
170
|
+
},
|
|
171
|
+
(value) => {
|
|
172
|
+
try {
|
|
173
|
+
checkExpectations(value, expectation);
|
|
174
|
+
return true;
|
|
175
|
+
} catch {
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
timeoutMs: typeof args.timeoutMs === "number" ? args.timeoutMs : options.defaultTimeoutMs ?? 6e4,
|
|
181
|
+
intervalMs: typeof args.intervalMs === "number" ? args.intervalMs : 1e3,
|
|
182
|
+
operation: options.operation ?? "poll"
|
|
183
|
+
}
|
|
184
|
+
);
|
|
185
|
+
} catch (error) {
|
|
186
|
+
if (error instanceof TimeoutError && last !== void 0) return last.value;
|
|
187
|
+
throw error;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// src/testing/ops.ts
|
|
192
|
+
var builtinOps = Object.freeze({
|
|
193
|
+
core: coreOps
|
|
194
|
+
});
|
|
195
|
+
var registry = /* @__PURE__ */ new Map();
|
|
196
|
+
function registerOps(category, ops) {
|
|
197
|
+
const normalized = isCategoryOps(ops) ? ops : { ops };
|
|
198
|
+
const prev = registry.get(category);
|
|
199
|
+
registry.set(category, prev === void 0 ? normalized : mergeOps(prev, normalized));
|
|
200
|
+
}
|
|
201
|
+
function resetRegisteredOps() {
|
|
202
|
+
registry.clear();
|
|
203
|
+
}
|
|
204
|
+
function isCategoryOps(value) {
|
|
205
|
+
return typeof value.ops === "object" && typeof value.ops !== "function";
|
|
206
|
+
}
|
|
207
|
+
function mergeOps(base, over) {
|
|
208
|
+
const merged = { ops: { ...base.ops, ...over.ops } };
|
|
209
|
+
const dispose = over.dispose ?? base.dispose;
|
|
210
|
+
const variables = over.variables ?? base.variables;
|
|
211
|
+
if (dispose !== void 0) merged.dispose = dispose;
|
|
212
|
+
if (variables !== void 0) merged.variables = variables;
|
|
213
|
+
return merged;
|
|
214
|
+
}
|
|
215
|
+
function resolveOps(category, extra) {
|
|
216
|
+
let ops = builtinOps[category];
|
|
217
|
+
const registered = registry.get(category);
|
|
218
|
+
if (registered !== void 0) ops = ops === void 0 ? registered : mergeOps(ops, registered);
|
|
219
|
+
const more = extra?.[category];
|
|
220
|
+
if (more !== void 0) {
|
|
221
|
+
const normalized = isCategoryOps(more) ? more : { ops: more };
|
|
222
|
+
ops = ops === void 0 ? normalized : mergeOps(ops, normalized);
|
|
223
|
+
}
|
|
224
|
+
return ops;
|
|
225
|
+
}
|
|
226
|
+
function randomRunId() {
|
|
227
|
+
const alphabet = "abcdefghijklmnopqrstuvwxyz0123456789";
|
|
228
|
+
let out = "";
|
|
229
|
+
for (let i = 0; i < 8; i++)
|
|
230
|
+
out += alphabet[Math.floor(Math.random() * alphabet.length)];
|
|
231
|
+
return out;
|
|
232
|
+
}
|
|
233
|
+
function loadScenarios(scenariosDir) {
|
|
234
|
+
const files = readdirSync(scenariosDir).filter((f) => f.endsWith(".json"));
|
|
235
|
+
const scenarios = files.map((f) => {
|
|
236
|
+
const parsed = JSON.parse(readFileSync(join(scenariosDir, f), "utf8"));
|
|
237
|
+
if (typeof parsed.id !== "string" || typeof parsed.category !== "string" || !Array.isArray(parsed.steps)) {
|
|
238
|
+
throw new Error(`invalid scenario file ${f}`);
|
|
239
|
+
}
|
|
240
|
+
return parsed;
|
|
241
|
+
});
|
|
242
|
+
return scenarios.sort((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
|
|
243
|
+
}
|
|
244
|
+
var VAR = /\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g;
|
|
245
|
+
var WHOLE_VAR = /^\$\{([A-Za-z_][A-Za-z0-9_]*)\}$/;
|
|
246
|
+
function substitute(value, vars) {
|
|
247
|
+
const lookup = (name) => {
|
|
248
|
+
if (!(name in vars)) throw new Error(`unknown variable \${${name}}`);
|
|
249
|
+
return vars[name];
|
|
250
|
+
};
|
|
251
|
+
const walk = (v) => {
|
|
252
|
+
if (typeof v === "string") {
|
|
253
|
+
const whole = WHOLE_VAR.exec(v);
|
|
254
|
+
if (whole !== null) return lookup(whole[1]);
|
|
255
|
+
return v.replace(VAR, (_m, name) => String(lookup(name)));
|
|
256
|
+
}
|
|
257
|
+
if (Array.isArray(v)) return v.map(walk);
|
|
258
|
+
if (v !== null && typeof v === "object") {
|
|
259
|
+
return Object.fromEntries(
|
|
260
|
+
Object.entries(v).map(([k, x]) => [
|
|
261
|
+
k.replace(VAR, (_m, name) => String(lookup(name))),
|
|
262
|
+
walk(x)
|
|
263
|
+
])
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
return v;
|
|
267
|
+
};
|
|
268
|
+
return walk(value);
|
|
269
|
+
}
|
|
270
|
+
function capabilitySet(options, category) {
|
|
271
|
+
const caps = options.capabilities;
|
|
272
|
+
if (caps === void 0) return /* @__PURE__ */ new Set();
|
|
273
|
+
if (Array.isArray(caps)) return new Set(caps);
|
|
274
|
+
return new Set(caps[category] ?? []);
|
|
275
|
+
}
|
|
276
|
+
function missing(requires, caps) {
|
|
277
|
+
return (requires ?? []).filter((r) => !caps.has(r));
|
|
278
|
+
}
|
|
279
|
+
function message(err) {
|
|
280
|
+
if (err instanceof Error) {
|
|
281
|
+
const code = err.code;
|
|
282
|
+
return typeof code === "string" ? `${code}: ${err.message}` : err.message;
|
|
283
|
+
}
|
|
284
|
+
return String(err);
|
|
285
|
+
}
|
|
286
|
+
function planScenarios(options) {
|
|
287
|
+
const categories = new Set(options.categories ?? Object.keys(options.factories));
|
|
288
|
+
for (const c of categories) {
|
|
289
|
+
if (options.factories[c] === void 0) {
|
|
290
|
+
throw new Error(`conformance: no factory for category "${c}"`);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return loadScenarios(options.scenariosDir).filter((s) => categories.has(s.category)).filter((s) => options.only === void 0 || options.only.includes(s.id)).map((scenario) => {
|
|
294
|
+
const lacking = missing(scenario.requires, capabilitySet(options, scenario.category));
|
|
295
|
+
return lacking.length > 0 ? { scenario, skipReason: `missing capabilities: ${lacking.join(", ")}` } : { scenario };
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
async function runScenario(scenario, options) {
|
|
299
|
+
const started = performance.now();
|
|
300
|
+
const caps = capabilitySet(options, scenario.category);
|
|
301
|
+
const result = {
|
|
302
|
+
id: scenario.id,
|
|
303
|
+
category: scenario.category,
|
|
304
|
+
status: "passed",
|
|
305
|
+
steps: [],
|
|
306
|
+
durationMs: 0
|
|
307
|
+
};
|
|
308
|
+
const lacking = missing(scenario.requires, caps);
|
|
309
|
+
if (lacking.length > 0) {
|
|
310
|
+
result.status = "skipped";
|
|
311
|
+
result.skipReason = `missing capabilities: ${lacking.join(", ")}`;
|
|
312
|
+
return result;
|
|
313
|
+
}
|
|
314
|
+
const category = resolveOps(scenario.category, options.ops);
|
|
315
|
+
const factory = options.factories[scenario.category];
|
|
316
|
+
if (category === void 0 || factory === void 0) {
|
|
317
|
+
result.status = "failed";
|
|
318
|
+
result.error = category === void 0 ? `no op handlers for category "${scenario.category}"` : `no factory for category "${scenario.category}"`;
|
|
319
|
+
return result;
|
|
320
|
+
}
|
|
321
|
+
const run = (options.runId ?? randomRunId)();
|
|
322
|
+
const vars = { ...options.variables, run };
|
|
323
|
+
const prefix = substitute(options.prefix ?? "grow-conformance/${run}/", vars);
|
|
324
|
+
vars.prefix = prefix;
|
|
325
|
+
const cleanups = [];
|
|
326
|
+
let currentStep = scenario.steps[0] ?? { op: "" };
|
|
327
|
+
const context = {
|
|
328
|
+
scenario,
|
|
329
|
+
get step() {
|
|
330
|
+
return currentStep;
|
|
331
|
+
},
|
|
332
|
+
run,
|
|
333
|
+
prefix,
|
|
334
|
+
vars,
|
|
335
|
+
capabilities: caps,
|
|
336
|
+
substitute: (v) => substitute(v, vars),
|
|
337
|
+
onCleanup: (fn) => {
|
|
338
|
+
cleanups.push(fn);
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
let target;
|
|
342
|
+
try {
|
|
343
|
+
target = await factory({
|
|
344
|
+
scenario,
|
|
345
|
+
run,
|
|
346
|
+
prefix,
|
|
347
|
+
...scenario.batchOptions === void 0 ? {} : { batchOptions: scenario.batchOptions }
|
|
348
|
+
});
|
|
349
|
+
Object.assign(vars, category.variables?.(target) ?? {}, { ...options.variables, run, prefix });
|
|
350
|
+
for (const [index, step] of scenario.steps.entries()) {
|
|
351
|
+
currentStep = step;
|
|
352
|
+
const stepStart = performance.now();
|
|
353
|
+
const stepResult = { index, op: step.op, status: "passed", durationMs: 0 };
|
|
354
|
+
result.steps.push(stepResult);
|
|
355
|
+
const stepLacking = missing(step.requires, caps);
|
|
356
|
+
if (stepLacking.length > 0) {
|
|
357
|
+
stepResult.status = "skipped";
|
|
358
|
+
stepResult.skipReason = `missing capabilities: ${stepLacking.join(", ")}`;
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
361
|
+
try {
|
|
362
|
+
const handler = category.ops[step.op];
|
|
363
|
+
if (handler === void 0)
|
|
364
|
+
throw new Error(`unknown op "${step.op}" for category ${scenario.category}`);
|
|
365
|
+
const args = substitute(step.args ?? {}, vars);
|
|
366
|
+
const expectation = step.expect === void 0 ? void 0 : substitute(step.expect, vars);
|
|
367
|
+
let value;
|
|
368
|
+
let thrown;
|
|
369
|
+
let failed = false;
|
|
370
|
+
try {
|
|
371
|
+
value = await handler(target, args, context);
|
|
372
|
+
} catch (err) {
|
|
373
|
+
failed = true;
|
|
374
|
+
thrown = err;
|
|
375
|
+
}
|
|
376
|
+
if (expectation?.error !== void 0) {
|
|
377
|
+
if (!failed) throw new Error(`expected error ${expectation.error} but the op succeeded`);
|
|
378
|
+
const code = thrown.code;
|
|
379
|
+
if (code !== expectation.error) {
|
|
380
|
+
throw new Error(`expected error ${expectation.error}, got ${message(thrown)}`);
|
|
381
|
+
}
|
|
382
|
+
} else {
|
|
383
|
+
if (failed) throw thrown;
|
|
384
|
+
if (expectation !== void 0) checkExpectations(value, expectation);
|
|
385
|
+
if (step.save !== void 0) vars[step.save] = value;
|
|
386
|
+
}
|
|
387
|
+
} catch (err) {
|
|
388
|
+
stepResult.status = "failed";
|
|
389
|
+
stepResult.error = message(err);
|
|
390
|
+
result.status = "failed";
|
|
391
|
+
result.error = `step ${index} (${step.op}): ${stepResult.error}`;
|
|
392
|
+
break;
|
|
393
|
+
} finally {
|
|
394
|
+
stepResult.durationMs = performance.now() - stepStart;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
} catch (err) {
|
|
398
|
+
result.status = "failed";
|
|
399
|
+
result.error = `setup: ${message(err)}`;
|
|
400
|
+
} finally {
|
|
401
|
+
if (target !== void 0 && category.dispose !== void 0) {
|
|
402
|
+
try {
|
|
403
|
+
await category.dispose(target, context);
|
|
404
|
+
} catch (err) {
|
|
405
|
+
if (result.status !== "failed") {
|
|
406
|
+
result.status = "failed";
|
|
407
|
+
result.error = `dispose: ${message(err)}`;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
for (const fn of cleanups.reverse()) {
|
|
412
|
+
try {
|
|
413
|
+
await fn();
|
|
414
|
+
} catch {
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
result.durationMs = performance.now() - started;
|
|
418
|
+
}
|
|
419
|
+
return result;
|
|
420
|
+
}
|
|
421
|
+
async function runConformance(options) {
|
|
422
|
+
const results = [];
|
|
423
|
+
for (const { scenario } of planScenarios(options)) {
|
|
424
|
+
results.push(await runScenario(scenario, options));
|
|
425
|
+
}
|
|
426
|
+
const count = (s) => results.filter((r) => r.status === s).length;
|
|
427
|
+
const failed = count("failed");
|
|
428
|
+
return { ok: failed === 0, passed: count("passed"), failed, skipped: count("skipped"), results };
|
|
429
|
+
}
|
|
430
|
+
function formatReport(report) {
|
|
431
|
+
const lines = report.results.map((r) => {
|
|
432
|
+
const extra = r.status === "failed" ? ` \u2014 ${r.error ?? ""}` : r.status === "skipped" ? ` \u2014 ${r.skipReason ?? ""}` : "";
|
|
433
|
+
const skippedSteps = r.steps.filter((s) => s.status === "skipped").map((s) => `${s.op}#${s.index}`);
|
|
434
|
+
const stepNote = skippedSteps.length > 0 ? ` (skipped steps: ${skippedSteps.join(", ")})` : "";
|
|
435
|
+
return `${r.status.toUpperCase().padEnd(7)} ${r.id}${extra}${stepNote}`;
|
|
436
|
+
});
|
|
437
|
+
lines.push(`passed ${report.passed}, failed ${report.failed}, skipped ${report.skipped}`);
|
|
438
|
+
return lines.join("\n");
|
|
439
|
+
}
|
|
440
|
+
function assertConformance(report) {
|
|
441
|
+
if (!report.ok) throw new Error(`conformance failed:
|
|
442
|
+
${formatReport(report)}`);
|
|
443
|
+
}
|
|
444
|
+
function conformanceCases(options) {
|
|
445
|
+
return planScenarios(options).map(({ scenario, skipReason }) => ({
|
|
446
|
+
id: scenario.id,
|
|
447
|
+
category: scenario.category,
|
|
448
|
+
...skipReason === void 0 ? {} : { skip: skipReason },
|
|
449
|
+
run: async () => {
|
|
450
|
+
const result = await runScenario(scenario, options);
|
|
451
|
+
if (result.status === "failed")
|
|
452
|
+
throw new Error(`${scenario.id}: ${result.error ?? "failed"}`);
|
|
453
|
+
return result;
|
|
454
|
+
}
|
|
455
|
+
}));
|
|
456
|
+
}
|
|
457
|
+
var FakeIdp = class {
|
|
458
|
+
/** Issuer URL (`http://127.0.0.1:<port>`), set by {@link start}. */
|
|
459
|
+
issuer = "";
|
|
460
|
+
/** Audience put into minted tokens. */
|
|
461
|
+
audience;
|
|
462
|
+
/** Keys published in the JWKS. */
|
|
463
|
+
keys = [];
|
|
464
|
+
/** Request counters per path. */
|
|
465
|
+
hits = {};
|
|
466
|
+
/** When set, the server answers every request with this status. */
|
|
467
|
+
failStatus;
|
|
468
|
+
#server;
|
|
469
|
+
#current = "";
|
|
470
|
+
#counter = 0;
|
|
471
|
+
constructor(audience = "test-client") {
|
|
472
|
+
this.audience = audience;
|
|
473
|
+
}
|
|
474
|
+
/** Starts the server and creates the first key (`alg`, default RS256). */
|
|
475
|
+
async start(alg = "RS256") {
|
|
476
|
+
const server = createServer((req, res) => {
|
|
477
|
+
const path = (req.url ?? "/").split("?")[0] ?? "/";
|
|
478
|
+
this.hits[path] = (this.hits[path] ?? 0) + 1;
|
|
479
|
+
if (this.failStatus !== void 0) {
|
|
480
|
+
res.writeHead(this.failStatus).end();
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
let body;
|
|
484
|
+
if (path === "/.well-known/openid-configuration") {
|
|
485
|
+
body = {
|
|
486
|
+
issuer: this.issuer,
|
|
487
|
+
jwks_uri: `${this.issuer}/jwks`,
|
|
488
|
+
id_token_signing_alg_values_supported: [...DEFAULT_ALGORITHMS]
|
|
489
|
+
};
|
|
490
|
+
} else if (path === "/jwks") {
|
|
491
|
+
body = { keys: this.keys.map((key) => key.publicJwk) };
|
|
492
|
+
} else {
|
|
493
|
+
res.writeHead(404).end();
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
res.writeHead(200, { "content-type": "application/json" }).end(JSON.stringify(body));
|
|
497
|
+
});
|
|
498
|
+
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|
499
|
+
this.#server = server;
|
|
500
|
+
this.issuer = `http://127.0.0.1:${server.address().port}`;
|
|
501
|
+
await this.rotate(alg);
|
|
502
|
+
return this;
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Adds a new key of `alg` (any supported algorithm; EC curves follow the algorithm, RSA keys are
|
|
506
|
+
* 2048-bit) and makes it current (the old keys stay published until removed).
|
|
507
|
+
*/
|
|
508
|
+
async rotate(alg = "RS256") {
|
|
509
|
+
this.#counter += 1;
|
|
510
|
+
const kid = `key-${this.#counter}`;
|
|
511
|
+
const { privateKey, publicKey } = await generateKeyPair(
|
|
512
|
+
alg,
|
|
513
|
+
alg === "EdDSA" ? { crv: "Ed25519" } : {}
|
|
514
|
+
);
|
|
515
|
+
const publicJwk = { ...await exportJWK(publicKey), kid, alg, use: "sig" };
|
|
516
|
+
const key = { kid, alg, privateKey, publicJwk };
|
|
517
|
+
this.keys.push(key);
|
|
518
|
+
this.#current = kid;
|
|
519
|
+
return key;
|
|
520
|
+
}
|
|
521
|
+
/** Removes a key from the JWKS. */
|
|
522
|
+
removeKey(kid) {
|
|
523
|
+
const index = this.keys.findIndex((key) => key.kid === kid);
|
|
524
|
+
if (index >= 0) this.keys.splice(index, 1);
|
|
525
|
+
}
|
|
526
|
+
/** Signs a token with the current (or the given) key. */
|
|
527
|
+
async mint(options = {}) {
|
|
528
|
+
const kid = options.kid ?? this.#current;
|
|
529
|
+
const key = this.keys.find((candidate) => candidate.kid === kid);
|
|
530
|
+
if (key === void 0) throw new Error(`fake idp: unknown kid ${kid}`);
|
|
531
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
532
|
+
const claims = {
|
|
533
|
+
iss: this.issuer,
|
|
534
|
+
aud: this.audience,
|
|
535
|
+
sub: "user-1",
|
|
536
|
+
iat: now,
|
|
537
|
+
exp: now + (options.ttlSeconds ?? 300),
|
|
538
|
+
...options.claims
|
|
539
|
+
};
|
|
540
|
+
for (const [name, value] of Object.entries(claims))
|
|
541
|
+
if (value === void 0) Reflect.deleteProperty(claims, name);
|
|
542
|
+
const header = {
|
|
543
|
+
alg: key.alg,
|
|
544
|
+
kid: key.kid,
|
|
545
|
+
typ: "JWT",
|
|
546
|
+
...options.header
|
|
547
|
+
};
|
|
548
|
+
for (const [name, value] of Object.entries(header))
|
|
549
|
+
if (value === void 0) Reflect.deleteProperty(header, name);
|
|
550
|
+
return new SignJWT(claims).setProtectedHeader(header).sign(key.privateKey);
|
|
551
|
+
}
|
|
552
|
+
/** Stops the server. */
|
|
553
|
+
async stop() {
|
|
554
|
+
const server = this.#server;
|
|
555
|
+
this.#server = void 0;
|
|
556
|
+
if (server !== void 0) {
|
|
557
|
+
server.closeAllConnections();
|
|
558
|
+
await new Promise((resolve) => {
|
|
559
|
+
server.close(() => {
|
|
560
|
+
resolve();
|
|
561
|
+
});
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
};
|
|
566
|
+
|
|
567
|
+
export { FakeIdp, assertConformance, builtinOps, checkExpectations, conformanceCases, coreOps, formatReport, loadScenarios, planScenarios, pollForExpectation, randomRunId, registerOps, resetRegisteredOps, resolveOps, runConformance, runScenario, sizeOf, stringForms, subsetEquals, substitute, toPlain };
|
|
568
|
+
//# sourceMappingURL=index.js.map
|
|
569
|
+
//# sourceMappingURL=index.js.map
|