Skip to content

Commit 46bc338

Browse files
Bryan C. Millsgopherbot
Bryan C. Mills
authored andcommitted
[release-branch.go1.20] cmd/go/internal/vcs: error out if the requested repo does not support a secure protocol
Updates #63845. Fixes #63972. Change-Id: If86d6b13d3b55877b35c087112bd76388c9404b8 Reviewed-on: https://go-review.googlesource.com/c/go/+/539321 Reviewed-by: Michael Matloob <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Roland Shoemaker <[email protected]> Auto-Submit: Bryan Mills <[email protected]> (cherry picked from commit be26ae1) Reviewed-on: https://go-review.googlesource.com/c/go/+/540335 Auto-Submit: Dmitri Shuralyov <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]>
1 parent e1dc209 commit 46bc338

File tree

2 files changed

+47
-6
lines changed

2 files changed

+47
-6
lines changed

src/cmd/go/internal/vcs/vcs.go

+19-6
Original file line numberDiff line numberDiff line change
@@ -1179,18 +1179,31 @@ func repoRootFromVCSPaths(importPath string, security web.SecurityMode, vcsPaths
11791179
var ok bool
11801180
repoURL, ok = interceptVCSTest(repo, vcs, security)
11811181
if !ok {
1182-
scheme := vcs.Scheme[0] // default to first scheme
1183-
if vcs.PingCmd != "" {
1184-
// If we know how to test schemes, scan to find one.
1182+
scheme, err := func() (string, error) {
11851183
for _, s := range vcs.Scheme {
11861184
if security == web.SecureOnly && !vcs.isSecureScheme(s) {
11871185
continue
11881186
}
1189-
if vcs.Ping(s, repo) == nil {
1190-
scheme = s
1191-
break
1187+
1188+
// If we know how to ping URL schemes for this VCS,
1189+
// check that this repo works.
1190+
// Otherwise, default to the first scheme
1191+
// that meets the requested security level.
1192+
if vcs.PingCmd == "" {
1193+
return s, nil
1194+
}
1195+
if err := vcs.Ping(s, repo); err == nil {
1196+
return s, nil
11921197
}
11931198
}
1199+
securityFrag := ""
1200+
if security == web.SecureOnly {
1201+
securityFrag = "secure "
1202+
}
1203+
return "", fmt.Errorf("no %sprotocol found for repository", securityFrag)
1204+
}()
1205+
if err != nil {
1206+
return nil, err
11941207
}
11951208
repoURL = scheme + "://" + repo
11961209
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Regression test for https://go.dev/issue/63845:
2+
# If 'git ls-remote' fails for all secure protocols,
3+
# we should fail instead of falling back to an arbitrary protocol.
4+
#
5+
# Note that this test does not use the local vcweb test server
6+
# (vcs-test.golang.org), because the hook for redirecting to that
7+
# server bypasses the "ping to determine protocol" logic
8+
# in cmd/go/internal/vcs.
9+
10+
[!net] skip
11+
[!git] skip
12+
[short] skip 'tries to access a nonexistent external Git repo'
13+
14+
env GOPRIVATE=golang.org
15+
env CURLOPT_TIMEOUT_MS=100
16+
env GIT_SSH_COMMAND=false
17+
18+
! go get -x golang.org/nonexist.git@latest
19+
stderr '^git ls-remote https://golang.org/nonexist$'
20+
stderr '^git ls-remote git\+ssh://golang.org/nonexist'
21+
stderr '^git ls-remote ssh://golang.org/nonexist$'
22+
! stderr 'git://'
23+
stderr '^go: golang.org/nonexist.git@latest: no secure protocol found for repository$'
24+
25+
-- go.mod --
26+
module example
27+
28+
go 1.19

0 commit comments

Comments
 (0)