@ultimat3/testing 30.9.0 → 31.1.0
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/CLAUDE.md +46 -55
- package/README.md +179 -39
- package/package.json +23 -17
- package/src/ai-conformance-answer.ts +67 -0
- package/src/ai-gateway-conformance.ts +105 -0
- package/src/ai-provider-conformance.ts +69 -0
- package/src/ai-provider-transport-conformance.ts +170 -0
- package/src/audit-sink-conformance.ts +204 -0
- package/src/auth-adapter-conformance-credentials.ts +124 -0
- package/src/auth-adapter-conformance-mfa.ts +70 -0
- package/src/auth-adapter-conformance-passkeys.ts +133 -0
- package/src/auth-adapter-conformance-sessions.ts +115 -0
- package/src/auth-adapter-conformance-support.ts +71 -0
- package/src/auth-adapter-conformance-users.ts +128 -0
- package/src/auth-adapter-conformance.ts +34 -0
- package/src/auth-limiter-factory-conformance.ts +224 -0
- package/src/auth-server-store-conformance-records.ts +69 -0
- package/src/auth-server-store-conformance.ts +208 -0
- package/src/cache-tier-conformance-checks.ts +142 -0
- package/src/cache-tier-conformance.ts +24 -0
- package/src/cassette-format.ts +8 -13
- package/src/cassette-record.ts +1 -1
- package/src/cdp-browser.ts +10 -11
- package/src/cdp-e2e-page.ts +2 -2
- package/src/cdp-e2e-session.ts +2 -2
- package/src/cdp-network-probe.ts +1 -1
- package/src/cdp-offline-script.ts +2 -2
- package/src/clock-conformance.ts +126 -0
- package/src/conformance.ts +239 -0
- package/src/e2e-browser-handle.ts +1 -2
- package/src/e2e-error-codes.ts +17 -16
- package/src/e2e-run.ts +4 -3
- package/src/embedder-conformance.ts +101 -0
- package/src/entity-conformance-aggregates.ts +210 -0
- package/src/entity-conformance-batches.ts +216 -0
- package/src/entity-conformance-bulk.ts +379 -0
- package/src/entity-conformance-checks.ts +27 -0
- package/src/entity-conformance-entities.ts +52 -0
- package/src/entity-conformance-locks.ts +286 -0
- package/src/entity-conformance-matrix.ts +397 -0
- package/src/entity-conformance-reads.ts +241 -0
- package/src/entity-conformance-support.ts +56 -0
- package/src/entity-conformance-tenancy.ts +296 -0
- package/src/entity-conformance-values.ts +305 -0
- package/src/entity-conformance-versions.ts +60 -0
- package/src/entity-conformance-writes.ts +348 -0
- package/src/entity-driver-conformance.ts +103 -0
- package/src/error-groups-store-conformance.ts +198 -0
- package/src/error-reporter-conformance.ts +119 -0
- package/src/errors.ts +20 -2
- package/src/event-bus-conformance.ts +161 -0
- package/src/exercise-drift-hint.ts +4 -1
- package/src/exercise-judge.ts +5 -3
- package/src/exercise-override-line.ts +98 -0
- package/src/exercise-report.ts +138 -115
- package/src/exercise-room-mail.ts +40 -0
- package/src/exercise.ts +33 -29
- package/src/factories.ts +192 -179
- package/src/factory-api.ts +131 -0
- package/src/factory-associations.ts +67 -0
- package/src/factory-errors.ts +38 -0
- package/src/factory-lint.ts +92 -0
- package/src/factory-persist.ts +74 -16
- package/src/factory-pipeline.ts +191 -0
- package/src/factory-registry.ts +2 -1
- package/src/factory-types.ts +131 -0
- package/src/failure-store-conformance.ts +137 -0
- package/src/fixture-jobs.ts +27 -11
- package/src/fixture-mail.ts +7 -7
- package/src/fixture-seed.ts +111 -0
- package/src/fixture-statements.ts +68 -52
- package/src/framework-fixtures.ts +1 -1
- package/src/idempotency-store-conformance.ts +186 -0
- package/src/idempotency-store-replay-conformance.ts +140 -0
- package/src/idempotency-store-tx-conformance.ts +132 -0
- package/src/idempotency-store-world-conformance.ts +82 -0
- package/src/identity-provider-conformance.ts +144 -0
- package/src/image-transform-conformance.ts +89 -0
- package/src/index.ts +68 -157
- package/src/isr-store-conformance.ts +113 -0
- package/src/job-sim-effects.ts +19 -31
- package/src/job-sim-world.ts +6 -15
- package/src/lease-store-conformance.ts +195 -0
- package/src/mail-driver-conformance.ts +108 -0
- package/src/matcher-doubles.ts +104 -0
- package/src/matcher-stub.ts +78 -0
- package/src/matcher-surface.ts +21 -0
- package/src/matchers.ts +19 -1
- package/src/mcp-confirmation-store-conformance.ts +262 -0
- package/src/meter-store-conformance.ts +135 -0
- package/src/notify-digest-conformance.ts +133 -0
- package/src/notify-inbox-conformance.ts +130 -0
- package/src/notify-ledger-conformance.ts +134 -0
- package/src/notify-preference-conformance.ts +49 -0
- package/src/notify-stores-conformance.ts +73 -0
- package/src/outbox-store-conformance-claims.ts +112 -0
- package/src/outbox-store-conformance-subject.ts +65 -0
- package/src/outbox-store-conformance.ts +71 -0
- package/src/per-test-reset.ts +55 -20
- package/src/preload.ts +4 -2
- package/src/purge-conformance.ts +79 -0
- package/src/push-device-conformance.ts +124 -0
- package/src/push-subscription-conformance.ts +123 -0
- package/src/quiet-logs.ts +4 -4
- package/src/rate-limit-store-conformance.ts +178 -0
- package/src/registry-leak-error.ts +8 -1
- package/src/scale-sweep-run.ts +6 -9
- package/src/scrape-driver-conformance-frame-checks.ts +97 -0
- package/src/scrape-driver-conformance-page-checks.ts +114 -0
- package/src/scrape-driver-conformance-site.ts +84 -0
- package/src/scrape-driver-conformance.ts +34 -0
- package/src/sealed-network.ts +20 -2
- package/src/search-index-conformance-list.ts +76 -0
- package/src/search-index-conformance-support.ts +69 -0
- package/src/search-index-conformance-versions.ts +66 -0
- package/src/search-index-conformance.ts +126 -0
- package/src/secret-source-conformance.ts +91 -0
- package/src/seed-factories.ts +57 -0
- package/src/seed-writer.ts +8 -19
- package/src/semantic-cache-factory-conformance.ts +86 -0
- package/src/sms-transport-conformance.ts +102 -0
- package/src/step-store-conformance.ts +171 -0
- package/src/storage-conformance-read-checks.ts +132 -0
- package/src/storage-conformance-shape.ts +121 -0
- package/src/storage-conformance-stream-checks.ts +226 -0
- package/src/storage-conformance.ts +34 -0
- package/src/stub-action.ts +24 -0
- package/src/stub-errors.ts +86 -0
- package/src/stub-job.ts +30 -0
- package/src/stub-query.ts +25 -0
- package/src/stub-script.ts +76 -0
- package/src/stub-stack.ts +29 -0
- package/src/stub.ts +73 -0
- package/src/swap-adapter.ts +135 -0
- package/src/test-scope.ts +96 -0
- package/src/test-types.ts +1 -1
- package/src/totp-replay-guard-conformance.ts +76 -0
- package/src/transport-conformance.ts +179 -0
- package/src/upload-scanner-conformance.ts +112 -0
- package/src/vector-store-conformance-checks.ts +174 -0
- package/src/vector-store-conformance.ts +21 -0
- package/src/cdp-connection.ts +0 -291
- package/src/cdp-errors.ts +0 -179
- package/src/cdp-launch-attempt.ts +0 -224
- package/src/cdp-launch-candidates.ts +0 -62
- package/src/cdp-launch-profile.ts +0 -106
- package/src/cdp-launch-reap.ts +0 -68
- package/src/cdp-launch-wire.ts +0 -171
- package/src/cdp-launch.ts +0 -175
- package/src/cdp-pipe.ts +0 -77
- package/src/cdp-wire-watch.ts +0 -113
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
// The `IdempotencyStore` contract of `@ultimat3/action` as shared examples, for a store of your own:
|
|
2
|
+
// `behavesLike(idempotencyStoreConformance, () => subject)`. Two halves: the port alone (atomic
|
|
3
|
+
// reserve, the reservation-id fence, the window, the redaction flag), and the store behind
|
|
4
|
+
// `withIdempotency` inside a real transaction (`idempotency-store-{tx,replay}-conformance.ts`).
|
|
5
|
+
|
|
6
|
+
import { expect, test } from 'bun:test';
|
|
7
|
+
import type { IdempotencyStore } from '@ultimat3/action/adapter';
|
|
8
|
+
import { finiteCount } from '@ultimat3/core';
|
|
9
|
+
import type { DbClient } from '@ultimat3/db';
|
|
10
|
+
import { IDEMPOTENCY_REPLAY_CHECKS } from './idempotency-store-replay-conformance';
|
|
11
|
+
import { IDEMPOTENCY_TX_CHECKS } from './idempotency-store-tx-conformance';
|
|
12
|
+
import type { SharedExamples } from './shared-examples';
|
|
13
|
+
import { sharedExamples } from './shared-examples';
|
|
14
|
+
|
|
15
|
+
type Maybe<T> = T | Promise<T>;
|
|
16
|
+
|
|
17
|
+
/** What a store's author hands the suite: the store, and the two things only they can do to it. */
|
|
18
|
+
export interface IdempotencyStoreSubject {
|
|
19
|
+
readonly store: IdempotencyStore;
|
|
20
|
+
/** The database a handler's transaction runs on — the one the store settles inside. */
|
|
21
|
+
readonly client: DbClient;
|
|
22
|
+
/** The request deadline the store was built with (`reclaimAfterMs`), in ms. Above zero. */
|
|
23
|
+
readonly reclaimAfterMs: number;
|
|
24
|
+
/** Make the record under `key` `ms` older, as the store's own clock sees it. */
|
|
25
|
+
age(key: string, ms: number): Promise<void>;
|
|
26
|
+
/** Forget every record. Run before each check. */
|
|
27
|
+
reset(): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface IdempotencyStoreCheck {
|
|
31
|
+
readonly name: string;
|
|
32
|
+
run(subject: IdempotencyStoreSubject): Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** The window every store defaults to: a day. A store built with another one ages past its own. */
|
|
36
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
37
|
+
|
|
38
|
+
let minted = 0;
|
|
39
|
+
/** A key no other check, run or process shares — a shared database outlives one test file. */
|
|
40
|
+
export const idempotencyKeyOf = (): string => {
|
|
41
|
+
minted += 1;
|
|
42
|
+
return `["conformance","${process.pid.toString(36)}","${Date.now().toString(36)}",${minted}]`;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const RACERS = 16;
|
|
46
|
+
|
|
47
|
+
/** The store's own window, screened: `NaN + 1_000` ages nothing, and the check would pass vacuously. */
|
|
48
|
+
const windowOf = (windowMs: number | undefined): number =>
|
|
49
|
+
finiteCount('idempotencyStoreConformance', 'windowMs', windowMs ?? DAY_MS, 1);
|
|
50
|
+
|
|
51
|
+
const PORT_CHECKS: readonly IdempotencyStoreCheck[] = [
|
|
52
|
+
{
|
|
53
|
+
name: 'declares its scope, and that it keeps the redaction flag',
|
|
54
|
+
async run({ store }) {
|
|
55
|
+
expect(['process', 'shared']).toContain(store.scope ?? 'undeclared');
|
|
56
|
+
expect(store.keepsRedaction).toBe(true);
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
name: `${RACERS} concurrent reserves of one fresh key create exactly one record`,
|
|
61
|
+
async run({ store }) {
|
|
62
|
+
const key = idempotencyKeyOf();
|
|
63
|
+
const all = await Promise.all(
|
|
64
|
+
Array.from({ length: RACERS }, () => store.reserve(key, 'hash')),
|
|
65
|
+
);
|
|
66
|
+
expect(all.filter((each) => each.created)).toHaveLength(1);
|
|
67
|
+
expect(new Set(all.map((each) => each.record.id)).size).toBe(1);
|
|
68
|
+
expect(all.every((each) => each.record.status === 'in-flight')).toBe(true);
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
name: 'a settled record is what get answers and what the next reserve replays',
|
|
73
|
+
async run({ store }) {
|
|
74
|
+
const key = idempotencyKeyOf();
|
|
75
|
+
const { record } = await store.reserve(key, 'hash-1');
|
|
76
|
+
expect(record).toMatchObject({ key, requestHash: 'hash-1', status: 'in-flight' });
|
|
77
|
+
const value = { charged: 'ch_1', amount: { minor: 1250, currency: 'EUR' }, tags: ['a'] };
|
|
78
|
+
await store.settle(key, value, record.id, false);
|
|
79
|
+
const held = await store.get(key);
|
|
80
|
+
expect(held).toMatchObject({ id: record.id, status: 'settled', value });
|
|
81
|
+
expect(held?.redacted).not.toBe(true);
|
|
82
|
+
const again = await store.reserve(key, 'hash-1');
|
|
83
|
+
expect(again.created).toBe(false);
|
|
84
|
+
expect(again.record).toMatchObject({ id: record.id, status: 'settled', value });
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
name: 'settle keeps the redaction flag and hands it back',
|
|
89
|
+
async run({ store }) {
|
|
90
|
+
const key = idempotencyKeyOf();
|
|
91
|
+
const { record } = await store.reserve(key, 'hash');
|
|
92
|
+
await store.settle(key, { apiKey: '[redacted]' }, record.id, true);
|
|
93
|
+
expect((await store.get(key))?.redacted).toBe(true);
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: 'a failure settles as failed, with the four fields a replay re-throws',
|
|
98
|
+
async run({ store }) {
|
|
99
|
+
if (store.fail === undefined) return expect.unreachable('this store has no fail()');
|
|
100
|
+
const key = idempotencyKeyOf();
|
|
101
|
+
const { record } = await store.reserve(key, 'hash');
|
|
102
|
+
const failure = {
|
|
103
|
+
code: 'X_FORBIDDEN',
|
|
104
|
+
cause: 'declined',
|
|
105
|
+
fix: 'x verify --only unit --json',
|
|
106
|
+
};
|
|
107
|
+
await store.fail(key, failure, record.id);
|
|
108
|
+
const held = await store.get(key);
|
|
109
|
+
expect(held?.status).toBe('failed');
|
|
110
|
+
expect(held?.failure).toMatchObject(failure);
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
name: 'settle, fail and release are fenced on the reservation id',
|
|
115
|
+
async run({ store }) {
|
|
116
|
+
const key = idempotencyKeyOf();
|
|
117
|
+
const { record } = await store.reserve(key, 'hash');
|
|
118
|
+
const stranger = '00000000-0000-7000-8000-000000000000';
|
|
119
|
+
await store.settle(key, { stolen: true }, stranger, false);
|
|
120
|
+
await store.fail?.(
|
|
121
|
+
key,
|
|
122
|
+
{ code: 'X_INTERNAL', cause: 'c', fix: 'x verify --only unit --json' },
|
|
123
|
+
stranger,
|
|
124
|
+
);
|
|
125
|
+
await store.release(key, stranger);
|
|
126
|
+
expect(await store.get(key)).toMatchObject({ id: record.id, status: 'in-flight' });
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
name: 'release drops the reservation it owns, and the key is free again',
|
|
131
|
+
async run({ store }) {
|
|
132
|
+
const key = idempotencyKeyOf();
|
|
133
|
+
const { record } = await store.reserve(key, 'hash');
|
|
134
|
+
await store.release(key, record.id);
|
|
135
|
+
expect(await store.get(key)).toBeUndefined();
|
|
136
|
+
expect((await store.reserve(key, 'hash')).created).toBe(true);
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
name: 'past the window a record answers as a missing one, its redaction forgotten',
|
|
141
|
+
async run(subject) {
|
|
142
|
+
const { store } = subject;
|
|
143
|
+
const key = idempotencyKeyOf();
|
|
144
|
+
const first = await store.reserve(key, 'hash');
|
|
145
|
+
await store.settle(key, { apiKey: '[redacted]' }, first.record.id, true);
|
|
146
|
+
await subject.age(key, windowOf(store.windowMs) + 1_000);
|
|
147
|
+
expect(await store.get(key)).toBeUndefined();
|
|
148
|
+
const reclaimed = await store.reserve(key, 'hash');
|
|
149
|
+
expect(reclaimed.created).toBe(true);
|
|
150
|
+
expect(reclaimed.record.id).not.toBe(first.record.id);
|
|
151
|
+
expect(reclaimed.record.redacted).not.toBe(true);
|
|
152
|
+
await store.settle(key, { charged: 'ch_2' }, reclaimed.record.id, false);
|
|
153
|
+
expect((await store.get(key))?.redacted).not.toBe(true);
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
name: 'an autocommit reservation that never settled is not reclaimed by the deadline',
|
|
158
|
+
async run(subject) {
|
|
159
|
+
// No transaction: the handler may have committed before the process died.
|
|
160
|
+
const key = idempotencyKeyOf();
|
|
161
|
+
expect((await subject.store.reserve(key, 'hash')).created).toBe(true);
|
|
162
|
+
await subject.age(key, subject.reclaimAfterMs + 1_000);
|
|
163
|
+
const second = await subject.store.reserve(key, 'hash');
|
|
164
|
+
expect(second.created).toBe(false);
|
|
165
|
+
expect(second.record.status).toBe('in-flight');
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
];
|
|
169
|
+
|
|
170
|
+
/** Every check, port first. Each runs against a `reset()` subject. */
|
|
171
|
+
export const IDEMPOTENCY_STORE_CHECKS: readonly IdempotencyStoreCheck[] = [
|
|
172
|
+
...PORT_CHECKS,
|
|
173
|
+
...IDEMPOTENCY_TX_CHECKS,
|
|
174
|
+
...IDEMPOTENCY_REPLAY_CHECKS,
|
|
175
|
+
];
|
|
176
|
+
|
|
177
|
+
export const idempotencyStoreConformance: SharedExamples<Maybe<IdempotencyStoreSubject>> =
|
|
178
|
+
sharedExamples('an idempotency store', (subject) => {
|
|
179
|
+
for (const check of IDEMPOTENCY_STORE_CHECKS) {
|
|
180
|
+
test(check.name, async () => {
|
|
181
|
+
const current = await subject();
|
|
182
|
+
await current.reset();
|
|
183
|
+
await check.run(current);
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
});
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// The replay half of `idempotencyStoreConformance`: an answer at rest holds no credential, and an
|
|
2
|
+
// answer no retry could replay is one verdict on every store — refused first and on replay.
|
|
3
|
+
|
|
4
|
+
import { expect } from 'bun:test';
|
|
5
|
+
import { withIdempotency } from '@ultimat3/action';
|
|
6
|
+
import { finiteCount } from '@ultimat3/core';
|
|
7
|
+
import { withTransaction } from '@ultimat3/db';
|
|
8
|
+
import type { IdempotencyWorldCheck as TxCheck } from './idempotency-store-world-conformance';
|
|
9
|
+
import { codeOf, DAY_MS, world } from './idempotency-store-world-conformance';
|
|
10
|
+
|
|
11
|
+
/** An answer at rest for a day holds no credential, and the replay that lost one is refused. */
|
|
12
|
+
const REDACTION: readonly TxCheck[] = [
|
|
13
|
+
{
|
|
14
|
+
name: 'a secret answer rests [redacted], flagged, and its replay is refused',
|
|
15
|
+
async run(subject) {
|
|
16
|
+
const w = await world(subject);
|
|
17
|
+
expect(await w.once({ id: 'key_1', apiKey: 'sk_live_plaintext' })).toEqual({
|
|
18
|
+
value: { id: 'key_1', apiKey: 'sk_live_plaintext' },
|
|
19
|
+
replayed: false,
|
|
20
|
+
});
|
|
21
|
+
const stored = await subject.store.get(w.key);
|
|
22
|
+
expect(stored?.value).toEqual({ id: 'key_1', apiKey: '[redacted]' });
|
|
23
|
+
expect(stored?.redacted).toBe(true);
|
|
24
|
+
expect(JSON.stringify(stored)).not.toContain('sk_live_plaintext');
|
|
25
|
+
expect(codeOf(await w.once({ id: 'never-run' }).catch((e: unknown) => e))).toBe(
|
|
26
|
+
'X_IDEMPOTENT_REPLAY_REDACTED',
|
|
27
|
+
);
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: 'a secret nested in objects, arrays and toJSON is redacted where it sits',
|
|
32
|
+
async run(subject) {
|
|
33
|
+
const w = await world(subject);
|
|
34
|
+
const leaky = { toJSON: () => ({ apiKey: 'sk_live_tojson' }) };
|
|
35
|
+
await w.once({ logins: [{ label: 'main', password: 'hunter2' }], creds: leaky });
|
|
36
|
+
const stored = await subject.store.get(w.key);
|
|
37
|
+
expect(stored?.value).toMatchObject({ logins: [{ label: 'main', password: '[redacted]' }] });
|
|
38
|
+
expect(JSON.stringify(stored)).not.toContain('sk_live_tojson');
|
|
39
|
+
expect(stored?.redacted).toBe(true);
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: 'a cyclic answer settles redacted, and its replay is refused',
|
|
44
|
+
async run(subject) {
|
|
45
|
+
const w = await world(subject);
|
|
46
|
+
const answer: Record<string, unknown> = { id: 'k1' };
|
|
47
|
+
answer['self'] = answer;
|
|
48
|
+
expect(await w.once(answer)).toEqual({ value: answer, replayed: false });
|
|
49
|
+
const stored = await subject.store.get(w.key);
|
|
50
|
+
expect(stored).toMatchObject({ status: 'settled', value: { id: 'k1', self: '[redacted]' } });
|
|
51
|
+
expect(codeOf(await w.once(null).catch((e: unknown) => e))).toBe(
|
|
52
|
+
'X_IDEMPOTENT_REPLAY_REDACTED',
|
|
53
|
+
);
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: 'an answer with no secret replays exactly as it was given',
|
|
58
|
+
async run(subject) {
|
|
59
|
+
const w = await world(subject);
|
|
60
|
+
const answer = { charged: 'ch_1', amount: { minor: 1250, currency: 'EUR' }, tags: ['a'] };
|
|
61
|
+
await w.once(answer);
|
|
62
|
+
expect((await subject.store.get(w.key))?.redacted).not.toBe(true);
|
|
63
|
+
expect(await w.once({ charged: 'never-run' })).toEqual({ value: answer, replayed: true });
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: 'inside a transaction the settle that commits with the write is redacted too',
|
|
68
|
+
async run(subject) {
|
|
69
|
+
const w = await world(subject);
|
|
70
|
+
await withTransaction(() => w.once({ token: 'tok_plaintext' }), { client: subject.client });
|
|
71
|
+
expect(await subject.store.get(w.key)).toMatchObject({
|
|
72
|
+
value: { token: '[redacted]' },
|
|
73
|
+
redacted: true,
|
|
74
|
+
});
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: 'a key reclaimed past the window forgets the redaction with the answer',
|
|
79
|
+
async run(subject) {
|
|
80
|
+
const w = await world(subject);
|
|
81
|
+
await w.once({ apiKey: 'sk_1' });
|
|
82
|
+
await w.age(
|
|
83
|
+
finiteCount(
|
|
84
|
+
'idempotencyStoreConformance',
|
|
85
|
+
'windowMs',
|
|
86
|
+
subject.store.windowMs ?? DAY_MS,
|
|
87
|
+
1,
|
|
88
|
+
) + 1_000,
|
|
89
|
+
);
|
|
90
|
+
expect(await w.once({ charged: 'ch_2' })).toEqual({
|
|
91
|
+
value: { charged: 'ch_2' },
|
|
92
|
+
replayed: false,
|
|
93
|
+
});
|
|
94
|
+
expect((await subject.store.get(w.key))?.redacted).not.toBe(true);
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
];
|
|
98
|
+
|
|
99
|
+
/** An answer no retry could replay is ONE verdict, the same on every store, and runs once. */
|
|
100
|
+
const UNSERIALISABLE: readonly TxCheck[] = [
|
|
101
|
+
...(
|
|
102
|
+
[
|
|
103
|
+
['a bigint', { n: 5n }],
|
|
104
|
+
['a NUL', { note: 'a\u0000b' }],
|
|
105
|
+
['a lone surrogate', { note: 'x\ud83d' }],
|
|
106
|
+
] as const
|
|
107
|
+
).map(
|
|
108
|
+
([label, answer]): TxCheck => ({
|
|
109
|
+
name: `${label}: refused first and on replay, failed at rest, and the handler ran once`,
|
|
110
|
+
async run(subject) {
|
|
111
|
+
const w = await world(subject);
|
|
112
|
+
let runs = 0;
|
|
113
|
+
const once = () =>
|
|
114
|
+
withIdempotency(subject.store, w.key, { id: 'same-payload' }, () => {
|
|
115
|
+
runs += 1;
|
|
116
|
+
return Promise.resolve(answer);
|
|
117
|
+
}).catch((error: unknown) => error);
|
|
118
|
+
expect(codeOf(await once())).toBe('X_IDEMPOTENCY_OUTPUT_UNSERIALIZABLE');
|
|
119
|
+
expect((await subject.store.get(w.key))?.status).toBe('failed');
|
|
120
|
+
const replay = await once();
|
|
121
|
+
expect(codeOf(replay)).toBe('X_IDEMPOTENCY_OUTPUT_UNSERIALIZABLE');
|
|
122
|
+
expect((replay as { meta?: { replayed?: unknown } }).meta?.replayed).toBe(true);
|
|
123
|
+
expect(runs).toBe(1);
|
|
124
|
+
},
|
|
125
|
+
}),
|
|
126
|
+
),
|
|
127
|
+
{
|
|
128
|
+
// JSON has no `undefined`: a store keeps `null`, and the action's `output` schema answers for it.
|
|
129
|
+
name: 'undefined settles, and the record holds no value',
|
|
130
|
+
async run(subject) {
|
|
131
|
+
const w = await world(subject);
|
|
132
|
+
expect((await w.once(undefined)).replayed).toBe(false);
|
|
133
|
+
const stored = await subject.store.get(w.key);
|
|
134
|
+
expect(stored?.status).toBe('settled');
|
|
135
|
+
expect(stored?.value ?? null).toBeNull();
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
];
|
|
139
|
+
|
|
140
|
+
export const IDEMPOTENCY_REPLAY_CHECKS: readonly TxCheck[] = [...REDACTION, ...UNSERIALISABLE];
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// The transactional half of `idempotencyStoreConformance`: a store that settles outside the
|
|
2
|
+
// handler's transaction replays a success for a write that rolled back, and one that lets a
|
|
3
|
+
// straggler settle a reclaimed key answers one request with another's value.
|
|
4
|
+
|
|
5
|
+
import { expect } from 'bun:test';
|
|
6
|
+
import { outsideTransaction, withTransaction } from '@ultimat3/db';
|
|
7
|
+
import type { IdempotencyWorldCheck as TxCheck } from './idempotency-store-world-conformance';
|
|
8
|
+
import { codeOf, late, world } from './idempotency-store-world-conformance';
|
|
9
|
+
|
|
10
|
+
export const IDEMPOTENCY_TX_CHECKS: readonly TxCheck[] = [
|
|
11
|
+
{
|
|
12
|
+
name: 'in a transaction: a commit settles with the write, and the retry replays it',
|
|
13
|
+
async run(subject) {
|
|
14
|
+
const w = await world(subject);
|
|
15
|
+
await w.charge('ch_1');
|
|
16
|
+
expect(await w.statusOf()).toBe('settled');
|
|
17
|
+
expect(await w.charge('ch_2')).toEqual({ value: { charged: 'ch_1' }, replayed: true });
|
|
18
|
+
expect(await w.charges()).toEqual(['ch_1']);
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: 'in a transaction: a rollback after the settle leaves the record in flight',
|
|
23
|
+
async run(subject) {
|
|
24
|
+
const w = await world(subject);
|
|
25
|
+
expect(
|
|
26
|
+
await w.charge('ch_1', { after: late }).catch((error: unknown) => error),
|
|
27
|
+
).toBeInstanceOf(RangeError);
|
|
28
|
+
expect(await w.charges()).toEqual([]);
|
|
29
|
+
// `settled` is the defect: the retry would replay a success for a write that rolled back.
|
|
30
|
+
expect(await w.statusOf()).toBe('in-flight');
|
|
31
|
+
expect(codeOf(await w.charge('ch_2').catch((error: unknown) => error))).toBe(
|
|
32
|
+
'X_IDEMPOTENCY_CONFLICT',
|
|
33
|
+
);
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: 'in a transaction: past the deadline the rolled-back key runs again, one write stored',
|
|
38
|
+
async run(subject) {
|
|
39
|
+
const w = await world(subject);
|
|
40
|
+
await w.charge('ch_1', { after: late }).catch(() => undefined);
|
|
41
|
+
await w.age(subject.reclaimAfterMs + 1_000);
|
|
42
|
+
expect(await w.charge('ch_2')).toEqual({ value: { charged: 'ch_2' }, replayed: false });
|
|
43
|
+
expect(await w.charges()).toEqual(['ch_2']);
|
|
44
|
+
expect(await w.statusOf()).toBe('settled');
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: 'in a transaction: a reservation never settled is freed by the deadline',
|
|
49
|
+
async run(subject) {
|
|
50
|
+
const w = await world(subject);
|
|
51
|
+
await withTransaction(
|
|
52
|
+
async () => {
|
|
53
|
+
expect((await subject.store.reserve(w.key, 'hash')).created).toBe(true);
|
|
54
|
+
},
|
|
55
|
+
{ client: subject.client },
|
|
56
|
+
);
|
|
57
|
+
await w.age(subject.reclaimAfterMs + 1_000);
|
|
58
|
+
expect((await subject.store.reserve(w.key, 'hash')).created).toBe(true);
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
name: 'in a transaction: a takeover before the settle refuses the slow attempt and undoes its write',
|
|
63
|
+
async run(subject) {
|
|
64
|
+
const w = await world(subject);
|
|
65
|
+
const slow = await w
|
|
66
|
+
.charge('slow', {
|
|
67
|
+
// Past the deadline with the record in flight: a retry, outside this transaction, takes it.
|
|
68
|
+
during: () =>
|
|
69
|
+
outsideTransaction(async () => {
|
|
70
|
+
await w.age(subject.reclaimAfterMs + 1_000);
|
|
71
|
+
expect((await subject.store.reserve(w.key, 'hash')).created).toBe(true);
|
|
72
|
+
}),
|
|
73
|
+
})
|
|
74
|
+
.catch((error: unknown) => error);
|
|
75
|
+
expect(codeOf(slow)).toBe('X_IDEMPOTENCY_RESERVATION_LOST');
|
|
76
|
+
expect(await w.charges()).toEqual([]);
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
name: 'in a transaction: a settle waiting on its commit is nobody’s to reclaim',
|
|
81
|
+
async run(subject) {
|
|
82
|
+
const w = await world(subject);
|
|
83
|
+
let retry: Promise<{ created: boolean }> | undefined;
|
|
84
|
+
await w.charge('ch_1', {
|
|
85
|
+
// Old before the settle: a row store's settle holds the row's lock until the commit.
|
|
86
|
+
during: () => outsideTransaction(() => w.age(subject.reclaimAfterMs + 1_000)),
|
|
87
|
+
// After the settle ran, before the commit. Not awaited: a row store blocks it on the lock.
|
|
88
|
+
after: async () => {
|
|
89
|
+
retry = outsideTransaction(() => subject.store.reserve(w.key, 'hash'));
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
expect((await retry)?.created).toBe(false);
|
|
93
|
+
expect(await w.statusOf()).toBe('settled');
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
...(['commit', 'rollback'] as const).map(
|
|
97
|
+
(ending): TxCheck => ({
|
|
98
|
+
name: `a straggler that outlives a ${ending} settles at once — its transaction is over`,
|
|
99
|
+
async run(subject) {
|
|
100
|
+
const w = await world(subject);
|
|
101
|
+
const gate = Promise.withResolvers<void>();
|
|
102
|
+
let straggler: Promise<unknown> = Promise.resolve();
|
|
103
|
+
await withTransaction(
|
|
104
|
+
() => {
|
|
105
|
+
straggler = gate.promise.then(async () => {
|
|
106
|
+
const { record } = await subject.store.reserve(w.key, 'hash');
|
|
107
|
+
await subject.store.settle(w.key, { late: true }, record.id, false);
|
|
108
|
+
});
|
|
109
|
+
return ending === 'commit' ? Promise.resolve() : late();
|
|
110
|
+
},
|
|
111
|
+
{ client: subject.client },
|
|
112
|
+
).catch(() => undefined);
|
|
113
|
+
gate.resolve();
|
|
114
|
+
await straggler;
|
|
115
|
+
expect(await w.statusOf()).toBe('settled');
|
|
116
|
+
},
|
|
117
|
+
}),
|
|
118
|
+
),
|
|
119
|
+
{
|
|
120
|
+
name: 'autocommit: the settle is immediate and a retry replays',
|
|
121
|
+
async run(subject) {
|
|
122
|
+
const w = await world(subject);
|
|
123
|
+
await w.chargeAutocommit('ch_1');
|
|
124
|
+
expect(await w.statusOf()).toBe('settled');
|
|
125
|
+
expect(await w.chargeAutocommit('ch_2')).toEqual({
|
|
126
|
+
value: { charged: 'ch_1' },
|
|
127
|
+
replayed: true,
|
|
128
|
+
});
|
|
129
|
+
expect(await w.charges()).toEqual(['ch_1']);
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
];
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// The world `idempotencyStoreConformance`'s transactional checks run in: one key behind
|
|
2
|
+
// `withIdempotency`, a handler writing one row of the caller's own table inside a real transaction
|
|
3
|
+
// on the subject's database. Not a suite — `idempotency-store-tx-conformance.ts` and
|
|
4
|
+
// `idempotency-store-replay-conformance.ts` drive it.
|
|
5
|
+
|
|
6
|
+
import { withIdempotency } from '@ultimat3/action';
|
|
7
|
+
import type { IdempotencyStore } from '@ultimat3/action/adapter';
|
|
8
|
+
import type { DbClient } from '@ultimat3/db';
|
|
9
|
+
import { raw, sql, withTransaction } from '@ultimat3/db';
|
|
10
|
+
|
|
11
|
+
/** `IdempotencyStoreSubject`, as the checks need it — restated to keep the imports one-way. */
|
|
12
|
+
export interface IdempotencyWorldSubject {
|
|
13
|
+
readonly store: IdempotencyStore;
|
|
14
|
+
readonly client: DbClient;
|
|
15
|
+
readonly reclaimAfterMs: number;
|
|
16
|
+
age(key: string, ms: number): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface IdempotencyWorldCheck {
|
|
20
|
+
readonly name: string;
|
|
21
|
+
run(subject: IdempotencyWorldSubject): Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** The caller's own table: the write the settle must commit with, or not at all. */
|
|
25
|
+
const CHARGES = 'x_conformance_charges';
|
|
26
|
+
export const DAY_MS = 24 * 60 * 60 * 1000;
|
|
27
|
+
|
|
28
|
+
let minted = 0;
|
|
29
|
+
const keyOf = (): string => {
|
|
30
|
+
minted += 1;
|
|
31
|
+
return `["conformance-tx","${process.pid.toString(36)}",${minted}]`;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** The outer unit of work failing after the gate returned — the settle already ran. */
|
|
35
|
+
export const late = (): Promise<void> =>
|
|
36
|
+
Promise.reject(new RangeError('the unit of work failed late'));
|
|
37
|
+
export const codeOf = (error: unknown): unknown =>
|
|
38
|
+
typeof error === 'object' && error !== null ? (error as { code?: unknown }).code : undefined;
|
|
39
|
+
|
|
40
|
+
interface Hooks {
|
|
41
|
+
readonly during?: () => Promise<void>;
|
|
42
|
+
readonly after?: () => Promise<void>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** One key's world: a charge behind the gate, with or without a transaction around it. */
|
|
46
|
+
export async function world(subject: IdempotencyWorldSubject) {
|
|
47
|
+
const { client, store } = subject;
|
|
48
|
+
await client.execute(raw(`create table if not exists ${CHARGES} (key text, id text)`));
|
|
49
|
+
const key = keyOf();
|
|
50
|
+
const run = (id: string, during?: () => Promise<void>) =>
|
|
51
|
+
withIdempotency(store, key, { id: 'same-payload' }, async () => {
|
|
52
|
+
await withTransaction(
|
|
53
|
+
(tx) => tx.execute(sql`insert into x_conformance_charges (key, id) values (${key}, ${id})`),
|
|
54
|
+
{ client },
|
|
55
|
+
);
|
|
56
|
+
await during?.();
|
|
57
|
+
return { charged: id };
|
|
58
|
+
});
|
|
59
|
+
return {
|
|
60
|
+
key,
|
|
61
|
+
charge: (id: string, hooks: Hooks = {}) =>
|
|
62
|
+
withTransaction(
|
|
63
|
+
async () => {
|
|
64
|
+
const outcome = await run(id, hooks.during);
|
|
65
|
+
await hooks.after?.();
|
|
66
|
+
return outcome;
|
|
67
|
+
},
|
|
68
|
+
{ client },
|
|
69
|
+
),
|
|
70
|
+
chargeAutocommit: (id: string) => run(id),
|
|
71
|
+
charges: async () =>
|
|
72
|
+
(
|
|
73
|
+
await client.query<{ id: string }>(
|
|
74
|
+
sql`select id from x_conformance_charges where key = ${key} order by id`,
|
|
75
|
+
)
|
|
76
|
+
).map((row) => row.id),
|
|
77
|
+
statusOf: async () => (await store.get(key))?.status,
|
|
78
|
+
age: (ms: number) => subject.age(key, ms),
|
|
79
|
+
once: (value: unknown) =>
|
|
80
|
+
withIdempotency(store, key, { id: 'same-payload' }, () => Promise.resolve(value)),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// The `IdentityProvider` contract of `@ultimat3/auth` as shared examples:
|
|
2
|
+
// `behavesLike(identityProviderConformance, () => harness)`. The harness plays the IdP (answers a
|
|
3
|
+
// redirect, tampers with an answer); every adapter must issue a fresh state per begin, prove one
|
|
4
|
+
// profile from an honest answer, and refuse a replayed, tampered or cross-wired one with a code.
|
|
5
|
+
|
|
6
|
+
import { expect, test } from 'bun:test';
|
|
7
|
+
import type { IdentityProvider, IdentityRedirect, VerifiedIdentity } from '@ultimat3/auth';
|
|
8
|
+
import { memoryTotpReplayGuard, type TotpReplayGuard } from '@ultimat3/auth';
|
|
9
|
+
import { type Clock, isUltimateError } from '@ultimat3/core';
|
|
10
|
+
import type { SharedExamples } from './shared-examples';
|
|
11
|
+
import { sharedExamples } from './shared-examples';
|
|
12
|
+
|
|
13
|
+
export interface IdentityProviderHarness {
|
|
14
|
+
readonly provider: IdentityProvider;
|
|
15
|
+
/** The URL `begin` and `complete` are given: what the IdP is registered to answer. */
|
|
16
|
+
readonly callbackUrl: string;
|
|
17
|
+
readonly clock: Clock;
|
|
18
|
+
/** Play the IdP: the callback params a consenting user's browser would bring back. */
|
|
19
|
+
answer(redirect: IdentityRedirect): Promise<Readonly<Record<string, string>>>;
|
|
20
|
+
/** The same answer with its proof altered — a changed signed value, a forged state. */
|
|
21
|
+
tamper(params: Readonly<Record<string, string>>): Readonly<Record<string, string>>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface IdentityProviderCheck {
|
|
25
|
+
readonly name: string;
|
|
26
|
+
run(harness: IdentityProviderHarness): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const complete = (
|
|
30
|
+
harness: IdentityProviderHarness,
|
|
31
|
+
state: string,
|
|
32
|
+
params: Readonly<Record<string, string>>,
|
|
33
|
+
replay: TotpReplayGuard,
|
|
34
|
+
): Promise<VerifiedIdentity> =>
|
|
35
|
+
harness.provider.complete({
|
|
36
|
+
state,
|
|
37
|
+
params,
|
|
38
|
+
callbackUrl: harness.callbackUrl,
|
|
39
|
+
clock: harness.clock,
|
|
40
|
+
replay,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
/** A refusal must be coded: an `X_*` an operator can look up, never a bare throw. */
|
|
44
|
+
async function expectCodedRefusal(call: Promise<unknown>): Promise<void> {
|
|
45
|
+
const outcome = await call.then(
|
|
46
|
+
() => 'accepted',
|
|
47
|
+
(error: unknown) =>
|
|
48
|
+
isUltimateError(error) && /^X_[A-Z0-9_]+$/.test(error.code) ? 'coded' : 'uncoded',
|
|
49
|
+
);
|
|
50
|
+
expect(outcome).toBe('coded');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const begin = (harness: IdentityProviderHarness): Promise<IdentityRedirect> =>
|
|
54
|
+
harness.provider.begin({ callbackUrl: harness.callbackUrl, clock: harness.clock });
|
|
55
|
+
|
|
56
|
+
export const IDENTITY_PROVIDER_CHECKS: readonly IdentityProviderCheck[] = [
|
|
57
|
+
{
|
|
58
|
+
name: 'declares a cookie-safe id and a callback method matching its protocol',
|
|
59
|
+
async run({ provider }) {
|
|
60
|
+
expect(provider.id).toMatch(/^[A-Za-z0-9_-]+$/);
|
|
61
|
+
expect(provider.callbackMethod).toBe(provider.protocol === 'saml' ? 'POST' : 'GET');
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: 'begin redirects to an absolute URL with a fresh state every time',
|
|
66
|
+
async run(harness) {
|
|
67
|
+
const [a, b] = [await begin(harness), await begin(harness)];
|
|
68
|
+
expect(URL.canParse(a.location)).toBe(true);
|
|
69
|
+
expect(a.state).not.toBe('');
|
|
70
|
+
expect(a.state).not.toBe(b.state);
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: 'an honest answer completes to one profile under the provider id',
|
|
75
|
+
async run(harness) {
|
|
76
|
+
const redirect = await begin(harness);
|
|
77
|
+
const identity = await complete(
|
|
78
|
+
harness,
|
|
79
|
+
redirect.state,
|
|
80
|
+
await harness.answer(redirect),
|
|
81
|
+
memoryTotpReplayGuard(),
|
|
82
|
+
);
|
|
83
|
+
expect(identity.profile.provider).toBe(harness.provider.id);
|
|
84
|
+
expect(identity.profile.providerAccountId).not.toBe('');
|
|
85
|
+
expect(identity.profile.emailVerified && identity.profile.email === null).toBe(false);
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
name: 'the same answer completes once; the second is a coded refusal',
|
|
90
|
+
async run(harness) {
|
|
91
|
+
const replay = memoryTotpReplayGuard();
|
|
92
|
+
const redirect = await begin(harness);
|
|
93
|
+
const params = await harness.answer(redirect);
|
|
94
|
+
await complete(harness, redirect.state, params, replay);
|
|
95
|
+
await expectCodedRefusal(complete(harness, redirect.state, params, replay));
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
name: 'a tampered answer is a coded refusal',
|
|
100
|
+
async run(harness) {
|
|
101
|
+
const redirect = await begin(harness);
|
|
102
|
+
const params = harness.tamper(await harness.answer(redirect));
|
|
103
|
+
await expectCodedRefusal(complete(harness, redirect.state, params, memoryTotpReplayGuard()));
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
name: "an answer to one begin, completed with another begin's state, is a coded refusal",
|
|
108
|
+
async run(harness) {
|
|
109
|
+
const [first, second] = [await begin(harness), await begin(harness)];
|
|
110
|
+
const params = await harness.answer(first);
|
|
111
|
+
await expectCodedRefusal(complete(harness, second.state, params, memoryTotpReplayGuard()));
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
name: 'answers() binds an answer to the state it was begun with, and to no other',
|
|
116
|
+
async run(harness) {
|
|
117
|
+
const [first, second] = [await begin(harness), await begin(harness)];
|
|
118
|
+
const params = await harness.answer(first);
|
|
119
|
+
expect(harness.provider.answers(first.state, params)).toBe(true);
|
|
120
|
+
expect(harness.provider.answers(second.state, params)).toBe(false);
|
|
121
|
+
expect(harness.provider.answers('{"forged":true}', params)).toBe(false);
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
name: 'a state the provider never issued is a coded refusal',
|
|
126
|
+
async run(harness) {
|
|
127
|
+
const redirect = await begin(harness);
|
|
128
|
+
const params = await harness.answer(redirect);
|
|
129
|
+
await expectCodedRefusal(
|
|
130
|
+
complete(harness, '{"forged":true}', params, memoryTotpReplayGuard()),
|
|
131
|
+
);
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
];
|
|
135
|
+
|
|
136
|
+
export const identityProviderConformance: SharedExamples<
|
|
137
|
+
IdentityProviderHarness | Promise<IdentityProviderHarness>
|
|
138
|
+
> = sharedExamples('an identity provider', (subject) => {
|
|
139
|
+
for (const check of IDENTITY_PROVIDER_CHECKS) {
|
|
140
|
+
test(check.name, async () => {
|
|
141
|
+
await check.run(await subject());
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
});
|