From 0dff0fdab4f1137006b7a192ba0746c11d820f23 Mon Sep 17 00:00:00 2001 From: Alex Couture-Beil Date: Tue, 15 Dec 2020 13:28:26 -0800 Subject: [PATCH] Check for explicit ssh git URL - fix IsSSHTransport to also check for explicitly-defined ssh-based git repos Signed-off-by: Alex Couture-Beil --- util/sshutil/transport_validation.go | 7 +++++++ util/sshutil/transport_validation_test.go | 1 + 2 files changed, 8 insertions(+) diff --git a/util/sshutil/transport_validation.go b/util/sshutil/transport_validation.go index f00a1df2..598afac7 100644 --- a/util/sshutil/transport_validation.go +++ b/util/sshutil/transport_validation.go @@ -2,10 +2,17 @@ package sshutil import ( "regexp" + "strings" ) var gitSSHRegex = regexp.MustCompile("^[a-zA-Z0-9-_]+@[a-zA-Z0-9-.]+:.*$") func IsSSHTransport(s string) bool { + // check for explicit ssh transport + if strings.HasPrefix(s, "ssh://") { + return true + } + + // check for implicit ssh transport return gitSSHRegex.MatchString(s) } diff --git a/util/sshutil/transport_validation_test.go b/util/sshutil/transport_validation_test.go index 0f8ade57..546986dd 100644 --- a/util/sshutil/transport_validation_test.go +++ b/util/sshutil/transport_validation_test.go @@ -20,4 +20,5 @@ func TestIsSSHTransport(t *testing.T) { require.True(t, IsSSHTransport("other_Funky-username52@example.com:path/to/repo.git/")) require.True(t, IsSSHTransport("other_Funky-username52@example.com:/to/really:odd:repo.git/")) require.True(t, IsSSHTransport("teddy@4houses-down.com:/~/catnip.git/")) + require.True(t, IsSSHTransport("ssh://root@subdomain.example.hostname:2222/root/my/really/weird/path/foo.git")) }