Commit bcb134c
test(metrics): cover the equal-length wrong-token + malformed-header paths (#343)
`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: Aaron K. Clark <akclark@thenetwerk.net>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent f84fd45 commit bcb134c
1 file changed
Lines changed: 28 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
104 | 132 | | |
0 commit comments