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
}
// RemoveBasicAuth returns a copy of the given URL, with any basic auth information
// removed.
// RemoveBasicAuth returns a copy of the given URL, with any basic auth password
// redacted.
func RemoveBasicAuth(u string) string {
uu, err := url.Parse(u)
if err != nil {
return u
}
uu.User = nil
return uu.String()
return uu.Redacted()
}

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

Loading…
Cancel
Save