From c218a075beedef729307359969f8c76f410dac10 Mon Sep 17 00:00:00 2001 From: Ross Light Date: Thu, 25 Jun 2015 13:14:28 -0700 Subject: [PATCH] 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 --- src/cmd/go/vcs.go | 1 + src/cmd/go/vcs_test.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/cmd/go/vcs.go b/src/cmd/go/vcs.go index ea7dd1c1df..29433de541 100644 --- a/src/cmd/go/vcs.go +++ b/src/cmd/go/vcs.go @@ -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 { diff --git a/src/cmd/go/vcs_test.go b/src/cmd/go/vcs_test.go index a60a7ac1a0..44f7ea8418 100644 --- a/src/cmd/go/vcs_test.go +++ b/src/cmd/go/vcs_test.go @@ -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) + } + } +} -- 2.48.1