1
0
Fork 0

Use standard library redaction functionality

master
Philip O'Toole 2 years ago
parent 6c837046fd
commit 038812b4cb

@ -56,13 +56,12 @@ func AddBasicAuth(joinAddr, username, password string) (string, error) {
return u.String(), nil return u.String(), nil
} }
// RemoveBasicAuth returns a copy of the given URL, with any basic auth information // RemoveBasicAuth returns a copy of the given URL, with any basic auth password
// removed. // redacted.
func RemoveBasicAuth(u string) string { func RemoveBasicAuth(u string) string {
uu, err := url.Parse(u) uu, err := url.Parse(u)
if err != nil { if err != nil {
return u return u
} }
uu.User = nil return uu.Redacted()
return uu.String()
} }

@ -121,15 +121,15 @@ func Test_RemoveBasicAuth(t *testing.T) {
}, },
{ {
orig: "https://foo:bar@localhost", orig: "https://foo:bar@localhost",
removed: "https://localhost", removed: "https://foo:xxxxx@localhost",
}, },
{ {
orig: "https://foo:bar@localhost:4001", orig: "https://foo:bar@localhost:4001",
removed: "https://localhost:4001", removed: "https://foo:xxxxx@localhost:4001",
}, },
{ {
orig: "http://foo:bar@localhost:4001/path", orig: "http://foo:bar@localhost:4001/path",
removed: "http://localhost:4001/path", removed: "http://foo:xxxxx@localhost:4001/path",
}, },
} }

Loading…
Cancel
Save