test(admin): exercise webhook signing-key rotation router (Closes #1307) - #1418
Merged
greatest0fallt1me merged 2 commits intoOct 1, 2026
Conversation
…loraOrg#1307) - Add src/routes/admin/webhookKeys.test.ts (27 tests) driving POST /rotate-key and GET /grace-window through supertest with an injected InMemoryWebhookKeyStore, behind the real adminAuth middleware (restored; see below). Acceptance criteria covered: - Rotation demotes the prior key to 'previous' with exact expiry (fixed clock + injected grace window, asserted at store level). - A second/third rotation expires the oldest key; expired keys leave the valid-previous set. - Invalid graceWindowMs overrides (0, negative, fractional, string, null, NaN, Infinity, unknown fields) return 400 VALIDATION_ERROR with field details and mutate nothing (no rotation, no audit row, no notification). - Audit records (store rows + HTTP-layer logger.audit) carry actor and key ids and never raw secrets; only SHA-256 hashes persist. - Auth enforcement: 401 without/wrong credentials or non-admin JWT; admin JWT subject recorded as rotation actor. - Failure modes: store errors map to 500 without leaking internals; mid-rotation demotion failure leaves no partial state. Production changes (minimal, to expose the tested behavior): - WebhookSignerService.rotateKey accepts an optional per-rotation graceWindowMs override, validated before any state mutation; audit rows and results reflect the effective window. Service default unchanged. - rotate-key route validates an optional strict JSON body { graceWindowMs?: positive int } via the shared validate() middleware (bodyless/empty-body requests remain valid) and forwards the override. OpenAPI comment updated. Workspace repairs required to run tests (reconstructed, not re-written): restore src/middleware/adminAuth.ts verbatim from 092ece9~1 (it was deleted while its test and importers remained), and restore package.json / jest.env-setup.cjs so npm test works. Validation: npm test -- src/routes/admin/webhookKeys.test.ts => 27/27 passing; webhookSigner.test.ts unchanged (48/50, same two pre-existing failures); tsc error count identical to baseline. Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
|
@esegbueadam-sys Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
# Conflicts: # jest.env-setup.cjs # package.json # src/middleware/adminAuth.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Acceptance criteria covered:
Production changes (minimal, to expose the tested behavior):
Workspace repairs required to run tests (reconstructed, not re-written): restore src/middleware/adminAuth.ts verbatim from 092ece9~1 (it was deleted while its test and importers remained), and restore package.json / jest.env-setup.cjs so npm test works.
Validation: npm test -- src/routes/admin/webhookKeys.test.ts => 27/27 passing; webhookSigner.test.ts unchanged (48/50, same two pre-existing failures); tsc error count identical to baseline.
Closes #1307