Skip to content

test(metrics): cover equal-length wrong-token + malformed-header paths (#342)#343

Merged
CryptoJones merged 1 commit into
masterfrom
test/metrics-auth-branch-coverage
May 19, 2026
Merged

test(metrics): cover equal-length wrong-token + malformed-header paths (#342)#343
CryptoJones merged 1 commit into
masterfrom
test/metrics-auth-branch-coverage

Conversation

@CryptoJones
Copy link
Copy Markdown
Owner

Closes #342.

Summary

Adds two missing test cases for checkMetricsAuth: (a) non-Bearer prefix, (b) equal-length wrong token (the timingSafeEqual branch — different-length tokens hit a different code path that was already covered).

Test plan

  • npm run lint && npm test — 790 passing (was 788).

Proudly Made in Nebraska. Go Big Red! 🌽 https://xkcd.com/2347/

…paths

`checkMetricsAuth` in `app/middleware/metrics.js` branches three
ways:
  1. Missing Authorization header → 401.
  2. Non-"Bearer <token>" shape → 401.
  3. Bearer-prefixed but token doesn't match:
     a. Equal-length supplied vs required → timingSafeEqual.
     b. Different-length → sha256-of-both fallback, returning false.

Pre-existing tests covered (1), (3b) (the "wrong token" case used
a value of different length than the configured token), and the
happy path. Missing:

- (2) — a header without the `Bearer ` prefix. Without an explicit
  test, a future "lenient parser" refactor that fell through to
  treat the raw header value as the token could slip past CI.

- (3a) — the timingSafeEqual branch with a same-length wrong
  token. A future "optimization" that returned true on equal
  bytes for the wrong reason would be invisible until a security
  scanner caught it.

Adds both cases; test count 788 → 790.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@CryptoJones CryptoJones merged commit bcb134c into master May 19, 2026
3 checks passed
@CryptoJones CryptoJones deleted the test/metrics-auth-branch-coverage branch May 19, 2026 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(metrics): equal-length wrong-token + non-Bearer-prefix paths uncovered

1 participant