Improve "invalid reference" error message
Use the same error message as is used in docker/reference/reference.go to provide slightly more information about the error. This change tests if the reference passes after lowercasing its characters, to determine if the reference was invalid due to it containing uppercase characters. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
5e8d18f615
commit
744ae974a5
2 changed files with 26 additions and 1 deletions
|
@ -24,6 +24,7 @@ package reference
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/docker/distribution/digest"
|
"github.com/docker/distribution/digest"
|
||||||
)
|
)
|
||||||
|
@ -43,6 +44,9 @@ var (
|
||||||
// ErrDigestInvalidFormat represents an error while trying to parse a string as a tag.
|
// ErrDigestInvalidFormat represents an error while trying to parse a string as a tag.
|
||||||
ErrDigestInvalidFormat = errors.New("invalid digest format")
|
ErrDigestInvalidFormat = errors.New("invalid digest format")
|
||||||
|
|
||||||
|
// ErrNameContainsUppercase is returned for invalid repository names that contain uppercase characters.
|
||||||
|
ErrNameContainsUppercase = errors.New("repository name must be lowercase")
|
||||||
|
|
||||||
// ErrNameEmpty is returned for empty, invalid repository names.
|
// ErrNameEmpty is returned for empty, invalid repository names.
|
||||||
ErrNameEmpty = errors.New("repository name must have at least one component")
|
ErrNameEmpty = errors.New("repository name must have at least one component")
|
||||||
|
|
||||||
|
@ -149,7 +153,9 @@ func Parse(s string) (Reference, error) {
|
||||||
if s == "" {
|
if s == "" {
|
||||||
return nil, ErrNameEmpty
|
return nil, ErrNameEmpty
|
||||||
}
|
}
|
||||||
// TODO(dmcgowan): Provide more specific and helpful error
|
if ReferenceRegexp.FindStringSubmatch(strings.ToLower(s)) != nil {
|
||||||
|
return nil, ErrNameContainsUppercase
|
||||||
|
}
|
||||||
return nil, ErrReferenceInvalidFormat
|
return nil, ErrReferenceInvalidFormat
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -95,6 +95,25 @@ func TestReferenceParse(t *testing.T) {
|
||||||
input: "validname@invaliddigest:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
|
input: "validname@invaliddigest:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
|
||||||
err: digest.ErrDigestUnsupported,
|
err: digest.ErrDigestUnsupported,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
input: "Uppercase:tag",
|
||||||
|
err: ErrNameContainsUppercase,
|
||||||
|
},
|
||||||
|
// FIXME "Uppercase" is incorrectly handled as a domain-name here, therefore passes.
|
||||||
|
// See https://github.com/docker/distribution/pull/1778, and https://github.com/docker/docker/pull/20175
|
||||||
|
//{
|
||||||
|
// input: "Uppercase/lowercase:tag",
|
||||||
|
// err: ErrNameContainsUppercase,
|
||||||
|
//},
|
||||||
|
{
|
||||||
|
input: "test:5000/Uppercase/lowercase:tag",
|
||||||
|
err: ErrNameContainsUppercase,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: "lowercase:Uppercase",
|
||||||
|
repository: "lowercase",
|
||||||
|
tag: "Uppercase",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
input: strings.Repeat("a/", 128) + "a:tag",
|
input: strings.Repeat("a/", 128) + "a:tag",
|
||||||
err: ErrNameTooLong,
|
err: ErrNameTooLong,
|
||||||
|
|
Loading…
Reference in a new issue