@@ -189,3 +189,45 @@ func TestGitRemoteURL(t *testing.T) {
189189 })
190190 }
191191}
192+
193+ func TestStripCredentials (t * testing.T ) {
194+ cases := []struct {
195+ name string
196+ url string
197+ want string
198+ }{
199+ {
200+ name : "non-blank Password" ,
201+ url :
"https://user:[email protected] /this:that" ,
202+ want : "https://host.tld/this:that" ,
203+ },
204+ {
205+ name : "blank Password" ,
206+ url :
"https://[email protected] /this:that" ,
207+ want : "https://host.tld/this:that" ,
208+ },
209+ {
210+ name : "blank Username" ,
211+ url :
"https://:[email protected] /this:that" ,
212+ want : "https://host.tld/this:that" ,
213+ },
214+ {
215+ name : "blank Username, blank Password" ,
216+ url : "https://host.tld/this:that" ,
217+ want : "https://host.tld/this:that" ,
218+ },
219+ {
220+ name : "invalid URL" ,
221+ url : "1https://foo.com" ,
222+ want : "1https://foo.com" ,
223+ },
224+ }
225+ for _ , tt := range cases {
226+ tt := tt
227+ t .Run (tt .name , func (t * testing.T ) {
228+ if g , w := stripCredentials (tt .url ), tt .want ; g != w {
229+ t .Fatalf ("got: %q\n want: %q" , g , w )
230+ }
231+ })
232+ }
233+ }
0 commit comments