-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathlegacy-verify-alias-headers.test.ts
More file actions
93 lines (84 loc) · 3.38 KB
/
Copy pathlegacy-verify-alias-headers.test.ts
File metadata and controls
93 lines (84 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/**
* Legacy /verify alias: deprecation-header contract.
*
* The reference verifier keeps `POST /verify` runtime-reachable as a
* deprecated compatibility alias. Every response (success or error)
* MUST carry:
*
* - `Deprecation: true` (RFC 9745)
* - `Sunset: Sat, 01 Nov 2026 00:00:00 GMT` (RFC 8594)
* - `Link: <https://www.peacprotocol.org/docs/migration>; rel="deprecation"` (RFC 8288)
*
* The same is true for the `/api/v1/verify` alias. This test exercises
* the alias routes directly in a minimal Hono app that wires the alias
* handler the same way the real server does.
*/
import { describe, it, expect, beforeAll } from 'vitest';
import { Hono } from 'hono';
import {
createVerifyV1Handler,
resetVerifyV1RateLimit,
isProblemError,
PROBLEM_MEDIA_TYPE,
LEGACY_VERIFY_DEPRECATION_HEADERS,
createLegacyVerifyAliasHandler,
} from '../src/index.js';
function buildApp() {
resetVerifyV1RateLimit();
const app = new Hono();
app.onError((err, c) => {
if (isProblemError(err)) {
c.header('Content-Type', PROBLEM_MEDIA_TYPE);
return c.body(JSON.stringify(err.toProblemDetails()), err.status);
}
return c.json({ title: 'Internal Server Error', status: 500 }, 500);
});
const verifyV1 = createVerifyV1Handler();
const legacyVerifyAlias = createLegacyVerifyAliasHandler(verifyV1);
app.post('/v1/verify', verifyV1);
app.post('/verify', legacyVerifyAlias);
app.post('/api/v1/verify', legacyVerifyAlias);
return app;
}
function request(path: string, body: unknown) {
return new Request(`http://localhost${path}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body),
});
}
describe('legacy /verify alias: deprecation headers', () => {
let app: ReturnType<typeof buildApp>;
beforeAll(() => {
app = buildApp();
});
it('exposes the full deprecation header set as a named constant', () => {
expect(LEGACY_VERIFY_DEPRECATION_HEADERS.Deprecation).toBe('true');
expect(LEGACY_VERIFY_DEPRECATION_HEADERS.Sunset).toBe('Sat, 01 Nov 2026 00:00:00 GMT');
expect(LEGACY_VERIFY_DEPRECATION_HEADERS.Link).toBe(
'<https://www.peacprotocol.org/docs/migration>; rel="deprecation"'
);
});
it('stamps all three headers on a /verify error response', async () => {
const res = await app.request(request('/verify', { receipt: 'not-a-jws' }));
expect(res.headers.get('Deprecation')).toBe('true');
expect(res.headers.get('Sunset')).toBe('Sat, 01 Nov 2026 00:00:00 GMT');
expect(res.headers.get('Link')).toBe(
'<https://www.peacprotocol.org/docs/migration>; rel="deprecation"'
);
});
it('stamps all three headers on an /api/v1/verify error response', async () => {
const res = await app.request(request('/api/v1/verify', { receipt: 'not-a-jws' }));
expect(res.headers.get('Deprecation')).toBe('true');
expect(res.headers.get('Sunset')).toBe('Sat, 01 Nov 2026 00:00:00 GMT');
expect(res.headers.get('Link')).toBe(
'<https://www.peacprotocol.org/docs/migration>; rel="deprecation"'
);
});
it('canonical /v1/verify response does NOT carry deprecation headers', async () => {
const res = await app.request(request('/v1/verify', { receipt: 'not-a-jws' }));
expect(res.headers.get('Deprecation')).toBeNull();
expect(res.headers.get('Sunset')).toBeNull();
expect(res.headers.get('Link')).toBeNull();
});
});