Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MGMT-15886: Fix domain validation #5801

Merged
merged 1 commit into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/validations/validations.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
)

const (
baseDomainRegex = `^[a-z\d]+[\-]*[a-z\d]+$`
dnsNameRegex = `^([a-z\d]([\-]*[a-z\d]+)*\.)+[a-z\d]+[\-]*[a-z\d]+$`
baseDomainRegex = `^[a-z]([\-]*[a-z\d]+)+$`
dnsNameRegex = `^([a-z]([\-]*[a-z\d]+)*\.)+[a-z\d]+([\-]*[a-z\d]+)+$`
wildCardDomainRegex = `^(validateNoWildcardDNS\.).+\.?$`
hostnameRegex = `^[a-z0-9][a-z0-9\-\.]{0,61}[a-z0-9]$`
installerArgsValuesRegex = `^[A-Za-z0-9@!#$%*()_+-=//.,";':{}\[\]]+$`
Expand Down
36 changes: 16 additions & 20 deletions pkg/validations/validations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,6 @@ var _ = Describe("dns name", func() {
domainName: fqnHugeDomain,
valid: false,
},
{
domainName: "a.com",
valid: true,
},
{
domainName: "a",
valid: false,
Expand All @@ -200,24 +196,32 @@ var _ = Describe("dns name", func() {
domainName: "a-",
valid: false,
},
{
domainName: "co",
valid: true,
},
{
domainName: "1c",
valid: true,
valid: false,
},
{
domainName: "1-c",
valid: true,
valid: false,
},
{
domainName: "1--c",
valid: false,
},
{
domainName: "a.c",
valid: false,
},
{
domainName: "aaa.c",
valid: false,
},
{
domainName: "co",
valid: true,
},
{
domainName: "aaa",
domainName: "a.com",
valid: true,
},
{
Expand All @@ -242,7 +246,7 @@ var _ = Describe("dns name", func() {
},
{
domainName: "0-example.com0",
valid: true,
valid: false,
},
{
domainName: "example-example-example.com",
Expand Down Expand Up @@ -272,14 +276,6 @@ var _ = Describe("dns name", func() {
domainName: "validateNoWildcardDNS.test.com.",
valid: true,
},
{
domainName: "a.c",
valid: false,
},
{
domainName: "aaa.c",
valid: false,
},
}
for _, t := range tests {
t := t
Expand Down
10 changes: 5 additions & 5 deletions subsystem/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,11 @@ var _ = Describe("Validate BaseDNSDomain when creating a cluster", func() {
BaseDNSDomain: "-example.com",
ShouldThrow: true,
},
{
It: "V2RegisterCluster should throw an error. BaseDNSDomain='1-example.com', Illegal first character in domain name",
BaseDNSDomain: "1-example.com",
ShouldThrow: true,
},
{
It: "V2RegisterCluster should not throw an error. BaseDNSDomain='example.com', valid DNS",
BaseDNSDomain: "example.com",
Expand All @@ -1049,11 +1054,6 @@ var _ = Describe("Validate BaseDNSDomain when creating a cluster", func() {
BaseDNSDomain: "exam--ple.com",
ShouldThrow: false,
},
{
It: "V2RegisterCluster should not throw an error. BaseDNSDomain='1-example.com', valid DNS",
BaseDNSDomain: "1-example.com",
ShouldThrow: false,
},
{
It: "V2RegisterCluster should not throw an error. BaseDNSDomain='example.com1', valid DNS",
BaseDNSDomain: "example.com1",
Expand Down