Merge pull request #90172 from nak3/add-IsDNS1123Label

Add DNS1123Label validation to IsFullyQualifiedDomainName() func
This commit is contained in:
Kubernetes Prow Robot 2020-06-28 04:50:13 -07:00 committed by GitHub
commit aadaa5d6a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -106,6 +106,11 @@ func IsFullyQualifiedDomainName(fldPath *field.Path, name string) field.ErrorLis
if len(strings.Split(name, ".")) < 2 {
return append(allErrors, field.Invalid(fldPath, name, "should be a domain with at least two segments separated by dots"))
}
for _, label := range strings.Split(name, ".") {
if errs := IsDNS1123Label(label); len(errs) > 0 {
return append(allErrors, field.Invalid(fldPath, label, strings.Join(errs, ",")))
}
}
return allErrors
}

View File

@ -557,7 +557,8 @@ func TestIsFullyQualifiedDomainName(t *testing.T) {
"bbc.co.uk",
"10.0.0.1", // DNS labels can start with numbers and there is no requirement for letters.
"hyphens-are-good.k8s.io",
strings.Repeat("a", 246) + ".k8s.io",
strings.Repeat("a", 63) + ".k8s.io",
strings.Repeat("a", 63) + "." + strings.Repeat("b", 63) + "." + strings.Repeat("c", 63) + "." + strings.Repeat("d", 54) + ".k8s.io",
}
for _, val := range goodValues {
if err := IsFullyQualifiedDomainName(field.NewPath(""), val).ToAggregate(); err != nil {
@ -579,7 +580,8 @@ func TestIsFullyQualifiedDomainName(t *testing.T) {
"underscores_are_bad.k8s.io",
"foo@bar.example.com",
"http://foo.example.com",
strings.Repeat("a", 247) + ".k8s.io",
strings.Repeat("a", 64) + ".k8s.io",
strings.Repeat("a", 63) + "." + strings.Repeat("b", 63) + "." + strings.Repeat("c", 63) + "." + strings.Repeat("d", 55) + ".k8s.io",
}
for _, val := range badValues {
if err := IsFullyQualifiedDomainName(field.NewPath(""), val).ToAggregate(); err == nil {