From 038812b4cbc3023a177bc2da00fbcd0f98f81e45 Mon Sep 17 00:00:00 2001 From: Philip O'Toole Date: Tue, 1 Nov 2022 07:37:11 -0400 Subject: [PATCH] Use standard library redaction functionality --- http/url/url.go | 7 +++---- http/url/url_test.go | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/http/url/url.go b/http/url/url.go index e615dda6..20f468fc 100644 --- a/http/url/url.go +++ b/http/url/url.go @@ -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() } diff --git a/http/url/url_test.go b/http/url/url_test.go index 5e77545b..beff066e 100644 --- a/http/url/url_test.go +++ b/http/url/url_test.go @@ -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", }, }