From bc964d19c1b0dee37aa0fcab2d07442ba2021eef Mon Sep 17 00:00:00 2001 From: Reinhard Naegele Date: Sat, 6 Jul 2019 19:16:57 +0200 Subject: [PATCH] Consider username and password in repo urls Signed-off-by: Reinhard Naegele --- pkg/tool/account.go | 2 +- pkg/tool/account_test.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/tool/account.go b/pkg/tool/account.go index 0a8e5c49..c1433fa2 100644 --- a/pkg/tool/account.go +++ b/pkg/tool/account.go @@ -24,7 +24,7 @@ import ( type AccountValidator struct{} -var repoDomainPattern = regexp.MustCompile("(?:https://|git@)([^/:]+)") +var repoDomainPattern = regexp.MustCompile("(?:https://(?:[^@:]+:[^@:]+@)?|git@)([^/:]+)") func (v AccountValidator) Validate(repoURL string, account string) error { domain, err := parseOutGitRepoDomain(repoURL) diff --git a/pkg/tool/account_test.go b/pkg/tool/account_test.go index a19f174a..498d5e04 100644 --- a/pkg/tool/account_test.go +++ b/pkg/tool/account_test.go @@ -16,10 +16,13 @@ func TestParseOutGitDomain(t *testing.T) { }{ {"GitHub SSH", "git@github.com:foo/bar", "github.com", nil}, {"GitHub HTTPS", "https://github.com/foo/bar", "github.com", nil}, + {"GitHub HTTPS with username/password", "https://foo:token@github.com/foo/bar", "github.com", nil}, {"Gitlab SSH", "git@gitlab.com:foo/bar", "gitlab.com", nil}, {"Gitlab HTTPS", "https://gitlab.com/foo/bar", "gitlab.com", nil}, + {"Gitlab HTTPS with username/password", "https://gitlab-ci-token:password@gitlab.com/foo/bar", "gitlab.com", nil}, {"Bitbucket SSH", "git@bitbucket.com:foo/bar", "bitbucket.com", nil}, {"Bitbucket HTTPS", "https://bitbucket.com/foo/bar", "bitbucket.com", nil}, + {"Bitbucket HTTPS with username/password", "https://user:pass@bitbucket.com/foo/bar", "bitbucket.com", nil}, {"Invalid", "foo/bar", "", fmt.Errorf("Could not parse git repository domain for 'foo/bar'")}, }