Commit 043ebe7
authored
[test] Add tests for server.nonceCache.evictExpired (#5965)
# Test Coverage Improvement: `nonceCache.evictExpired`
## Function Analyzed
- **Package**: `internal/server`
- **Function**: `(*nonceCache).evictExpired`
- **File**: `internal/server/hmac.go`
- **Previous Coverage**: 0% (no direct tests)
- **New Coverage**: High (all branches covered)
- **Complexity**: Medium
## Why This Function?
`evictExpired` is the core garbage-collection routine for the HMAC
replay-protection nonce cache. It is called on every HMAC-validated
request (from both `checkAndSet` and `seenNonce`) but had **zero direct
test coverage**. While the function is exercised indirectly via
integration through the middleware tests, no test directly validated its
eviction logic, boundary conditions, or interaction behaviour.
The function has meaningful branching logic (`now.After(deadline)`) and
is security-critical — if eviction is broken, the nonce cache could grow
unboundedly or incorrectly retain/remove nonces, weakening replay
protection.
## Tests Added
- ✅ Empty cache (no-op, no panic)
- ✅ All entries expired — all removed
- ✅ All entries fresh — none removed
- ✅ Mixed expired and fresh — only expired entries evicted
- ✅ Exact deadline boundary (`now.After(deadline)` is `false` when equal
→ entry retained)
- ✅ Just-expired entry (one nanosecond past deadline → evicted)
- ✅ Large entry count (100 entries, 50 expired / 50 fresh)
- ✅ Integration: `checkAndSet` internally triggers eviction of stale
entries
- ✅ Integration: `seenNonce` internally triggers eviction of stale
entries
## Coverage Report
```
Before: 0% direct coverage (exercised only as side-effect of middleware tests)
After: All branches of evictExpired directly covered
Improvement: Full branch coverage for the eviction logic
```
## Test File
`internal/server/hmac_evict_coverage_test.go` — 9 test functions using
table-driven and scenario-based patterns consistent with the existing
`hmac_test.go`.
---
*Generated by Test Coverage Improver*
*Next run will target the next most complex under-tested function*
> [!WARNING]
> <details>
> <summary>Firewall blocked 3 domains</summary>
>
> The following domains were blocked by the firewall during workflow
execution:
>
> - `goproxy.io`
> - `proxy.golang.org`
> - `sum.golang.org`
>> To allow these domains, add them to the `network.allowed` list in
your workflow frontmatter:
>
> ```yaml
> network:
> allowed:
> - defaults
> - "goproxy.io"
> - "proxy.golang.org"
> - "sum.golang.org"
> ```
>
> See [Network
Configuration](https://github.github.com/gh-aw/reference/network/) for
more information.
>
> </details>
> Generated by [Test Coverage
Improver](https://github.com/github/gh-aw-mcpg/actions/runs/26048920315/agentic_workflow)
· ● 13.7M ·
[◷](https://github.com/search?q=repo%3Agithub%2Fgh-aw-mcpg+%22gh-aw-workflow-id%3A+test-coverage-improver%22&type=pullrequests)
<!-- gh-aw-agentic-workflow: Test Coverage Improver, engine: copilot,
version: 1.0.40, model: claude-sonnet-4.6, id: 26048920315, workflow_id:
test-coverage-improver, run:
https://github.com/github/gh-aw-mcpg/actions/runs/26048920315 -->
<!-- gh-aw-workflow-id: test-coverage-improver -->1 file changed
Lines changed: 201 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 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 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
0 commit comments