mirror of
https://github.com/netbirdio/netbird.git
synced 2025-06-20 17:58:02 +02:00
[management] Extend nameserver match domain validation (#3864)
* Enhance match domain validation logic and add test cases Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com> * remove the leading dot and root dot support ns regex Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com> * Remove support for wildcard ns match domain Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com> --------- Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
This commit is contained in:
parent
24f932b2ce
commit
2a89d6e47a
@ -18,7 +18,9 @@ import (
|
|||||||
"github.com/netbirdio/netbird/management/server/types"
|
"github.com/netbirdio/netbird/management/server/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
const domainPattern = `^(?i)[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,}$`
|
const domainPattern = `^(?i)[a-z0-9]+([\-\.]{1}[a-z0-9]+)*[*.a-z]{1,}$`
|
||||||
|
|
||||||
|
var invalidDomainName = errors.New("invalid domain name")
|
||||||
|
|
||||||
// GetNameServerGroup gets a nameserver group object from account and nameserver group IDs
|
// GetNameServerGroup gets a nameserver group object from account and nameserver group IDs
|
||||||
func (am *DefaultAccountManager) GetNameServerGroup(ctx context.Context, accountID, userID, nsGroupID string) (*nbdns.NameServerGroup, error) {
|
func (am *DefaultAccountManager) GetNameServerGroup(ctx context.Context, accountID, userID, nsGroupID string) (*nbdns.NameServerGroup, error) {
|
||||||
@ -319,13 +321,9 @@ func validateDomain(domain string) error {
|
|||||||
return errors.New("domain should consists of only letters, numbers, and hyphens with no leading, trailing hyphens, or spaces")
|
return errors.New("domain should consists of only letters, numbers, and hyphens with no leading, trailing hyphens, or spaces")
|
||||||
}
|
}
|
||||||
|
|
||||||
labels, valid := dns.IsDomainName(domain)
|
_, valid := dns.IsDomainName(domain)
|
||||||
if !valid {
|
if !valid {
|
||||||
return errors.New("invalid domain name")
|
return invalidDomainName
|
||||||
}
|
|
||||||
|
|
||||||
if labels < 2 {
|
|
||||||
return errors.New("domain should consists of a minimum of two labels")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -899,13 +899,33 @@ func TestValidateDomain(t *testing.T) {
|
|||||||
errFunc: require.NoError,
|
errFunc: require.NoError,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Invalid domain name with double hyphen",
|
name: "Valid domain name with only one label",
|
||||||
domain: "test--example.com",
|
domain: "example",
|
||||||
|
errFunc: require.NoError,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Valid domain name with trailing dot",
|
||||||
|
domain: "example.",
|
||||||
|
errFunc: require.NoError,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Invalid wildcard domain name",
|
||||||
|
domain: "*.example",
|
||||||
errFunc: require.Error,
|
errFunc: require.Error,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Invalid domain name with only one label",
|
name: "Invalid domain name with leading dot",
|
||||||
domain: "com",
|
domain: ".com",
|
||||||
|
errFunc: require.Error,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Invalid domain name with dot only",
|
||||||
|
domain: ".",
|
||||||
|
errFunc: require.Error,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Invalid domain name with double hyphen",
|
||||||
|
domain: "test--example.com",
|
||||||
errFunc: require.Error,
|
errFunc: require.Error,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user