...
1 package header
2
3 import (
4 "net/http"
5 "reflect"
6 "testing"
7 )
8
9 func TestSanitize(t *testing.T) {
10 var headers = http.Header{}
11
12
13 headers.Set("Accept", "*/*")
14 headers.Set("User-Agent", "curl/7.54.0")
15 headers.Add("Cookie", "abcd=secret1")
16 headers.Add("Cookie", "xyz=secret2")
17 headers.Add("Set-Cookie", "session_id=secret3")
18 headers.Add("Set-Cookie", "id=a3fWa; Expires=Wed, 21 Oct 2015 07:28:00 GMT; Secure; HttpOnly")
19 headers.Add("Authorization", "Bearer foo")
20 headers.Add("Proxy-Authorization", "Basic Zm9vQGV4YW1wbGUuY29tOmJhcg==")
21 headers.Set("Content-Type", "application/x-www-form-urlencoded")
22 headers.Set("Content-Length", "3")
23
24 var got = Sanitize(DefaultSanitizers, headers)
25
26 if len(headers) != len(got) {
27 t.Errorf("Expected length of sanitized headers (%d) to be equal to length of original headers (%d)", len(got), len(headers))
28 }
29
30 want := http.Header{
31 "Accept": []string{"*/*"},
32 "User-Agent": []string{"curl/7.54.0"},
33 "Cookie": []string{"abcd=████████████████████", "xyz=████████████████████"},
34 "Set-Cookie": []string{"session_id=████████████████████", "id=████████████████████; Expires=Wed, 21 Oct 2015 07:28:00 GMT; Secure; HttpOnly"},
35 "Authorization": []string{"Bearer ████████████████████"},
36 "Proxy-Authorization": []string{"Basic ████████████████████"},
37 "Content-Type": []string{"application/x-www-form-urlencoded"},
38 "Content-Length": []string{"3"},
39 }
40
41 if !reflect.DeepEqual(got, want) {
42 t.Errorf("Sanitized headers doesn't match expected value: wanted %+v, got %+v instead", want, got)
43 }
44 }
45
View as plain text