Personal Telegram developer console for GitHub
test: provide durable replay store to approval consume contract
davoodmehraban89 committed
Oct 3, 2026 at 07:13 UTC
80509daa5e01c5f7ca4ba6d5ce4c1069abaada74
1 file changed
+30
-1
test/approval.test.js
+30
-1
@@ -3,6 +3,18 @@ import assert from 'node:assert/strict';
3
4
const approvalModule = await import('../src/core/approval.js').catch(() => null);
5
6
+function makeReplayStore() {
7
+ const used = new Set();
8
+ return {
9
+ async consume({ ownerId, nonce }) {
10
+ const key = `${ownerId}:${nonce}`;
11
+ if (used.has(key)) return false;
12
+ used.add(key);
13
+ return true;
14
+ }
15
+ };
16
+}
17
+
18
test('ApprovalService module exists', () => {
19
assert.ok(approvalModule, 'ApprovalService module must exist');
20
assert.equal(typeof approvalModule?.ApprovalService, 'function');
@@ -75,7 +87,8 @@ test('ApprovalService consume is one-time and rejects replay', async () => {
87
assert.ok(approvalModule?.ApprovalService, 'ApprovalService module must exist');
88
const service = new approvalModule.ApprovalService({
89
secret: 'test-signing-secret',
78
- now: () => 1_700_000_000_000
90
+ now: () => 1_700_000_000_000,
91
+ replayStore: makeReplayStore()
92
});
93
const token = await service.issue({
94
pluginId: 'github',
@@ -90,6 +103,22 @@ test('ApprovalService consume is one-time and rejects replay', async () => {
103
await assert.rejects(() => service.consume(token, { ownerId: '42' }), /already used/i);
104
});
105
106
+test('ApprovalService fails closed for missing replay protection on consume', async () => {
107
+ const service = new approvalModule.ApprovalService({
108
+ secret: 'test-signing-secret',
109
+ now: () => 1_700_000_000_000
110
+ });
111
+ const token = await service.issue({
112
+ pluginId: 'github',
113
+ actionId: 'github.workflow.run.cancel',
114
+ risk: 'WRITE',
115
+ ownerId: '42',
116
+ input: { repoId: 7, runId: 9 }
117
+ });
118
+
119
+ await assert.rejects(() => service.consume(token, { ownerId: '42' }), /replay protection is not configured/i);
120
+});
121
+
122
test('ApprovalService fails closed for missing secret and oversized callback token', async () => {
123
assert.ok(approvalModule?.ApprovalService, 'ApprovalService module must exist');
124
const missing = new approvalModule.ApprovalService({ secret: '' });