(t *testing.T)
| 11 | ) |
| 12 | |
| 13 | func TestRedactHeaders(t *testing.T) { |
| 14 | t.Parallel() |
| 15 | |
| 16 | t.Run("nil input", func(t *testing.T) { |
| 17 | t.Parallel() |
| 18 | |
| 19 | require.Nil(t, chatdebug.RedactHeaders(nil)) |
| 20 | }) |
| 21 | |
| 22 | t.Run("empty header", func(t *testing.T) { |
| 23 | t.Parallel() |
| 24 | |
| 25 | redacted := chatdebug.RedactHeaders(http.Header{}) |
| 26 | require.NotNil(t, redacted) |
| 27 | require.Empty(t, redacted) |
| 28 | }) |
| 29 | |
| 30 | t.Run("authorization redacted and others preserved", func(t *testing.T) { |
| 31 | t.Parallel() |
| 32 | |
| 33 | headers := http.Header{ |
| 34 | "Authorization": {"Bearer secret-token"}, |
| 35 | "Accept": {"application/json"}, |
| 36 | } |
| 37 | |
| 38 | redacted := chatdebug.RedactHeaders(headers) |
| 39 | require.Equal(t, chatdebug.RedactedValue, redacted["Authorization"]) |
| 40 | require.Equal(t, "application/json", redacted["Accept"]) |
| 41 | }) |
| 42 | |
| 43 | t.Run("multi-value headers are flattened", func(t *testing.T) { |
| 44 | t.Parallel() |
| 45 | |
| 46 | headers := http.Header{ |
| 47 | "Accept": {"application/json", "text/plain"}, |
| 48 | } |
| 49 | |
| 50 | redacted := chatdebug.RedactHeaders(headers) |
| 51 | require.Equal(t, "application/json, text/plain", redacted["Accept"]) |
| 52 | }) |
| 53 | |
| 54 | t.Run("header name matching is case insensitive", func(t *testing.T) { |
| 55 | t.Parallel() |
| 56 | |
| 57 | lowerAuthorization := "authorization" |
| 58 | upperAuthorization := "AUTHORIZATION" |
| 59 | headers := http.Header{ |
| 60 | lowerAuthorization: {"lower"}, |
| 61 | upperAuthorization: {"upper"}, |
| 62 | } |
| 63 | |
| 64 | redacted := chatdebug.RedactHeaders(headers) |
| 65 | require.Equal(t, chatdebug.RedactedValue, redacted[lowerAuthorization]) |
| 66 | require.Equal(t, chatdebug.RedactedValue, redacted[upperAuthorization]) |
| 67 | }) |
| 68 | |
| 69 | t.Run("token and secret substrings are redacted", func(t *testing.T) { |
| 70 | t.Parallel() |
nothing calls this directly
no test coverage detected