From a359c4ee2f5aa6eae537cfd89eba749177881eeb Mon Sep 17 00:00:00 2001 From: James Bardin Date: Tue, 17 Oct 2017 17:25:46 -0400 Subject: [PATCH] check the registry detector before local files Breaking change for 0.11. Local files were checked first to avoid the possibility of breaking a module with a local source that looked like a registry ID. Now we can enfore that any source iwth the pattern "namespace/identifier/provider" must be a registry module. --- config/module/get.go | 2 +- config/module/get_test.go | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/config/module/get.go b/config/module/get.go index 8d32d154e9..3e666f7a64 100644 --- a/config/module/get.go +++ b/config/module/get.go @@ -87,8 +87,8 @@ var detectors = []getter.Detector{ new(getter.GitHubDetector), new(getter.BitBucketDetector), new(getter.S3Detector), - new(localDetector), new(registryDetector), + new(localDetector), } // these prefixes can't be registry IDs diff --git a/config/module/get_test.go b/config/module/get_test.go index 6f001512f7..19dd09b8cd 100644 --- a/config/module/get_test.go +++ b/config/module/get_test.go @@ -39,6 +39,10 @@ var testMods = map[string]testMod{ location: "test-fixtures/registry-tar-subdir/foo.tgz//*?archive=tar.gz", version: "0.1.2", }, + "exists-in-registry/identifier/provider": { + location: "file:///registry/exists", + version: "0.2.0", + }, } func latestVersion(versions []string) string { @@ -65,7 +69,7 @@ func mockRegistry() *httptest.Server { http.StripPrefix("/v1/modules/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { p := strings.TrimLeft(r.URL.Path, "/") // handle download request - download := regexp.MustCompile(`^(\w+/\w+/\w+)/download$`) + download := regexp.MustCompile(`^([-a-z]+/\w+/\w+)/download$`) // download lookup matches := download.FindStringSubmatch(p) @@ -189,8 +193,8 @@ func TestDetectors(t *testing.T) { new(getter.GitHubDetector), new(getter.BitBucketDetector), new(getter.S3Detector), - new(localDetector), regDetector, + new(localDetector), } for _, tc := range []struct { @@ -239,13 +243,22 @@ func TestDetectors(t *testing.T) { err: true, }, - // make sure a local module that looks like a registry id takes precedence + // make sure a local module that looks like a registry id can be found { source: "namespace/identifier/provider", fixture: "discover-subdirs", // this should be found locally location: "file://" + filepath.Join(wd, fixtureDir, "discover-subdirs/namespace/identifier/provider"), }, + + // The registry takes precedence over local paths if they don't start + // with a relative or absolute path + { + source: "exists-in-registry/identifier/provider", + fixture: "discover-registry-local", + // registry should take precidence + location: "file:///registry/exists", + }, } { t.Run(tc.source, func(t *testing.T) {