From 2ead24d017ae3cfdecb02222d5a5fe63caae2a83 Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Mon, 23 Sep 2024 13:56:46 +0200 Subject: [PATCH] Assert tokens are redacted in origin URL when username is not specified --- libs/git/repository_test.go | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/libs/git/repository_test.go b/libs/git/repository_test.go index a28038eebd..46adae7761 100644 --- a/libs/git/repository_test.go +++ b/libs/git/repository_test.go @@ -209,7 +209,31 @@ func TestRepositoryGitConfigWhenNotARepo(t *testing.T) { } func TestRepositoryOriginUrlRemovesUserCreds(t *testing.T) { - repo := newTestRepository(t) - repo.addOriginUrl("https://username:token@github.com/databricks/foobar.git") - repo.assertOriginUrl("https://github.com/databricks/foobar.git") + tcases := []struct { + url string + expected string + }{ + { + url: "https://username:token@github.com/databricks/foobar.git", + expected: "https://github.com/databricks/foobar.git", + }, + { + url: "https://token@github.com/databricks/foobar.git", + expected: "https://github.com/databricks/foobar.git", + }, + { + url: "https://johndoe:abcdefghijklmnopqrstuvwxyz0123456789@dev.azure.com/mycompany/myproject/_git/myrepo", + expected: "https://dev.azure.com/mycompany/myproject/_git/myrepo", + }, + { + url: "https://abcdefghijklmnopqrstuvwxyz0123456789@dev.azure.com/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) + } }