Skip to content

Commit

Permalink
Assert tokens are redacted in origin URL when username is not specified
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyas-goenka committed Sep 23, 2024
1 parent 56ed9be commit 2ead24d
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions libs/git/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,31 @@ func TestRepositoryGitConfigWhenNotARepo(t *testing.T) {
}

func TestRepositoryOriginUrlRemovesUserCreds(t *testing.T) {
repo := newTestRepository(t)
repo.addOriginUrl("https://username:[email protected]/databricks/foobar.git")
repo.assertOriginUrl("https://github.com/databricks/foobar.git")
tcases := []struct {
url string
expected string
}{
{
url: "https://username:[email protected]/databricks/foobar.git",
expected: "https://github.com/databricks/foobar.git",
},
{
url: "https://[email protected]/databricks/foobar.git",
expected: "https://github.com/databricks/foobar.git",
},
{
url: "https://johndoe:[email protected]/mycompany/myproject/_git/myrepo",
expected: "https://dev.azure.com/mycompany/myproject/_git/myrepo",
},
{
url: "https://[email protected]/mycompany/myproject/_git/myrepo",
expected: "https://dev.azure.com/mycompany/myproject/_git/myrepo",
},
}

for _, tc := range tcases {
repo := newTestRepository(t)
repo.addOriginUrl(tc.url)
repo.assertOriginUrl(tc.expected)
}
}

0 comments on commit 2ead24d

Please sign in to comment.