-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredact_test.go
35 lines (33 loc) · 1.27 KB
/
redact_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package hmetrics
import (
"net/url"
"testing"
)
func TestRedacting(t *testing.T) {
const uuid1 = "12345678-90ab-cdef-fedc-ba0987654321"
const uuid2 = "deadbeef-abcd-9876-1234-f00fdeadbeef"
for i, e := range []struct{ in, out string }{
// beware with multiple query params that may be reordered
{"http://fred:[email protected]:1234/foo", "http://fred:[email protected]:1234/foo"},
{"http://metrics.host:1234/foo", "http://metrics.host:1234/foo"},
{"https://metrics.host/foo?token=wibble", "https://metrics.host/foo?token=redacted"},
{"https://fred:[email protected]/foo?secret=wibble", "https://fred:[email protected]/foo?secret=redacted"},
{"https://metrics.host/" + uuid1, "https://metrics.host/redacted-uuid-form"},
{"https://metrics.host/" + uuid1 + "/" + uuid2, "https://metrics.host/redacted-uuid-form/redacted-uuid-form"},
} {
dirty, err := url.Parse(e.in)
if err != nil {
t.Fatalf("[%d] url.Parse(%q) failed: %s", i, e.in, err)
}
cleaned, err := redactURL(dirty)
if err != nil {
t.Errorf("[%d] redactURL(%q) failed: %s", i, e.in, err)
}
have := cleaned.String()
if have != e.out {
t.Errorf("[%d] mismatch: redactURL(%q)=%q, expected %q", i, e.in, have, e.out)
} else {
t.Logf("[%d] good: redactURL(%q)=%q", i, e.in, have)
}
}
}