diff --git a/internal/registry/config.go b/internal/registry/config.go index 6abc299be..fab9e8ab5 100644 --- a/internal/registry/config.go +++ b/internal/registry/config.go @@ -105,10 +105,6 @@ func (config *serviceConfig) loadInsecureRegistries(registries []string) error { skip: for _, r := range registries { - // validate insecure registry - if _, err := ValidateIndexName(r); err != nil { - return err - } if scheme, host, ok := strings.Cut(r, "://"); ok { switch strings.ToLower(scheme) { case "http", "https": @@ -219,16 +215,6 @@ func isCIDRMatch(cidrs []*registry.NetIPNet, urlHost string) bool { return false } -// ValidateIndexName validates an index name. It is used by the daemon to -// validate the daemon configuration. -func ValidateIndexName(val string) (string, error) { - val = normalizeIndexName(val) - if strings.HasPrefix(val, "-") || strings.HasSuffix(val, "-") { - return "", invalidParamf("invalid index name (%s). Cannot begin or end with a hyphen", val) - } - return val, nil -} - func normalizeIndexName(val string) string { if val == "index.docker.io" { return "docker.io" diff --git a/internal/registry/config_test.go b/internal/registry/config_test.go index f3d8b4c44..7e0838fe5 100644 --- a/internal/registry/config_test.go +++ b/internal/registry/config_test.go @@ -5,7 +5,6 @@ import ( cerrdefs "github.com/containerd/errdefs" "gotest.tools/v3/assert" - is "gotest.tools/v3/assert/cmp" ) func TestLoadInsecureRegistries(t *testing.T) { @@ -46,10 +45,6 @@ func TestLoadInsecureRegistries(t *testing.T) { registries: []string{"svn://myregistry.example.com"}, err: "insecure registry svn://myregistry.example.com should not contain '://'", }, - { - registries: []string{"-invalid-registry"}, - err: "Cannot begin or end with a hyphen", - }, { registries: []string{`mytest-.com`}, err: `insecure registry mytest-.com is not valid: invalid host "mytest-.com"`, @@ -96,63 +91,3 @@ func TestLoadInsecureRegistries(t *testing.T) { } } } - -func TestValidateIndexName(t *testing.T) { - valid := []struct { - index string - expect string - }{ - { - index: "index.docker.io", - expect: "docker.io", - }, - { - index: "example.com", - expect: "example.com", - }, - { - index: "127.0.0.1:8080", - expect: "127.0.0.1:8080", - }, - { - index: "mytest-1.com", - expect: "mytest-1.com", - }, - { - index: "mirror-1.example.com/v1/?q=foo", - expect: "mirror-1.example.com/v1/?q=foo", - }, - } - - for _, testCase := range valid { - result, err := ValidateIndexName(testCase.index) - if assert.Check(t, err) { - assert.Check(t, is.Equal(testCase.expect, result)) - } - } -} - -func TestValidateIndexNameWithError(t *testing.T) { - invalid := []struct { - index string - err string - }{ - { - index: "docker.io-", - err: "invalid index name (docker.io-). Cannot begin or end with a hyphen", - }, - { - index: "-example.com", - err: "invalid index name (-example.com). Cannot begin or end with a hyphen", - }, - { - index: "mirror-1.example.com/v1/?q=foo-", - err: "invalid index name (mirror-1.example.com/v1/?q=foo-). Cannot begin or end with a hyphen", - }, - } - for _, testCase := range invalid { - _, err := ValidateIndexName(testCase.index) - assert.Check(t, is.Error(err, testCase.err)) - assert.Check(t, cerrdefs.IsInvalidArgument(err)) - } -}