Commit 189246a
authored
[Repo Assist] refactor(auth): move IsMalformedHeader from server to auth package (#4144)
🤖 *This PR was created by Repo Assist, an automated AI assistant.*
## Summary
Moves the RFC 7230 header-character validation logic out of
`internal/server/auth.go` into `internal/auth/header.go`, where all
other header-parsing utilities already live.
This addresses **Issue 3** from the automated [Semantic Function
Clustering Analysis
(#4138)](#4138), which
identified that `isMalformedAuthHeader` is conceptually misplaced — it
validates raw header bytes per RFC 7230 before any auth parsing, and
belongs alongside `ParseAuthHeader`, `ExtractSessionID`,
`ValidateAPIKey`, etc.
## Changes
- **`internal/auth/header.go`** — Add exported `IsMalformedHeader(header
string) bool`
- **`internal/server/auth.go`** — Remove private
`isMalformedAuthHeader`; import `internal/auth`; call
`auth.IsMalformedHeader`
- **`internal/auth/header_test.go`** — Add `TestIsMalformedHeader` with
12 test cases (empty string, normal key, horizontal tab, null byte,
control chars 0x01/0x0A/0x0D/0x1F, DEL 0x7F, etc.)
- **`internal/server/auth_test.go`** — Update
`TestIsMalformedAuthHeader` to call `auth.IsMalformedHeader` (no logic
change; existing 10 cases preserved)
## Rationale
Before this change, `server/auth.go` contained a comment pointing
maintainers *at* `internal/auth` for header logic — yet itself held a
piece of header validation. After this change, all header validation
lives in one package and can be used by any future callers without
importing the server package.
## Test Status
The environment has Go 1.24.13; the module requires Go 1.25.0
(network-restricted — toolchain download blocked). Build and test could
not be run locally. CI will provide authoritative results.
The logic in `IsMalformedHeader` is identical to the previous
`isMalformedAuthHeader` — only renamed and relocated. The existing 10
unit tests in `server/auth_test.go` continue to cover the same code
paths via the new `auth.IsMalformedHeader` call, and 12 new cases are
added directly to `auth/header_test.go`.
> [!WARNING]
> <details>
> <summary><strong>4 files changed
Lines changed: 98 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
183 | 183 | | |
184 | 184 | | |
185 | 185 | | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
186 | 199 | | |
187 | 200 | | |
188 | 201 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 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 | + | |
12 | 90 | | |
13 | 91 | | |
14 | 92 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | 12 | | |
25 | 13 | | |
26 | 14 | | |
| |||
43 | 31 | | |
44 | 32 | | |
45 | 33 | | |
46 | | - | |
| 34 | + | |
47 | 35 | | |
48 | 36 | | |
49 | 37 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
| |||
292 | 294 | | |
293 | 295 | | |
294 | 296 | | |
295 | | - | |
| 297 | + | |
296 | 298 | | |
297 | 299 | | |
298 | 300 | | |
| |||
313 | 315 | | |
314 | 316 | | |
315 | 317 | | |
316 | | - | |
317 | | - | |
| 318 | + | |
| 319 | + | |
318 | 320 | | |
319 | 321 | | |
320 | 322 | | |
0 commit comments