]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/modfetch: halt proxy fallback if the proxy returns a non-404/410...
authorBryan C. Mills <bcmills@google.com>
Tue, 25 Jun 2019 21:13:21 +0000 (17:13 -0400)
committerBryan C. Mills <bcmills@google.com>
Wed, 26 Jun 2019 19:14:29 +0000 (19:14 +0000)
The @latest proxy endpoint is optional. If a proxy returns a 404 for
it, and returns an @v/list with no matching versions, then we should
allow module lookup to try other module paths. However, if the proxy
returns some other error (say, a 403 or 505), then the result of the
lookup is ambiguous, and we should report the actual error rather than
"no matching versions for query".

(This fix was prompted by discussion with Dmitri on CL 183619.)

Updates #32715
Updates #26334

Change-Id: I6d510a5ac24d48d9bc5037c3c747ac50695c663f
Reviewed-on: https://go-review.googlesource.com/c/go/+/183845
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
src/cmd/go/internal/modfetch/proxy.go
src/cmd/go/testdata/script/mod_query_empty.txt

index 6049ccfd30a5bc26abf6140173e71aabbeb84d09..569ef3a57a60a39682d00c8a38b0c54113307cca 100644 (file)
@@ -345,7 +345,9 @@ func (p *proxyRepo) Stat(rev string) (*RevInfo, error) {
 func (p *proxyRepo) Latest() (*RevInfo, error) {
        data, err := p.getBytes("@latest")
        if err != nil {
-               // TODO return err if not 404
+               if !errors.Is(err, os.ErrNotExist) {
+                       return nil, p.versionError("", err)
+               }
                return p.latest()
        }
        info := new(RevInfo)
index 4e27c1ee5c8d8db6170c0f5df6b35656d9ac1780..4d8259b40f1a4be6efe05ab0fca35008be71b77d 100644 (file)
@@ -28,6 +28,20 @@ go list -m example.com/join/...
 ! stdout 'example.com/join/subpkg'
 stdout 'example.com/join v1.1.0'
 
+# If the proxy provides an empty @v/list but rejects @latest with
+# some other explicit error (for example, a "permission denied" error),
+# that error should be reported to the user (and override a successful
+# result for other possible module paths).
+#
+# Depending on how the specific platform enforces permissions, the 'go get' may
+# fail either due to the intended permission error or due to a parse error.
+# We accept either failure message.
+env GOPROXY=file:///$WORK/gatekeeper
+chmod 0000 $WORK/gatekeeper/example.com/join/subpkg/@latest
+cp go.mod.orig go.mod
+! go get -d example.com/join/subpkg
+stderr 'go get example.com/join/subpkg: module example.com/join/subpkg: (invalid character .+|reading file://.*/gatekeeper/example.com/join/subpkg/@latest: .+)'
+
 -- go.mod.orig --
 module example.com/othermodule
 go 1.13
@@ -50,3 +64,10 @@ v1.0.0-does-not-exist
 v1.1.0
 -- $WORK/notfound/example.com/join/@v/v1.1.0.info --
 {"Version": "v1.1.0"}
+-- $WORK/gatekeeper/example.com/join/subpkg/@v/list --
+-- $WORK/gatekeeper/example.com/join/subpkg/@latest --
+ERROR: Latest version is forbidden.
+-- $WORK/gatekeeper/example.com/join/@v/list --
+v1.1.0
+-- $WORK/gatekeeper/example.com/join/@v/v1.1.0.info --
+{"Version": "v1.1.0"}