MCPcopy
hub / github.com/tinyauthapp/tinyauth / TestParseHeaders

Function TestParseHeaders

internal/utils/label_utils_test.go:11–66  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

9)
10
11func TestParseHeaders(t *testing.T) {
12 // Normal case
13 headers := []string{
14 "X-Custom-Header=Value",
15 "Another-Header=AnotherValue",
16 }
17 expected := map[string]string{
18 "X-Custom-Header": "Value",
19 "Another-Header": "AnotherValue",
20 }
21 assert.DeepEqual(t, expected, utils.ParseHeaders(headers))
22
23 // Case insensitivity and trimming
24 headers = []string{
25 " x-custom-header = Value ",
26 "ANOTHER-HEADER=AnotherValue",
27 }
28 expected = map[string]string{
29 "X-Custom-Header": "Value",
30 "Another-Header": "AnotherValue",
31 }
32 assert.DeepEqual(t, expected, utils.ParseHeaders(headers))
33
34 // Invalid headers (missing '=', empty key/value)
35 headers = []string{
36 "InvalidHeader",
37 "=NoKey",
38 "NoValue=",
39 " = ",
40 }
41 expected = map[string]string{}
42 assert.DeepEqual(t, expected, utils.ParseHeaders(headers))
43
44 // Headers with unsafe characters
45 headers = []string{
46 "X-Custom-Header=Val\x00ue", // Null byte
47 "Another-Header=Anoth\x7FerValue", // DEL character
48 "Good-Header=GoodValue",
49 }
50 expected = map[string]string{
51 "X-Custom-Header": "Value",
52 "Another-Header": "AnotherValue",
53 "Good-Header": "GoodValue",
54 }
55 assert.DeepEqual(t, expected, utils.ParseHeaders(headers))
56
57 // Header with spaces in key (should be ignored)
58 headers = []string{
59 "X Custom Header=Value",
60 "Valid-Header=ValidValue",
61 }
62 expected = map[string]string{
63 "Valid-Header": "ValidValue",
64 }
65 assert.DeepEqual(t, expected, utils.ParseHeaders(headers))
66}
67
68func TestSanitizeHeader(t *testing.T) {

Callers

nothing calls this directly

Calls 1

ParseHeadersFunction · 0.92

Tested by

no test coverage detected