40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
|
|
package internal
|
||
|
|
|
||
|
|
import (
|
||
|
|
"net/http"
|
||
|
|
"reflect"
|
||
|
|
"testing"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestRedactHeaders(t *testing.T) {
|
||
|
|
in := http.Header{
|
||
|
|
"Cookie": []string{"session=abc"},
|
||
|
|
"Authorization": []string{"Bearer token"},
|
||
|
|
"X-Api-Token": []string{"secret"},
|
||
|
|
"Content-Type": []string{"application/json"},
|
||
|
|
}
|
||
|
|
got := RedactHeaders(in)
|
||
|
|
|
||
|
|
if want := []string{"<redacted>"}; !reflect.DeepEqual(got["Cookie"], want) {
|
||
|
|
t.Fatalf("cookie not redacted: %v", got["Cookie"])
|
||
|
|
}
|
||
|
|
if want := []string{"<redacted>"}; !reflect.DeepEqual(got["Authorization"], want) {
|
||
|
|
t.Fatalf("authorization not redacted: %v", got["Authorization"])
|
||
|
|
}
|
||
|
|
if want := []string{"<redacted>"}; !reflect.DeepEqual(got["X-Api-Token"], want) {
|
||
|
|
t.Fatalf("token header not redacted: %v", got["X-Api-Token"])
|
||
|
|
}
|
||
|
|
if want := []string{"application/json"}; !reflect.DeepEqual(got["Content-Type"], want) {
|
||
|
|
t.Fatalf("safe header should remain unchanged: %v", got["Content-Type"])
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestLogfNoPanic(t *testing.T) {
|
||
|
|
orig := Debug
|
||
|
|
Debug = false
|
||
|
|
Logf("this should be ignored")
|
||
|
|
Debug = true
|
||
|
|
Logf("this should log: %d", 1)
|
||
|
|
Debug = orig
|
||
|
|
}
|