Commit c218a075 authored by Ross Light's avatar Ross Light Committed by Russ Cox

cmd/go: mark ssh:// URLs as secure

Add tests for isSecure function.

Change-Id: I49de9d2846b75d4c7be745484f85d351a6fd851d
Reviewed-on: https://go-review.googlesource.com/11514Reviewed-by: default avatarRuss Cox <rsc@golang.org>
parent 3290e9c1
......@@ -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 {
......
......@@ -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)
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment