Skip to content

Commit bf80e3b

Browse files
committed
cmd/go: fix module get -insecure
Need to actually use the flag for it to take effect. Fixes #27049. Change-Id: I57227b45f46f9dd67ecbf87c11bb2d08124bcfa0 Reviewed-on: https://go-review.googlesource.com/129801 Run-TryBot: Russ Cox <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent c5046bc commit bf80e3b

File tree

2 files changed

+42
-15
lines changed

2 files changed

+42
-15
lines changed

src/cmd/go/go_test.go

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3532,24 +3532,43 @@ func TestImportLocal(t *testing.T) {
35323532
}
35333533

35343534
func TestGoGetInsecure(t *testing.T) {
3535-
testenv.MustHaveExternalNetwork(t)
3535+
test := func(t *testing.T, modules bool) {
3536+
testenv.MustHaveExternalNetwork(t)
35363537

3537-
tg := testgo(t)
3538-
defer tg.cleanup()
3539-
tg.makeTempdir()
3540-
tg.setenv("GOPATH", tg.path("."))
3541-
tg.failSSH()
3538+
tg := testgo(t)
3539+
defer tg.cleanup()
3540+
tg.makeTempdir()
3541+
tg.failSSH()
35423542

3543-
const repo = "insecure.go-get-issue-15410.appspot.com/pkg/p"
3543+
if modules {
3544+
tg.setenv("GOPATH", tg.path("gp"))
3545+
tg.tempFile("go.mod", "module m")
3546+
tg.cd(tg.path("."))
3547+
tg.setenv("GO111MODULE", "on")
3548+
} else {
3549+
tg.setenv("GOPATH", tg.path("."))
3550+
tg.setenv("GO111MODULE", "off")
3551+
}
35443552

3545-
// Try go get -d of HTTP-only repo (should fail).
3546-
tg.runFail("get", "-d", repo)
3553+
const repo = "insecure.go-get-issue-15410.appspot.com/pkg/p"
35473554

3548-
// Try again with -insecure (should succeed).
3549-
tg.run("get", "-d", "-insecure", repo)
3555+
// Try go get -d of HTTP-only repo (should fail).
3556+
tg.runFail("get", "-d", repo)
3557+
3558+
// Try again with -insecure (should succeed).
3559+
tg.run("get", "-d", "-insecure", repo)
3560+
3561+
// Try updating without -insecure (should fail).
3562+
tg.runFail("get", "-d", "-u", "-f", repo)
3563+
3564+
if modules {
3565+
tg.run("list", "-m", "...")
3566+
tg.grepStdout("insecure.go-get-issue", "should find insecure module")
3567+
}
3568+
}
35503569

3551-
// Try updating without -insecure (should fail).
3552-
tg.runFail("get", "-d", "-u", "-f", repo)
3570+
t.Run("gopath", func(t *testing.T) { test(t, false) })
3571+
t.Run("modules", func(t *testing.T) { test(t, true) })
35533572
}
35543573

35553574
func TestGoGetUpdateInsecure(t *testing.T) {

src/cmd/go/internal/modfetch/repo.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,11 @@ func lookup(path string) (r Repo, err error) {
216216
return lookupProxy(path)
217217
}
218218

219-
rr, err := get.RepoRootForImportPath(path, get.PreferMod, web.Secure)
219+
security := web.Secure
220+
if get.Insecure {
221+
security = web.Insecure
222+
}
223+
rr, err := get.RepoRootForImportPath(path, get.PreferMod, security)
220224
if err != nil {
221225
// We don't know where to find code for a module with this path.
222226
return nil, err
@@ -257,7 +261,11 @@ func ImportRepoRev(path, rev string) (Repo, *RevInfo, error) {
257261
// Note: Because we are converting a code reference from a legacy
258262
// version control system, we ignore meta tags about modules
259263
// and use only direct source control entries (get.IgnoreMod).
260-
rr, err := get.RepoRootForImportPath(path, get.IgnoreMod, web.Secure)
264+
security := web.Secure
265+
if get.Insecure {
266+
security = web.Insecure
267+
}
268+
rr, err := get.RepoRootForImportPath(path, get.IgnoreMod, security)
261269
if err != nil {
262270
return nil, nil, err
263271
}

0 commit comments

Comments
 (0)