@udibo/oauth2 0.32.1 → 0.33.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/dist/adapters/hono/bff/session-store.d.ts +2 -1
- package/dist/adapters/hono/bff/testing.d.ts +22 -7
- package/dist/adapters/hono/bff/testing.js +16 -10
- package/dist/testing/contract/token-rotation.d.ts +7 -0
- package/dist/testing/contract/token-rotation.js +3 -2
- package/dist/testing/contract/token.d.ts +19 -0
- package/dist/testing/contract/token.js +72 -41
- package/package.json +1 -1
|
@@ -109,7 +109,8 @@ export interface RefreshLockStore {
|
|
|
109
109
|
* longer overwrite or end the session that instance refreshed. A store
|
|
110
110
|
* that calls `refresh()` with no lease still works, but a lock that
|
|
111
111
|
* expires mid-refresh then lets the former holder's write or sign-out
|
|
112
|
-
* land on top of the new holder's.
|
|
112
|
+
* land on top of the new holder's. `runSessionStoreContractTests` fails
|
|
113
|
+
* such a store unless its options declare that the lock never expires.
|
|
113
114
|
* - Reject when the lock cannot be acquired within a bound you choose.
|
|
114
115
|
* `HonoBff` then answers `502` `temporarily_unavailable` and keeps the
|
|
115
116
|
* session.
|
|
@@ -165,6 +165,20 @@ export interface SessionStoreContractOptions {
|
|
|
165
165
|
* supplying this factory.
|
|
166
166
|
*/
|
|
167
167
|
makeBoundedStore?(maxAgeMs: number): Promise<SessionStore> | SessionStore;
|
|
168
|
+
/**
|
|
169
|
+
* Set to `true` when the store's refresh lock never expires, so a holder
|
|
170
|
+
* keeps it until its `refresh` settles, as `MemorySessionStore` does by
|
|
171
|
+
* default. The suite then skips the lease checks for a store whose
|
|
172
|
+
* `withRefreshLock` passes no {@link RefreshLease}, instead of failing it.
|
|
173
|
+
*
|
|
174
|
+
* Without a lease, nothing stops a holder that lost an expiring lock from
|
|
175
|
+
* writing or destroying the session, and the suite cannot tell a lock that
|
|
176
|
+
* never expires from one that does. Declare it only when no holder can lose
|
|
177
|
+
* the lock while its refresh runs, as when the lock lives in the one process
|
|
178
|
+
* that runs every refresh. Then a holder that hangs holds the session's
|
|
179
|
+
* refresh until it settles. Defaults to `false`.
|
|
180
|
+
*/
|
|
181
|
+
refreshLockNeverExpires?: boolean;
|
|
168
182
|
}
|
|
169
183
|
/**
|
|
170
184
|
* Contract test suite for {@link SessionStore} implementations. Registers
|
|
@@ -175,12 +189,13 @@ export interface SessionStoreContractOptions {
|
|
|
175
189
|
*
|
|
176
190
|
* A store that implements `withRefreshLock` ({@link RefreshLockStore}) also
|
|
177
191
|
* runs the lock checks; they are skipped for a store without it. The lease
|
|
178
|
-
* checks ({@link RefreshLease})
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
192
|
+
* checks ({@link RefreshLease}) fail a store whose `withRefreshLock` passes no
|
|
193
|
+
* lease, unless the options declare that its lock never expires
|
|
194
|
+
* ({@linkcode SessionStoreContractOptions.refreshLockNeverExpires}). They
|
|
195
|
+
* prove that a lease stops acting once its call releases the lock or another
|
|
196
|
+
* call holds it, not that it stops when the lock expires: expire a lease in a
|
|
197
|
+
* test of your own for that. They use one store object, so they prove the
|
|
198
|
+
* lock's behavior, not that separate instances share it: point two store
|
|
199
|
+
* objects at one backend in a test of your own for that.
|
|
185
200
|
*/
|
|
186
201
|
export declare function runSessionStoreContractTests(options: SessionStoreContractOptions): void;
|
|
@@ -204,17 +204,19 @@ async function rejection(promise) {
|
|
|
204
204
|
*
|
|
205
205
|
* A store that implements `withRefreshLock` ({@link RefreshLockStore}) also
|
|
206
206
|
* runs the lock checks; they are skipped for a store without it. The lease
|
|
207
|
-
* checks ({@link RefreshLease})
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
207
|
+
* checks ({@link RefreshLease}) fail a store whose `withRefreshLock` passes no
|
|
208
|
+
* lease, unless the options declare that its lock never expires
|
|
209
|
+
* ({@linkcode SessionStoreContractOptions.refreshLockNeverExpires}). They
|
|
210
|
+
* prove that a lease stops acting once its call releases the lock or another
|
|
211
|
+
* call holds it, not that it stops when the lock expires: expire a lease in a
|
|
212
|
+
* test of your own for that. They use one store object, so they prove the
|
|
213
|
+
* lock's behavior, not that separate instances share it: point two store
|
|
214
|
+
* objects at one backend in a test of your own for that.
|
|
214
215
|
*/
|
|
215
216
|
export function runSessionStoreContractTests(options) {
|
|
216
217
|
const destroyClearsRead = options.destroyClearsRead ?? true;
|
|
217
218
|
const makeBoundedStore = options.makeBoundedStore;
|
|
219
|
+
const refreshLockNeverExpires = options.refreshLockNeverExpires ?? false;
|
|
218
220
|
describe(options.describeName ?? "SessionStore contract", () => {
|
|
219
221
|
let store;
|
|
220
222
|
beforeEach(async () => {
|
|
@@ -375,9 +377,13 @@ export function runSessionStoreContractTests(options) {
|
|
|
375
377
|
});
|
|
376
378
|
async function leaseOf(locking, value, skip) {
|
|
377
379
|
const lease = await locking.withRefreshLock(value, (given) => Promise.resolve(given));
|
|
378
|
-
skip(lease === undefined, "withRefreshLock passes the refresh no lease,
|
|
379
|
-
"
|
|
380
|
-
|
|
380
|
+
skip(lease === undefined && refreshLockNeverExpires, "withRefreshLock passes the refresh no lease, and the store declares " +
|
|
381
|
+
"that its lock never expires");
|
|
382
|
+
assert(lease !== undefined, "withRefreshLock passed the refresh no lease, so a holder that " +
|
|
383
|
+
"stalls past an expiring lock can still write and destroy the " +
|
|
384
|
+
"session another holder refreshed. Pass a RefreshLease, or set " +
|
|
385
|
+
"refreshLockNeverExpires: true if the lock never expires.");
|
|
386
|
+
return lease;
|
|
381
387
|
}
|
|
382
388
|
function refreshedSession() {
|
|
383
389
|
return {
|
|
@@ -82,6 +82,13 @@ export interface TokenRotationContractOptions<C extends ClientInterface, U exten
|
|
|
82
82
|
* longer to reach the lock they wait on.
|
|
83
83
|
*/
|
|
84
84
|
blockedAfterMs?: number;
|
|
85
|
+
/**
|
|
86
|
+
* Returns a new rotation-family id the store accepts as a
|
|
87
|
+
* {@linkcode RefreshToken.familyId}, distinct on every call. Each case calls
|
|
88
|
+
* it for the two families it uses. Set it when the store keeps family ids in
|
|
89
|
+
* a format other than a UUID. Defaults to `crypto.randomUUID()`.
|
|
90
|
+
*/
|
|
91
|
+
makeFamilyId?(): string;
|
|
85
92
|
/** Overrides the name passed to the outer `describe` block. */
|
|
86
93
|
describeName?: string;
|
|
87
94
|
}
|
|
@@ -55,6 +55,7 @@ export function runTokenRotationContractTests(options) {
|
|
|
55
55
|
const makeClient = options.makeClient ?? defaultMakeClient;
|
|
56
56
|
const pausable = options.rotateAwaitsBarrier ?? true;
|
|
57
57
|
const blockedAfterMs = options.blockedAfterMs ?? 100;
|
|
58
|
+
const makeFamilyId = options.makeFamilyId ?? (() => crypto.randomUUID());
|
|
58
59
|
describe(options.describeName ?? "TokenServiceInterface.rotate contract", () => {
|
|
59
60
|
let clientService;
|
|
60
61
|
let tokenService;
|
|
@@ -75,8 +76,8 @@ export function runTokenRotationContractTests(options) {
|
|
|
75
76
|
};
|
|
76
77
|
beforeEach(async () => {
|
|
77
78
|
armed = undefined;
|
|
78
|
-
family =
|
|
79
|
-
otherFamily =
|
|
79
|
+
family = makeFamilyId();
|
|
80
|
+
otherFamily = makeFamilyId();
|
|
80
81
|
const services = await options.makeServices(barriers);
|
|
81
82
|
clientService = services.clientService;
|
|
82
83
|
tokenService = services.tokenService;
|
|
@@ -46,6 +46,25 @@ export interface TokenServiceContractOptions<C extends ClientInterface, U extend
|
|
|
46
46
|
makeClient?(seq: number): C;
|
|
47
47
|
/** Builds a scope from its string value. Defaults to a {@linkcode BasicScope}. */
|
|
48
48
|
makeScope?(value: string): S;
|
|
49
|
+
/**
|
|
50
|
+
* A scope value the service accepts for the fixture client. The
|
|
51
|
+
* `acceptedScope` case with a user requests it and expects it back
|
|
52
|
+
* unchanged; the case with no user requests it and expects it not to be
|
|
53
|
+
* refused. Set it when `acceptedScope` refuses scopes outside a fixed
|
|
54
|
+
* vocabulary, for example `"openid"`. Defaults to `"read"`.
|
|
55
|
+
*/
|
|
56
|
+
supportedScope?: string;
|
|
57
|
+
/**
|
|
58
|
+
* Returns a new rotation-family id the store accepts as a
|
|
59
|
+
* {@linkcode RefreshToken.familyId}, distinct on every call. The family cases
|
|
60
|
+
* call it for each family they create and for a family that was never
|
|
61
|
+
* issued, so each case sees only its own families. Users, clients and the
|
|
62
|
+
* authorization-code and unknown-token probes keep fixed values, so a store
|
|
63
|
+
* that keeps state across cases still needs `makeServices` to isolate those.
|
|
64
|
+
* Set it when the store keeps family ids in a format other than a UUID.
|
|
65
|
+
* Defaults to `crypto.randomUUID()`.
|
|
66
|
+
*/
|
|
67
|
+
makeFamilyId?(): string;
|
|
49
68
|
/**
|
|
50
69
|
* Set to `false` when the service deliberately omits the optional
|
|
51
70
|
* reuse-detection pair, {@linkcode TokenServiceInterface.getRevokedRefreshToken}
|
|
@@ -26,11 +26,14 @@ const defaultMakeClient = (seq) => ({
|
|
|
26
26
|
grants: ["authorization_code", "refresh_token"],
|
|
27
27
|
});
|
|
28
28
|
const defaultMakeScope = (value) => new BasicScope(value);
|
|
29
|
+
const defaultMakeFamilyId = () => crypto.randomUUID();
|
|
29
30
|
/** Runs the {@link TokenServiceInterface} contract suite. */
|
|
30
31
|
export function runTokenServiceContractTests(options) {
|
|
31
32
|
const makeUser = options.makeUser ?? defaultMakeUser;
|
|
32
33
|
const makeClient = options.makeClient ?? defaultMakeClient;
|
|
33
34
|
const makeScope = options.makeScope ?? defaultMakeScope;
|
|
35
|
+
const supportedScope = options.supportedScope ?? "read";
|
|
36
|
+
const makeFamilyId = options.makeFamilyId ?? defaultMakeFamilyId;
|
|
34
37
|
const expectReuseDetection = options.refreshTokenReuseDetection ?? true;
|
|
35
38
|
describe(options.describeName ?? "TokenServiceInterface contract", () => {
|
|
36
39
|
let userService;
|
|
@@ -66,9 +69,9 @@ export function runTokenServiceContractTests(options) {
|
|
|
66
69
|
});
|
|
67
70
|
describe("acceptedScope", () => {
|
|
68
71
|
it("returns the requested scope unchanged for the simple case", async () => {
|
|
69
|
-
const requested = makeScope(
|
|
72
|
+
const requested = makeScope(supportedScope);
|
|
70
73
|
const result = await tokenService.acceptedScope(client, user, requested);
|
|
71
|
-
expect(result?.toString()).toStrictEqual(
|
|
74
|
+
expect(result?.toString()).toStrictEqual(supportedScope);
|
|
72
75
|
});
|
|
73
76
|
});
|
|
74
77
|
describe("save + getToken", () => {
|
|
@@ -97,7 +100,7 @@ export function runTokenServiceContractTests(options) {
|
|
|
97
100
|
expect(typeof accessToken).toStrictEqual("string");
|
|
98
101
|
});
|
|
99
102
|
it("accepts scope for a client with no user", async () => {
|
|
100
|
-
const result = await tokenService.acceptedScope(client, undefined, makeScope(
|
|
103
|
+
const result = await tokenService.acceptedScope(client, undefined, makeScope(supportedScope));
|
|
101
104
|
assert(result !== false, "scope must not be rejected for lack of a user");
|
|
102
105
|
});
|
|
103
106
|
it("dates the expiry of an access token with no user", async () => {
|
|
@@ -214,8 +217,12 @@ export function runTokenServiceContractTests(options) {
|
|
|
214
217
|
});
|
|
215
218
|
if (expectReuseDetection) {
|
|
216
219
|
describe("refresh-token rotation family", () => {
|
|
217
|
-
|
|
218
|
-
|
|
220
|
+
let family;
|
|
221
|
+
let otherFamily;
|
|
222
|
+
beforeEach(() => {
|
|
223
|
+
family = makeFamilyId();
|
|
224
|
+
otherFamily = makeFamilyId();
|
|
225
|
+
});
|
|
219
226
|
async function familyMember(familyId, refreshTokenExpiresAt = new Date(Date.now() + 600_000)) {
|
|
220
227
|
const accessToken = await tokenService.generateAccessToken(client, user);
|
|
221
228
|
const refreshToken = (await tokenService.generateRefreshToken(client, user));
|
|
@@ -244,16 +251,16 @@ export function runTokenServiceContractTests(options) {
|
|
|
244
251
|
"`refreshTokenReuseDetection: false` to record the gap.");
|
|
245
252
|
});
|
|
246
253
|
it("keeps a rotated-out refresh token findable, with its family", async () => {
|
|
247
|
-
const token = await saveFamilyMember(
|
|
254
|
+
const token = await saveFamilyMember(family);
|
|
248
255
|
await tokenService.revoke(token.refreshToken, "refresh_token");
|
|
249
256
|
expect(await tokenService.getRefreshToken(token.refreshToken), "a rotated-out token must no longer refresh").toBe(undefined);
|
|
250
257
|
const revoked = await tokenService.getRevokedRefreshToken(token.refreshToken);
|
|
251
258
|
assert(revoked !== undefined, "a revoked refresh token must stay findable — deleting the row " +
|
|
252
259
|
"is what turns a replay into an ordinary unknown token");
|
|
253
|
-
expect(revoked.familyId).toBe(
|
|
260
|
+
expect(revoked.familyId).toBe(family);
|
|
254
261
|
});
|
|
255
262
|
it("does not report a live refresh token as revoked", async () => {
|
|
256
|
-
const token = await saveFamilyMember(
|
|
263
|
+
const token = await saveFamilyMember(family);
|
|
257
264
|
expect(await tokenService.getRevokedRefreshToken(token.refreshToken), "reporting a live token as revoked turns every legitimate " +
|
|
258
265
|
"refresh into a detected replay").toBe(undefined);
|
|
259
266
|
});
|
|
@@ -261,28 +268,52 @@ export function runTokenServiceContractTests(options) {
|
|
|
261
268
|
expect(await tokenService.getRevokedRefreshToken("never-issued")).toBe(undefined);
|
|
262
269
|
});
|
|
263
270
|
it("revokes every live member of a replayed token's family", async () => {
|
|
264
|
-
const first = await saveFamilyMember(
|
|
265
|
-
const second = await saveFamilyMember(
|
|
266
|
-
expect(await tokenService.revokeFamily(
|
|
271
|
+
const first = await saveFamilyMember(family);
|
|
272
|
+
const second = await saveFamilyMember(family);
|
|
273
|
+
expect(await tokenService.revokeFamily(family)).toBe(true);
|
|
267
274
|
expect(await tokenService.getRefreshToken(first.refreshToken)).toBe(undefined);
|
|
268
275
|
expect(await tokenService.getRefreshToken(second.refreshToken)).toBe(undefined);
|
|
269
276
|
expect(await tokenService.getToken(second.accessToken), "the family's access tokens die with it — leaving them live " +
|
|
270
277
|
"keeps the thief's session alive for their remaining lifetime").toBe(undefined);
|
|
271
278
|
});
|
|
272
279
|
it("leaves other families untouched", async () => {
|
|
273
|
-
const mine = await saveFamilyMember(
|
|
274
|
-
const theirs = await saveFamilyMember(
|
|
275
|
-
await tokenService.revokeFamily(
|
|
280
|
+
const mine = await saveFamilyMember(family);
|
|
281
|
+
const theirs = await saveFamilyMember(otherFamily);
|
|
282
|
+
await tokenService.revokeFamily(family);
|
|
276
283
|
expect(await tokenService.getRefreshToken(mine.refreshToken)).toBe(undefined);
|
|
277
284
|
assert((await tokenService.getRefreshToken(theirs.refreshToken)) !==
|
|
278
285
|
undefined, "one compromised family must not sign every other session out");
|
|
279
286
|
});
|
|
280
287
|
it("returns false when the family has no live tokens", async () => {
|
|
281
|
-
expect(await tokenService.revokeFamily(
|
|
288
|
+
expect(await tokenService.revokeFamily(makeFamilyId())).toBe(false);
|
|
289
|
+
});
|
|
290
|
+
it("keeps a revoked family revoked: a successor saved after revokeFamily is not live", async ({ skip, }) => {
|
|
291
|
+
skip(typeof tokenService.rotate === "function", "the service implements rotate, so the refresh grant never saves " +
|
|
292
|
+
"a successor separately; runTokenRotationContractTests checks " +
|
|
293
|
+
"revokeFamily against rotate");
|
|
294
|
+
const parent = await saveFamilyMember(family);
|
|
295
|
+
const successor = await familyMember(family);
|
|
296
|
+
const claimed = tokenService.revokeRotated
|
|
297
|
+
? await tokenService.revokeRotated(parent)
|
|
298
|
+
: await tokenService.revoke(parent);
|
|
299
|
+
expect(claimed).toBe(true);
|
|
300
|
+
expect(await tokenService.getRefreshToken(parent.refreshToken), "the claim spends the presented refresh token").toBe(undefined);
|
|
301
|
+
await tokenService.revokeFamily(family);
|
|
302
|
+
await tokenService.save(successor);
|
|
303
|
+
expect(await tokenService.getRefreshToken(successor.refreshToken), "a successor saved after its family was revoked must be stored " +
|
|
304
|
+
"already revoked: the refresh grant claims a token and saves " +
|
|
305
|
+
"its successor in two calls, and a revokeFamily that lands " +
|
|
306
|
+
"between them otherwise leaves the successor live").toBe(undefined);
|
|
307
|
+
expect(await tokenService.getToken(successor.accessToken), "a successor saved after its family was revoked must be stored " +
|
|
308
|
+
"already revoked, its access token included").toBe(undefined);
|
|
309
|
+
if (tokenService.hasLiveRefreshToken) {
|
|
310
|
+
expect(await tokenService.hasLiveRefreshToken(family), "a successor saved after its family was revoked must be stored " +
|
|
311
|
+
"already revoked, so the family has no live member").toBe(false);
|
|
312
|
+
}
|
|
282
313
|
});
|
|
283
314
|
it("stamps a token revokeRotated revoked with its rotation time", async ({ skip, }) => {
|
|
284
315
|
skip(typeof tokenService.revokeRotated !== "function", "the service does not implement revokeRotated");
|
|
285
|
-
const token = await saveFamilyMember(
|
|
316
|
+
const token = await saveFamilyMember(family);
|
|
286
317
|
const before = Date.now();
|
|
287
318
|
expect(await tokenService.revokeRotated(token)).toBe(true);
|
|
288
319
|
const revoked = await tokenService.getRevokedRefreshToken(token.refreshToken);
|
|
@@ -294,17 +325,17 @@ export function runTokenServiceContractTests(options) {
|
|
|
294
325
|
});
|
|
295
326
|
it("rotates in one call: the parent is spent and stamped, the successor live", async ({ skip, }) => {
|
|
296
327
|
skip(typeof tokenService.rotate !== "function", "the service does not implement rotate");
|
|
297
|
-
const parent = await saveFamilyMember(
|
|
298
|
-
const next = await familyMember(
|
|
328
|
+
const parent = await saveFamilyMember(family);
|
|
329
|
+
const next = await familyMember(family);
|
|
299
330
|
const before = Date.now();
|
|
300
331
|
const rotated = await tokenService.rotate(parent, next);
|
|
301
332
|
expect(rotated?.refreshToken).toBe(next.refreshToken);
|
|
302
|
-
expect((await tokenService.getRefreshToken(next.refreshToken))?.familyId).toBe(
|
|
333
|
+
expect((await tokenService.getRefreshToken(next.refreshToken))?.familyId).toBe(family);
|
|
303
334
|
expect(await tokenService.getToken(next.accessToken)).not.toBe(undefined);
|
|
304
335
|
expect(await tokenService.getRefreshToken(parent.refreshToken)).toBe(undefined);
|
|
305
336
|
expect(await tokenService.getToken(parent.accessToken), "rotation ends the parent's access token, as revokeRotated does").toBe(undefined);
|
|
306
337
|
const tombstone = await tokenService.getRevokedRefreshToken(parent.refreshToken);
|
|
307
|
-
expect(tombstone?.familyId).toBe(
|
|
338
|
+
expect(tombstone?.familyId).toBe(family);
|
|
308
339
|
assert(tombstone?.rotatedAt instanceof Date &&
|
|
309
340
|
tombstone.rotatedAt.getTime() >= before - 1000 &&
|
|
310
341
|
tombstone.rotatedAt.getTime() <= Date.now() + 1000, "rotate must stamp rotatedAt as revokeRotated does, or the " +
|
|
@@ -313,11 +344,11 @@ export function runTokenServiceContractTests(options) {
|
|
|
313
344
|
});
|
|
314
345
|
it("refuses to rotate a refresh token that is no longer live, persisting nothing", async ({ skip, }) => {
|
|
315
346
|
skip(typeof tokenService.rotate !== "function", "the service does not implement rotate");
|
|
316
|
-
const parent = await saveFamilyMember(
|
|
317
|
-
const first = await familyMember(
|
|
318
|
-
const second = await familyMember(
|
|
319
|
-
const revokedParent = await saveFamilyMember(
|
|
320
|
-
const third = await familyMember(
|
|
347
|
+
const parent = await saveFamilyMember(family);
|
|
348
|
+
const first = await familyMember(family);
|
|
349
|
+
const second = await familyMember(family);
|
|
350
|
+
const revokedParent = await saveFamilyMember(family);
|
|
351
|
+
const third = await familyMember(family);
|
|
321
352
|
await tokenService.revoke(revokedParent.refreshToken, "refresh_token");
|
|
322
353
|
expect(await tokenService.rotate(parent, first)).not.toBe(undefined);
|
|
323
354
|
expect(await tokenService.rotate(parent, second), "a refresh token is claimed once").toBe(undefined);
|
|
@@ -330,12 +361,12 @@ export function runTokenServiceContractTests(options) {
|
|
|
330
361
|
});
|
|
331
362
|
it("finds a rotated-out token's family, so revoking it ends the live successor", async ({ skip, }) => {
|
|
332
363
|
skip(typeof tokenService.revokeRotated !== "function", "the service does not implement revokeRotated");
|
|
333
|
-
const rotatedOut = await saveFamilyMember(
|
|
364
|
+
const rotatedOut = await saveFamilyMember(family);
|
|
334
365
|
expect(await tokenService.revokeRotated(rotatedOut)).toBe(true);
|
|
335
|
-
const successor = await saveFamilyMember(
|
|
336
|
-
const unrelated = await saveFamilyMember(
|
|
366
|
+
const successor = await saveFamilyMember(family);
|
|
367
|
+
const unrelated = await saveFamilyMember(otherFamily);
|
|
337
368
|
const tombstone = await tokenService.getRevokedRefreshToken(rotatedOut.refreshToken);
|
|
338
|
-
assert(tombstone?.familyId ===
|
|
369
|
+
assert(tombstone?.familyId === family && tombstone.rotatedAt, "the revocation endpoint finds the family to end from the " +
|
|
339
370
|
"rotated-out token's record; without its familyId and " +
|
|
340
371
|
"rotatedAt, a sign-out racing a refresh leaves the successor live");
|
|
341
372
|
expect(tombstone.client.id.toString(), "the endpoint revokes the family only for the client the token " +
|
|
@@ -347,7 +378,7 @@ export function runTokenServiceContractTests(options) {
|
|
|
347
378
|
undefined);
|
|
348
379
|
});
|
|
349
380
|
it("leaves rotatedAt unset on a token revoked other than by rotation", async () => {
|
|
350
|
-
const token = await saveFamilyMember(
|
|
381
|
+
const token = await saveFamilyMember(family);
|
|
351
382
|
await tokenService.revoke(token.refreshToken, "refresh_token");
|
|
352
383
|
const revoked = await tokenService.getRevokedRefreshToken(token.refreshToken);
|
|
353
384
|
expect(revoked?.rotatedAt, "a revoked token that looks rotated gets the replay grace a " +
|
|
@@ -355,26 +386,26 @@ export function runTokenServiceContractTests(options) {
|
|
|
355
386
|
});
|
|
356
387
|
it("reports whether a family still has a live refresh token", async ({ skip, }) => {
|
|
357
388
|
skip(typeof tokenService.hasLiveRefreshToken !== "function", "the service does not implement hasLiveRefreshToken");
|
|
358
|
-
const token = await saveFamilyMember(
|
|
359
|
-
await saveFamilyMember(
|
|
360
|
-
expect(await tokenService.hasLiveRefreshToken(
|
|
389
|
+
const token = await saveFamilyMember(family);
|
|
390
|
+
await saveFamilyMember(otherFamily);
|
|
391
|
+
expect(await tokenService.hasLiveRefreshToken(family)).toBe(true);
|
|
361
392
|
await tokenService.revoke(token.refreshToken, "refresh_token");
|
|
362
|
-
expect(await tokenService.hasLiveRefreshToken(
|
|
363
|
-
expect(await tokenService.hasLiveRefreshToken(
|
|
364
|
-
expect(await tokenService.hasLiveRefreshToken(
|
|
393
|
+
expect(await tokenService.hasLiveRefreshToken(family), "a family whose last token was revoked has no successor to protect").toBe(false);
|
|
394
|
+
expect(await tokenService.hasLiveRefreshToken(otherFamily)).toBe(true);
|
|
395
|
+
expect(await tokenService.hasLiveRefreshToken(makeFamilyId())).toBe(false);
|
|
365
396
|
});
|
|
366
397
|
it("does not count an expired refresh token as live", async ({ skip, }) => {
|
|
367
398
|
skip(typeof tokenService.hasLiveRefreshToken !== "function", "the service does not implement hasLiveRefreshToken");
|
|
368
|
-
await saveFamilyMember(
|
|
369
|
-
expect(await tokenService.hasLiveRefreshToken(
|
|
399
|
+
await saveFamilyMember(family, new Date(Date.now() - 1000));
|
|
400
|
+
expect(await tokenService.hasLiveRefreshToken(family), "an expired successor cannot be used, so a replay of its " +
|
|
370
401
|
"predecessor must not be excused as a straggler").toBe(false);
|
|
371
402
|
});
|
|
372
403
|
async function rotateOut(skip) {
|
|
373
404
|
skip(typeof tokenService.isWithinReplayGrace !== "function", "the service does not implement isWithinReplayGrace");
|
|
374
405
|
skip(typeof tokenService.rotate !== "function" &&
|
|
375
406
|
typeof tokenService.revokeRotated !== "function", "the service implements neither rotate nor revokeRotated");
|
|
376
|
-
const parent = await saveFamilyMember(
|
|
377
|
-
const successor = await familyMember(
|
|
407
|
+
const parent = await saveFamilyMember(family);
|
|
408
|
+
const successor = await familyMember(family);
|
|
378
409
|
if (tokenService.rotate) {
|
|
379
410
|
assert(await tokenService.rotate(parent, successor));
|
|
380
411
|
}
|
|
@@ -383,7 +414,7 @@ export function runTokenServiceContractTests(options) {
|
|
|
383
414
|
await tokenService.save(successor);
|
|
384
415
|
}
|
|
385
416
|
const tombstone = await tokenService.getRevokedRefreshToken(parent.refreshToken);
|
|
386
|
-
assert(tombstone?.familyId ===
|
|
417
|
+
assert(tombstone?.familyId === family && tombstone.rotatedAt, "a store that judges the replay grace must still return every " +
|
|
387
418
|
"rotated-out tombstone, with its family and rotatedAt; hiding " +
|
|
388
419
|
"one inside the window hides the family from a sign-out " +
|
|
389
420
|
"racing the refresh, which then leaves the successor live");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@udibo/oauth2",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.33.0",
|
|
4
4
|
"description": "A flexible OAuth2 toolkit: framework-agnostic authorization & resource servers, a typed client, Hono adapters (including a backend-for-frontend), and React bindings.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"authorization-server",
|