Skip to content

Commit be26ae1

Browse files
Bryan C. Millsgopherbot
Bryan C. Mills
authored andcommitted
cmd/go/internal/vcs: error out if the requested repo does not support a secure protocol
Fixes #63845. Change-Id: If86d6b13d3b55877b35c087112bd76388c9404b8 Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest,gotip-windows-amd64-longtest 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]>
1 parent 17211b6 commit be26ae1

File tree

2 files changed

+47
-6
lines changed

2 files changed

+47
-6
lines changed

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,18 +1171,31 @@ func repoRootFromVCSPaths(importPath string, security web.SecurityMode, vcsPaths
11711171
var ok bool
11721172
repoURL, ok = interceptVCSTest(repo, vcs, security)
11731173
if !ok {
1174-
scheme := vcs.Scheme[0] // default to first scheme
1175-
if vcs.PingCmd != "" {
1176-
// If we know how to test schemes, scan to find one.
1174+
scheme, err := func() (string, error) {
11771175
for _, s := range vcs.Scheme {
11781176
if security == web.SecureOnly && !vcs.isSecureScheme(s) {
11791177
continue
11801178
}
1181-
if vcs.Ping(s, repo) == nil {
1182-
scheme = s
1183-
break
1179+
1180+
// If we know how to ping URL schemes for this VCS,
1181+
// check that this repo works.
1182+
// Otherwise, default to the first scheme
1183+
// that meets the requested security level.
1184+
if vcs.PingCmd == "" {
1185+
return s, nil
1186+
}
1187+
if err := vcs.Ping(s, repo); err == nil {
1188+
return s, nil
11841189
}
11851190
}
1191+
securityFrag := ""
1192+
if security == web.SecureOnly {
1193+
securityFrag = "secure "
1194+
}
1195+
return "", fmt.Errorf("no %sprotocol found for repository", securityFrag)
1196+
}()
1197+
if err != nil {
1198+
return nil, err
11861199
}
11871200
repoURL = scheme + "://" + repo
11881201
}
Lines changed: 28 additions & 0 deletions
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:golang.org] 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)