From 2ead24d017ae3cfdecb02222d5a5fe63caae2a83 Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Mon, 23 Sep 2024 13:56:46 +0200 Subject: [PATCH 1/3] 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) + } } From 4ab039bc044a864e64486e4aba9c542d5bf23680 Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Mon, 23 Sep 2024 14:08:06 +0200 Subject: [PATCH 2/3] remove azure tests --- libs/git/repository_test.go | 8 -------- 1 file changed, 8 deletions(-) diff --git a/libs/git/repository_test.go b/libs/git/repository_test.go index 46adae7761..dc77e5b7a5 100644 --- a/libs/git/repository_test.go +++ b/libs/git/repository_test.go @@ -221,14 +221,6 @@ func TestRepositoryOriginUrlRemovesUserCreds(t *testing.T) { 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 { From e889d48b7b9716ebec0741ecd9a3605dbeeda181 Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Mon, 23 Sep 2024 14:35:54 +0200 Subject: [PATCH 3/3] clarify --- libs/git/repository_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libs/git/repository_test.go b/libs/git/repository_test.go index dc77e5b7a5..93d9a03dcc 100644 --- a/libs/git/repository_test.go +++ b/libs/git/repository_test.go @@ -218,6 +218,9 @@ func TestRepositoryOriginUrlRemovesUserCreds(t *testing.T) { expected: "https://github.com/databricks/foobar.git", }, { + // Note: The token is still considered and parsed as a username here. + // However credentials integrations by Git providers like GitHub + // allow for setting a PAT token as a username. url: "https://token@github.com/databricks/foobar.git", expected: "https://github.com/databricks/foobar.git", },