mirror of https://github.com/golang/go.git
cmd/go: mark ssh:// URLs as secure
Add tests for isSecure function. Change-Id: I49de9d2846b75d4c7be745484f85d351a6fd851d Reviewed-on: https://go-review.googlesource.com/11514 Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
parent
3290e9c145
commit
c218a075be
|
|
@ -46,6 +46,7 @@ var isSecureScheme = map[string]bool{
|
||||||
"git+ssh": true,
|
"git+ssh": true,
|
||||||
"bzr+ssh": true,
|
"bzr+ssh": true,
|
||||||
"svn+ssh": true,
|
"svn+ssh": true,
|
||||||
|
"ssh": true,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *vcsCmd) isSecure(repo string) bool {
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue