From db0e226d48285a0ae8cda7db05d2ca20d9000dc6 Mon Sep 17 00:00:00 2001 From: Chief Date: Wed, 28 Aug 2019 18:26:13 -0400 Subject: Add numeric username support for SSH urls. Signed-off-by: Chief --- internal/url/url.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/url/url.go b/internal/url/url.go index 0f0d709..14cf133 100644 --- a/internal/url/url.go +++ b/internal/url/url.go @@ -6,7 +6,7 @@ import ( var ( isSchemeRegExp = regexp.MustCompile(`^[^:]+://`) - scpLikeUrlRegExp = regexp.MustCompile(`^(?:(?P[^@]+)@)?(?P[^:\s]+):(?:(?P[0-9]{1,5})/)?(?P[^\\].*)$`) + scpLikeUrlRegExp = regexp.MustCompile(`^(?:(?P[^@]+)@)?(?P[^:\s]+):(?:(?P[0-9]{1,5})(?:\/|:))?(?P[^\\].*\/[^\\].*)$`) ) // MatchesScheme returns true if the given string matches a URL-like -- cgit From 80d88d96cbbbef05054d53745b9488d864859fdd Mon Sep 17 00:00:00 2001 From: Chief Date: Fri, 30 Aug 2019 13:15:14 -0400 Subject: Add tests for SSH url matching. Signed-off-by: Chief --- internal/url/url_test.go | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 internal/url/url_test.go diff --git a/internal/url/url_test.go b/internal/url/url_test.go new file mode 100644 index 0000000..710fa0c --- /dev/null +++ b/internal/url/url_test.go @@ -0,0 +1,50 @@ +package url + +import ( + "testing" +) + +func TestMatchesScpLike(t *testing.T) { + examples := []string{ + "git@github.com:james/bond", + "git@github.com:007/bond", + "git@github.com:22:james/bond", + "git@github.com:22:007/bond", + } + + for _, url := range examples { + if !MatchesScpLike(url) { + t.Fatalf("repo url %q did not match ScpLike", url) + } + } +} + +func TestFindScpLikeComponents(t *testing.T) { + url := "git@github.com:james/bond" + user, host, port, path := FindScpLikeComponents(url) + + if user != "git" || host != "github.com" || port != "" || path != "james/bond" { + t.Fatalf("repo url %q did not match properly", user) + } + + url = "git@github.com:007/bond" + user, host, port, path = FindScpLikeComponents(url) + + if user != "git" || host != "github.com" || port != "" || path != "007/bond" { + t.Fatalf("repo url %q did not match properly", user) + } + + url = "git@github.com:22:james/bond" + user, host, port, path = FindScpLikeComponents(url) + + if user != "git" || host != "github.com" || port != "22" || path != "james/bond" { + t.Fatalf("repo url %q did not match properly", user) + } + + url = "git@github.com:22:007/bond" + user, host, port, path = FindScpLikeComponents(url) + + if user != "git" || host != "github.com" || port != "22" || path != "007/bond" { + t.Fatalf("repo url %q did not match properly", user) + } +} -- cgit From 4c43218e7b19b9db7d9ce6964a6cfc569cfddbf1 Mon Sep 17 00:00:00 2001 From: Chief Date: Fri, 30 Aug 2019 14:08:56 -0400 Subject: Use gocheck for test. Signed-off-by: Chief --- internal/url/url_test.go | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) mode change 100644 => 100755 internal/url/url_test.go diff --git a/internal/url/url_test.go b/internal/url/url_test.go old mode 100644 new mode 100755 index 710fa0c..d168db6 --- a/internal/url/url_test.go +++ b/internal/url/url_test.go @@ -2,9 +2,17 @@ package url import ( "testing" + + . "gopkg.in/check.v1" ) -func TestMatchesScpLike(t *testing.T) { +func Test(t *testing.T) { TestingT(t) } + +type URLSuite struct{} + +var _ = Suite(&URLSuite{}) + +func (s *URLSuite) TestMatchesScpLike(c *C) { examples := []string{ "git@github.com:james/bond", "git@github.com:007/bond", @@ -13,38 +21,40 @@ func TestMatchesScpLike(t *testing.T) { } for _, url := range examples { - if !MatchesScpLike(url) { - t.Fatalf("repo url %q did not match ScpLike", url) - } + c.Check(MatchesScpLike(url), Equals, true) } } -func TestFindScpLikeComponents(t *testing.T) { +func (s *URLSuite) TestFindScpLikeComponents(c *C) { url := "git@github.com:james/bond" user, host, port, path := FindScpLikeComponents(url) - if user != "git" || host != "github.com" || port != "" || path != "james/bond" { - t.Fatalf("repo url %q did not match properly", user) - } + c.Check(user, Equals, "git") + c.Check(host, Equals, "github.com") + c.Check(port, Equals, "") + c.Check(path, Equals, "james/bond") url = "git@github.com:007/bond" user, host, port, path = FindScpLikeComponents(url) - if user != "git" || host != "github.com" || port != "" || path != "007/bond" { - t.Fatalf("repo url %q did not match properly", user) - } + c.Check(user, Equals, "git") + c.Check(host, Equals, "github.com") + c.Check(port, Equals, "") + c.Check(path, Equals, "007/bond") url = "git@github.com:22:james/bond" user, host, port, path = FindScpLikeComponents(url) - if user != "git" || host != "github.com" || port != "22" || path != "james/bond" { - t.Fatalf("repo url %q did not match properly", user) - } + c.Check(user, Equals, "git") + c.Check(host, Equals, "github.com") + c.Check(port, Equals, "22") + c.Check(path, Equals, "james/bond") url = "git@github.com:22:007/bond" user, host, port, path = FindScpLikeComponents(url) - if user != "git" || host != "github.com" || port != "22" || path != "007/bond" { - t.Fatalf("repo url %q did not match properly", user) - } + c.Check(user, Equals, "git") + c.Check(host, Equals, "github.com") + c.Check(port, Equals, "22") + c.Check(path, Equals, "007/bond") } -- cgit