From c634306b013aee84c999862b3c0f9a1b3e3c550a Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 8 Feb 2016 17:29:01 +0000 Subject: [PATCH] Fix 'tcp+tls' protocol not being accepted Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 878a0dc85cacfcf0005d3d2487f6d3266c31552d) From PR #20109 --- pkg/urlutil/urlutil.go | 4 ++-- pkg/urlutil/urlutil_test.go | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/pkg/urlutil/urlutil.go b/pkg/urlutil/urlutil.go index f7094b1fef..1135a4c6ce 100644 --- a/pkg/urlutil/urlutil.go +++ b/pkg/urlutil/urlutil.go @@ -11,7 +11,7 @@ var ( validPrefixes = map[string][]string{ "url": {"http://", "https://"}, "git": {"git://", "github.com/", "git@"}, - "transport": {"tcp://", "udp://", "unix://"}, + "transport": {"tcp://", "tcp+tls://", "udp://", "unix://"}, } urlPathWithFragmentSuffix = regexp.MustCompile(".git(?:#.+)?$") ) @@ -35,7 +35,7 @@ func IsGitTransport(str string) bool { return IsURL(str) || strings.HasPrefix(str, "git://") || strings.HasPrefix(str, "git@") } -// IsTransportURL returns true if the provided str is a transport (tcp, udp, unix) URL. +// IsTransportURL returns true if the provided str is a transport (tcp, tcp+tls, udp, unix) URL. func IsTransportURL(str string) bool { return checkURL(str, "transport") } diff --git a/pkg/urlutil/urlutil_test.go b/pkg/urlutil/urlutil_test.go index bb89d8b5fd..86d48cfe23 100644 --- a/pkg/urlutil/urlutil_test.go +++ b/pkg/urlutil/urlutil_test.go @@ -18,6 +18,12 @@ var ( invalidGitUrls = []string{ "http://github.com/docker/docker.git:#branch", } + transportUrls = []string{ + "tcp://example.com", + "tcp+tls://example.com", + "udp://example.com", + "unix:///example", + } ) func TestValidGitTransport(t *testing.T) { @@ -53,3 +59,11 @@ func TestIsGIT(t *testing.T) { } } } + +func TestIsTransport(t *testing.T) { + for _, url := range transportUrls { + if IsTransportURL(url) == false { + t.Fatalf("%q should be detected as valid Transport url", url) + } + } +}