Description
apps/backend/src/lib/api/cron-auth.ts has no co-located test file, despite gating every /api/cron/* route from unauthenticated invocation. Its shared-secret comparison logic is currently unverified by automated tests, which is a meaningful gap for an authentication boundary.
Requirements and Context
- Cover the valid-secret-header success path.
- Cover the missing-header and wrong-secret rejection paths, asserting the correct HTTP status.
- If the implementation uses a timing-safe comparison, assert it does (equal-length wrong secrets should still be rejected).
Suggested Execution
Branch: test/cron-auth-middleware-coverage
Implement Changes
- Create
apps/backend/src/lib/api/cron-auth.test.ts.
- Cover the valid, missing, and incorrect secret cases described above using a mocked
NextRequest.
Test and Commit
Run npm run test --workspace=@craft/backend -- cron-auth and confirm the new suite passes.
Example Commit Message
test(backend): add unit coverage for cron route authentication middleware
Co-authored-by: <your-name>
Guidelines
- Branch off
main, keep PRs focused on one issue
- All new code must include unit or integration tests
- Ensure
npm run lint and the relevant npm run test workspace pass before review
- Link this issue in your PR description
- Request review from at least one maintainer before merging
Description
apps/backend/src/lib/api/cron-auth.tshas no co-located test file, despite gating every/api/cron/*route from unauthenticated invocation. Its shared-secret comparison logic is currently unverified by automated tests, which is a meaningful gap for an authentication boundary.Requirements and Context
Suggested Execution
Branch:
test/cron-auth-middleware-coverageImplement Changes
apps/backend/src/lib/api/cron-auth.test.ts.NextRequest.Test and Commit
Run
npm run test --workspace=@craft/backend -- cron-authand confirm the new suite passes.Example Commit Message
Guidelines
main, keep PRs focused on one issuenpm run lintand the relevantnpm run testworkspace pass before review