mirror of
https://github.com/netbirdio/netbird.git
synced 2026-05-03 23:56:38 +00:00
update regex and tests
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user