55 | 55 |
}
|
56 | 56 |
|
57 | 57 |
func TestExtractRequestInfoFromReq_RedactURL(t *testing.T) {
|
58 | |
testCases := []struct{ in, exp string }{
|
59 | |
{in: "", exp: "http://example.com"},
|
60 | |
{in: "/", exp: "http://example.com/"},
|
61 | |
{in: "/foo.html", exp: "http://example.com/foo.html"},
|
62 | |
{in: "/foo.html?q=something&bar=123", exp: "http://example.com/foo.html?q=something&bar=123"},
|
63 | |
{in: "/foo.html?foo=1&foo=2&foo=3", exp: "http://example.com/foo.html?foo=1&foo=2&foo=3"},
|
|
58 |
testCases := []struct {
|
|
59 |
in url.URL
|
|
60 |
exp string
|
|
61 |
}{
|
|
62 |
{in: url.URL{}, exp: "http://example.com"},
|
|
63 |
{in: url.URL{Path: "/"}, exp: "http://example.com/"},
|
|
64 |
{in: url.URL{Path: "/foo.html"}, exp: "http://example.com/foo.html"},
|
|
65 |
{in: url.URL{Path: "/foo.html", RawQuery: "q=something&bar=123"}, exp: "http://example.com/foo.html?q=something&bar=123"},
|
|
66 |
{in: url.URL{Path: "/foo.html", RawQuery: "foo=1&foo=2&foo=3"}, exp: "http://example.com/foo.html?foo=1&foo=2&foo=3"},
|
64 | 67 |
|
65 | 68 |
// Invalid query string.
|
66 | |
{in: "/foo?%", exp: "http://example.com/foo?%"},
|
|
69 |
{in: url.URL{Path: "/foo", RawQuery: "%"}, exp: "http://example.com/foo?%"},
|
67 | 70 |
|
68 | 71 |
// Query params contain secrets
|
69 | |
{in: "/foo.html?access_token=something", exp: "http://example.com/foo.html?access_token=FILTERED"},
|
70 | |
{in: "/foo.html?access_token=something&access_token=", exp: "http://example.com/foo.html?access_token=FILTERED&access_token="},
|
|
72 |
{in: url.URL{Path: "/foo.html", RawQuery: "access_token=something"}, exp: "http://example.com/foo.html?access_token=[FILTERED]"},
|
|
73 |
{in: url.URL{Path: "/foo.html", RawQuery: "access_token=something&access_token=&foo=bar"}, exp: "http://example.com/foo.html?access_token=[FILTERED]&access_token=&foo=bar"},
|
71 | 74 |
}
|
72 | 75 |
|
73 | 76 |
for _, tc := range testCases {
|
74 | |
parsedURL, err := url.Parse(tc.in)
|
75 | |
if err != nil {
|
76 | |
t.Fatalf("error parsing originalURI (bad test): %v", err)
|
77 | |
}
|
78 | |
|
79 | 77 |
req := &http.Request{
|
80 | 78 |
Host: "example.com",
|
81 | |
URL: parsedURL,
|
|
79 |
URL: &tc.in,
|
82 | 80 |
}
|
83 | 81 |
result := extractRequestInfoFromReq(req)
|
84 | 82 |
if result.URL != tc.exp {
|