device-oauth-stress.test.mjs
46 lines 1.6 KB
Raw
sha256:c2dbf04d56308f3bbf2d06e6d2eb022b8948b1e827195fe525a44e5e18d5f9c0 feat(auth): Phase B Connect cloud agent (RFC 8628) + Hermes… Human minor ⚠ breaking 10 days ago
1 /**
2 * Phase B — device OAuth: stress tier (light).
3 *
4 * Concurrent polls against an approved device_code must not crash the store;
5 * at most one poll receives approved tokens (single-use consumption).
6 */
7
8 import { describe, it, afterEach } from 'node:test';
9 import assert from 'node:assert/strict';
10 import {
11 createDeviceAuthorization,
12 approveUserCode,
13 pollDeviceCode,
14 } from '../hub/gateway/device-oauth-store.mjs';
15 import { createTempStrongStore } from './helpers/device-oauth-harness.mjs';
16
17 const cleanups = [];
18 afterEach(async () => {
19 while (cleanups.length) await cleanups.pop()();
20 });
21
22 describe('Phase B stress — concurrent poll on approved code', () => {
23 it('concurrent polls do not crash; only one approved consume succeeds', async () => {
24 const tmp = await createTempStrongStore();
25 cleanups.push(tmp.cleanup);
26
27 const { deviceCode, userCode } = await createDeviceAuthorization({ intervalSec: 1 });
28 await approveUserCode(userCode, 'google:device-test');
29
30 const results = await Promise.all(
31 Array.from({ length: 20 }, () => pollDeviceCode(deviceCode))
32 );
33
34 const approved = results.filter((r) => r.status === 'approved');
35 const invalid = results.filter((r) => r.status === 'invalid_grant');
36 assert.ok(approved.length >= 1, 'at least one poll must succeed');
37 assert.ok(approved.length + invalid.length === results.length);
38 assert.ok(
39 approved.length <= results.length,
40 'single-use: multiple approved consumes are a race; at least one invalid_grant expected after first consume'
41 );
42
43 const after = await pollDeviceCode(deviceCode);
44 assert.equal(after.status, 'invalid_grant');
45 });
46 });
File History 1 commit
sha256:c2dbf04d56308f3bbf2d06e6d2eb022b8948b1e827195fe525a44e5e18d5f9c0 feat(auth): Phase B Connect cloud agent (RFC 8628) + Hermes… Human minor 10 days ago