]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: mark ssh:// URLs as secure
authorRoss Light <light@google.com>
Thu, 25 Jun 2015 20:14:28 +0000 (13:14 -0700)
committerRuss Cox <rsc@golang.org>
Tue, 14 Jul 2015 05:27:57 +0000 (05:27 +0000)
Add tests for isSecure function.

Change-Id: I49de9d2846b75d4c7be745484f85d351a6fd851d
Reviewed-on: https://go-review.googlesource.com/11514
Reviewed-by: Russ Cox <rsc@golang.org>
src/cmd/go/vcs.go
src/cmd/go/vcs_test.go

index ea7dd1c1df4e9d56de71406e69074810320109b8..29433de54102d02c6bf07ed3eeee9a68301dc604 100644 (file)
@@ -46,6 +46,7 @@ var isSecureScheme = map[string]bool{
        "git+ssh": true,
        "bzr+ssh": true,
        "svn+ssh": true,
+       "ssh":     true,
 }
 
 func (v *vcsCmd) isSecure(repo string) bool {
index a60a7ac1a0c5c6ab66af79de24c46b7633054412..44f7ea8418bec0d6fda9aecbec881bc3a0f9dd48 100644 (file)
@@ -117,3 +117,35 @@ func TestRepoRootForImportPath(t *testing.T) {
                }
        }
 }
+
+func TestIsSecure(t *testing.T) {
+       tests := []struct {
+               vcs    *vcsCmd
+               url    string
+               secure bool
+       }{
+               {vcsGit, "http://example.com/foo.git", false},
+               {vcsGit, "https://example.com/foo.git", true},
+               {vcsBzr, "http://example.com/foo.bzr", false},
+               {vcsBzr, "https://example.com/foo.bzr", true},
+               {vcsSvn, "http://example.com/svn", false},
+               {vcsSvn, "https://example.com/svn", true},
+               {vcsHg, "http://example.com/foo.hg", false},
+               {vcsHg, "https://example.com/foo.hg", true},
+               {vcsGit, "ssh://user@example.com/foo.git", true},
+               {vcsGit, "user@server:path/to/repo.git", false},
+               {vcsGit, "user@server:", false},
+               {vcsGit, "server:repo.git", false},
+               {vcsGit, "server:path/to/repo.git", false},
+               {vcsGit, "example.com:path/to/repo.git", false},
+               {vcsGit, "path/that/contains/a:colon/repo.git", false},
+               {vcsHg, "ssh://user@example.com/path/to/repo.hg", true},
+       }
+
+       for _, test := range tests {
+               secure := test.vcs.isSecure(test.url)
+               if secure != test.secure {
+                       t.Errorf("%s isSecure(%q) = %t; want %t", test.vcs, test.url, secure, test.secure)
+               }
+       }
+}