Personal Telegram developer console for GitHub
test: require approval lifecycle audit events
davoodmehraban89 committed
Oct 3, 2026 at 06:14 UTC
21e6ab488e3d66be4e1295827e3b306baf8b2704
1 file changed
+54
test/approval-flow.test.js
+54
@@ -189,3 +189,57 @@ test('WRITE approval falls back to the configured Telegram webhook secret when n
189
mock.restore();
190
}
191
});
192
+
193
+test('approval lifecycle is audited without logging signed callback tokens', async () => {
194
+ const mock = installMock();
195
+ const originalLog = console.log;
196
+ const logs = [];
197
+ console.log = (...args) => logs.push(args.map(String).join(' '));
198
+
199
+ try {
200
+ const menuMessage = { message_id: 703, chat: { id: 123 } };
201
+ await sendUpdate({
202
+ callback_query: {
203
+ id: 'audit-issue',
204
+ from: { id: 123 },
205
+ data: 'rerun:1001:55',
206
+ message: menuMessage
207
+ }
208
+ });
209
+
210
+ const approvalEdit = mock.telegramCalls
211
+ .filter(call => call.method === 'editMessageText')
212
+ .at(-1);
213
+ const approveButton = approvalEdit.body.reply_markup.inline_keyboard
214
+ .flat()
215
+ .find(button => String(button.callback_data || '').startsWith('approve:'));
216
+ assert.ok(approveButton);
217
+
218
+ await sendUpdate({
219
+ callback_query: {
220
+ id: 'audit-verify',
221
+ from: { id: 123 },
222
+ data: approveButton.callback_data,
223
+ message: menuMessage
224
+ }
225
+ });
226
+
227
+ await sendUpdate({
228
+ callback_query: {
229
+ id: 'audit-reject',
230
+ from: { id: 123 },
231
+ data: approveButton.callback_data,
232
+ message: menuMessage
233
+ }
234
+ });
235
+
236
+ const auditText = logs.filter(line => line.startsWith('nexa_audit ')).join('\n');
237
+ assert.match(auditText, /"event":"approval_issued"/);
238
+ assert.match(auditText, /"event":"approval_verified"/);
239
+ assert.match(auditText, /"event":"approval_rejected"/);
240
+ assert.doesNotMatch(auditText, new RegExp(approveButton.callback_data.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')));
241
+ } finally {
242
+ console.log = originalLog;
243
+ mock.restore();
244
+ }
245
+});