companion-oauth-pkce-performance.test.mjs
62 lines 2.5 KB
Raw
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd feat(calendar): enforce agent context tiers in retrieval AP… Human minor ⚠ breaking 1 day ago
1 /**
2 * Tier 6 — PERFORMANCE: the protocol core is on the interactive sign-in / refresh path, so each
3 * operation must be cheap. These are coarse upper bounds chosen to catch a pathological regression
4 * (e.g. an accidental O(n^2) or a synchronous blocking call), not micro-benchmarks.
5 */
6 import { describe, it } from 'node:test';
7 import assert from 'node:assert/strict';
8 import {
9 createPkcePair,
10 computeCodeChallenge,
11 buildAuthorizationUrl,
12 validateAuthorizationResponse,
13 validateTokenResponse,
14 decideTokenRefresh,
15 } from '../lib/companion-oauth-pkce.mjs';
16
17 const AUTH_EP = 'https://knowtation.store/authorize';
18 const CLIENT_ID = 'companion-public-client';
19 const REDIRECT = 'http://127.0.0.1:49321/callback';
20 const SCOPES = ['vault:read', 'vault:write'];
21
22 function timed(fn) {
23 const t0 = performance.now();
24 fn();
25 return performance.now() - t0;
26 }
27
28 describe('Performance — bounds', () => {
29 it('10k PKCE pairs in well under 3s', () => {
30 const ms = timed(() => { for (let i = 0; i < 10_000; i++) createPkcePair(); });
31 assert.ok(ms < 3000, `createPkcePair x10k took ${ms.toFixed(0)}ms`);
32 });
33
34 it('100k computeCodeChallenge in well under 3s', () => {
35 const v = createPkcePair().codeVerifier;
36 const ms = timed(() => { for (let i = 0; i < 100_000; i++) computeCodeChallenge(v); });
37 assert.ok(ms < 3000, `computeCodeChallenge x100k took ${ms.toFixed(0)}ms`);
38 });
39
40 it('100k buildAuthorizationUrl in under 4s', () => {
41 const args = { authorizationEndpoint: AUTH_EP, clientId: CLIENT_ID, redirectUri: REDIRECT, scopes: SCOPES, state: 's', codeChallenge: 'c' };
42 const ms = timed(() => { for (let i = 0; i < 100_000; i++) buildAuthorizationUrl(args); });
43 assert.ok(ms < 4000, `buildAuthorizationUrl x100k took ${ms.toFixed(0)}ms`);
44 });
45
46 it('200k validateAuthorizationResponse in under 4s', () => {
47 const args = { params: { code: 'c', state: 's' }, expectedState: 's' };
48 const ms = timed(() => { for (let i = 0; i < 200_000; i++) validateAuthorizationResponse(args); });
49 assert.ok(ms < 4000, `validateAuthorizationResponse x200k took ${ms.toFixed(0)}ms`);
50 });
51
52 it('200k validateTokenResponse + decideTokenRefresh in under 3s', () => {
53 const json = { access_token: 'jwt', token_type: 'Bearer', expires_in: 3600, refresh_token: 'r' };
54 const ms = timed(() => {
55 for (let i = 0; i < 200_000; i++) {
56 validateTokenResponse(json);
57 decideTokenRefresh({ expiresAt: 5000, now: i % 6000, skewMs: 100 });
58 }
59 });
60 assert.ok(ms < 3000, `validate+decide x200k took ${ms.toFixed(0)}ms`);
61 });
62 });
File History 2 commits
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd feat(calendar): enforce agent context tiers in retrieval AP… Human minor 1 day ago
sha256:9103f98c89257ed2b01c237cea895dabb3e85ea337dccb1161c175e4422355b6 docs: accept Calendar Events v0 spec with Phase 0 security … Human 1 day ago