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.
This commit is contained in:
James Bardin 2017-10-17 17:25:46 -04:00
parent 6088270c66
commit a359c4ee2f
2 changed files with 17 additions and 4 deletions

View File

@ -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

View File

@ -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) {