|
1 | | -package hookdeck |
2 | | - |
3 | | -import ( |
4 | | - "net/http" |
5 | | - "testing" |
6 | | - |
7 | | - "github.com/stretchr/testify/require" |
8 | | -) |
9 | | - |
10 | | -func TestRedactHeadersForLog_redactsAuthorization(t *testing.T) { |
11 | | - headers := http.Header{} |
12 | | - headers.Set("Authorization", "Basic c2tfdGVzdDo=") |
13 | | - headers.Set("Content-Type", "application/json") |
14 | | - |
15 | | - redacted := redactHeadersForLog(headers) |
16 | | - require.Equal(t, "[redacted]", redacted.Get("Authorization")) |
17 | | - require.Equal(t, "application/json", redacted.Get("Content-Type")) |
18 | | - require.Equal(t, "Basic c2tfdGVzdDo=", headers.Get("Authorization")) |
19 | | -} |
20 | | - |
21 | | -func TestRedactRequestBodyForLog_redactsGuestAPIKey(t *testing.T) { |
22 | | - body := `{"device_name":"laptop","guest_user_id":"usr_1","guest_api_key":"hk_secret"}` |
23 | | - redacted := redactRequestBodyForLog(body) |
24 | | - require.Contains(t, redacted, `"guest_api_key":"[redacted]"`) |
25 | | - require.Contains(t, redacted, `"guest_user_id":"usr_1"`) |
26 | | - require.NotContains(t, redacted, "hk_secret") |
27 | | -} |
28 | | - |
29 | | -func TestRedactRequestBodyForLog_leavesNonJSONUnchanged(t *testing.T) { |
30 | | - body := "guest_api_key=hk_secret" |
31 | | - require.Equal(t, body, redactRequestBodyForLog(body)) |
32 | | -} |
| 1 | +package hookdeck |
| 2 | + |
| 3 | +import ( |
| 4 | + "net/http" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/stretchr/testify/require" |
| 8 | +) |
| 9 | + |
| 10 | +func TestRedactHeadersForLog_redactsAuthorization(t *testing.T) { |
| 11 | + headers := http.Header{} |
| 12 | + headers.Set("Authorization", "Basic c2tfdGVzdDo=") |
| 13 | + headers.Set("Content-Type", "application/json") |
| 14 | + |
| 15 | + redacted := redactHeadersForLog(headers) |
| 16 | + require.Equal(t, "[redacted]", redacted.Get("Authorization")) |
| 17 | + require.Equal(t, "application/json", redacted.Get("Content-Type")) |
| 18 | + require.Equal(t, "Basic c2tfdGVzdDo=", headers.Get("Authorization")) |
| 19 | +} |
| 20 | + |
| 21 | +func TestRedactRequestBodyForLog_redactsGuestAPIKey(t *testing.T) { |
| 22 | + body := `{"device_name":"laptop","guest_api_key":"hk_secret"}` |
| 23 | + redacted := redactRequestBodyForLog(body) |
| 24 | + require.Contains(t, redacted, `"guest_api_key":"[redacted]"`) |
| 25 | + require.NotContains(t, redacted, "hk_secret") |
| 26 | +} |
| 27 | + |
| 28 | +func TestRedactRequestBodyForLog_leavesNonJSONUnchanged(t *testing.T) { |
| 29 | + body := "guest_api_key=hk_secret" |
| 30 | + require.Equal(t, body, redactRequestBodyForLog(body)) |
| 31 | +} |
0 commit comments