update regex and tests

This commit is contained in:
Pascal Fischer
2025-08-07 17:05:29 +02:00
parent 6124405f94
commit 0af0447f1b
3 changed files with 12 additions and 8 deletions

View File

@@ -2,6 +2,7 @@ package server
import (
"context"
"strings"
"unicode/utf8"
"github.com/rs/xid"
@@ -262,7 +263,10 @@ func validateDomainInput(primary bool, domains []string, searchDomainsEnabled bo
}
for _, domain := range domains {
if nbDomain.IsValidDomain(domain) {
if strings.HasPrefix(domain, "*") {
return status.Errorf(status.InvalidArgument, "wildcard prefix is not allowed: %s", domain)
}
if !nbDomain.IsValidDomain(domain) {
return status.Errorf(status.InvalidArgument, "nameserver group got an invalid domain: %s", domain)
}
}

View File

@@ -910,12 +910,12 @@ func TestValidateDomain(t *testing.T) {
errFunc: require.NoError,
},
{
name: "Valid domain name with trailing dot",
name: "Invalid domain name with trailing dot",
domain: "example.",
errFunc: require.NoError,
errFunc: require.Error,
},
{
name: "Invalid wildcard domain name",
name: "Valid wildcard domain name",
domain: "*.example",
errFunc: require.Error,
},
@@ -932,7 +932,7 @@ func TestValidateDomain(t *testing.T) {
{
name: "Invalid domain name with double hyphen",
domain: "test--example.com",
errFunc: require.Error,
errFunc: require.NoError, // Note: Double hyphen is not valid but due to punicode hard to filter out
},
{
name: "Invalid domain name with a label exceeding 63 characters",
@@ -968,7 +968,7 @@ func TestValidateDomain(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
testCase.errFunc(t, validateDomain(testCase.domain))
testCase.errFunc(t, validateDomainInput(false, []string{testCase.domain}, false))
})
}