|
| 1 | +package proxy |
| 2 | + |
| 3 | +import "testing" |
| 4 | + |
| 5 | +func TestSanitizeAccessControlRequestHeaderValues(t *testing.T) { |
| 6 | + tests := []struct { |
| 7 | + name string |
| 8 | + input string |
| 9 | + expected string |
| 10 | + }{ |
| 11 | + { |
| 12 | + name: "empty string", |
| 13 | + input: "", |
| 14 | + expected: "", |
| 15 | + }, |
| 16 | + { |
| 17 | + name: "whitespace only", |
| 18 | + input: " ", |
| 19 | + expected: "", |
| 20 | + }, |
| 21 | + { |
| 22 | + name: "single valid value", |
| 23 | + input: "content-type", |
| 24 | + expected: "content-type", |
| 25 | + }, |
| 26 | + { |
| 27 | + name: "multiple valid values", |
| 28 | + input: "content-type, authorization, x-requested-with", |
| 29 | + expected: "content-type, authorization, x-requested-with", |
| 30 | + }, |
| 31 | + { |
| 32 | + name: "values with extra spaces", |
| 33 | + input: " content-type , authorization ", |
| 34 | + expected: "content-type, authorization", |
| 35 | + }, |
| 36 | + { |
| 37 | + name: "values with tabs", |
| 38 | + input: "content-type,\tauthorization", |
| 39 | + expected: "content-type, authorization", |
| 40 | + }, |
| 41 | + { |
| 42 | + name: "values with invalid characters", |
| 43 | + input: "content-type, auth\n, x-requested-with\r", |
| 44 | + expected: "content-type, auth, x-requested-with", |
| 45 | + }, |
| 46 | + { |
| 47 | + name: "empty values in list", |
| 48 | + input: "content-type,,authorization", |
| 49 | + expected: "content-type, authorization", |
| 50 | + }, |
| 51 | + { |
| 52 | + name: "leading and trailing commas", |
| 53 | + input: ",content-type,authorization,", |
| 54 | + expected: "content-type, authorization", |
| 55 | + }, |
| 56 | + { |
| 57 | + name: "mixed valid and invalid values", |
| 58 | + input: "content-type, \x00invalid, x-requested-with", |
| 59 | + expected: "content-type, x-requested-with", |
| 60 | + }, |
| 61 | + { |
| 62 | + name: "mixed case values", |
| 63 | + input: "Content-Type, my-Valid-Header, Another-hEader", |
| 64 | + expected: "Content-Type, my-Valid-Header, Another-hEader", |
| 65 | + }, |
| 66 | + } |
| 67 | + |
| 68 | + for _, tt := range tests { |
| 69 | + t.Run(tt.name, func(t *testing.T) { |
| 70 | + got := SanitizeAccessControlRequestHeaderValues(tt.input) |
| 71 | + if got != tt.expected { |
| 72 | + t.Errorf("SanitizeAccessControlRequestHeaderValues(%q) = %q, want %q", |
| 73 | + tt.input, got, tt.expected) |
| 74 | + } |
| 75 | + }) |
| 76 | + } |
| 77 | +} |
0 commit comments