Skip to content

Commit

Permalink
Use validate.Host to check for a valid hostname when the canonical ch…
Browse files Browse the repository at this point in the history
…eck fails

Return a more verbose invalid response for a bad host value
  • Loading branch information
kirankt committed Nov 16, 2021
1 parent 2c231ed commit 550364c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions pkg/types/validation/installconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,9 +566,14 @@ func validateNamedRepository(r string) error {
// in an error. Instead we will check whether the input is
// a valid hostname as a workaround.
if err == dockerref.ErrNameNotCanonical {
_, err := url.ParseRequestURI(r)
// If the hostname string contains a port, lets attempt
// to split them
host, _, err := net.SplitHostPort(r)
if err != nil {
return fmt.Errorf("the repository provided is invalid")
host = r
}
if err = validate.Host(host); err != nil {
return errors.Wrap(err, "the repository provided is invalid")
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/types/validation/installconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ func TestValidateInstallConfig(t *testing.T) {
}}
return c
}(),
expectedError: `^imageContentSources\[0\]\.source: Invalid value: "ocp/release-x\.y": the repository provided is invalid$`,
expectedError: `^imageContentSources\[0\]\.source: Invalid value: "ocp/release-x\.y": the repository provided is invalid: a lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, \'\-\' or \'\.\', and must start and end with an alphanumeric character \(e.g. \'example\.com\', regex used for validation is \'\[a\-z0\-9\]\(\[\-a\-z0\-9\]\*\[a\-z0\-9\]\)\?\(\\\.\[a\-z0\-9\]\(\[\-a\-z0\-9\]\*\[a\-z0\-9\]\)\?\)\*\'\)`,
},
{
name: "release image source's mirror is not valid",
Expand All @@ -1104,7 +1104,7 @@ func TestValidateInstallConfig(t *testing.T) {
}}
return c
}(),
expectedError: `^imageContentSources\[0\]\.mirrors\[0\]: Invalid value: "ocp/openshift-x.y": the repository provided is invalid$`,
expectedError: `^imageContentSources\[0\]\.mirrors\[0\]: Invalid value: "ocp/openshift-x\.y": the repository provided is invalid: a lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, \'\-\' or \'\.\', and must start and end with an alphanumeric character \(e.g. \'example\.com\', regex used for validation is \'\[a\-z0\-9\]\(\[\-a\-z0\-9\]\*\[a\-z0\-9\]\)\?\(\\\.\[a\-z0\-9\]\(\[\-a\-z0\-9\]\*\[a\-z0\-9\]\)\?\)\*\'\)`,
},
{
name: "release image source's mirror is valid",
Expand Down

0 comments on commit 550364c

Please sign in to comment.