mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-27 23:09:08 +01:00
@@ -14,12 +14,14 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/mock/gomock"
|
"github.com/golang/mock/gomock"
|
||||||
"github.com/netbirdio/netbird/management/server/idp"
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
||||||
|
|
||||||
|
"github.com/netbirdio/netbird/management/domain"
|
||||||
|
"github.com/netbirdio/netbird/management/server/idp"
|
||||||
|
|
||||||
nbdns "github.com/netbirdio/netbird/dns"
|
nbdns "github.com/netbirdio/netbird/dns"
|
||||||
nbAccount "github.com/netbirdio/netbird/management/server/account"
|
nbAccount "github.com/netbirdio/netbird/management/server/account"
|
||||||
"github.com/netbirdio/netbird/management/server/activity"
|
"github.com/netbirdio/netbird/management/server/activity"
|
||||||
@@ -1688,7 +1690,7 @@ func TestAccount_Copy(t *testing.T) {
|
|||||||
NameServerGroups: map[string]*nbdns.NameServerGroup{
|
NameServerGroups: map[string]*nbdns.NameServerGroup{
|
||||||
"nsGroup1": {
|
"nsGroup1": {
|
||||||
ID: "nsGroup1",
|
ID: "nsGroup1",
|
||||||
Domains: []string{},
|
Domains: domain.List{},
|
||||||
Groups: []string{},
|
Groups: []string{},
|
||||||
NameServers: []nbdns.NameServer{},
|
NameServers: []nbdns.NameServer{},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
nbdns "github.com/netbirdio/netbird/dns"
|
nbdns "github.com/netbirdio/netbird/dns"
|
||||||
|
"github.com/netbirdio/netbird/management/domain"
|
||||||
"github.com/netbirdio/netbird/management/server/integrations/port_forwarding"
|
"github.com/netbirdio/netbird/management/server/integrations/port_forwarding"
|
||||||
"github.com/netbirdio/netbird/management/server/permissions"
|
"github.com/netbirdio/netbird/management/server/permissions"
|
||||||
"github.com/netbirdio/netbird/management/server/settings"
|
"github.com/netbirdio/netbird/management/server/settings"
|
||||||
@@ -367,7 +368,7 @@ func generateTestData(size int) nbdns.Config {
|
|||||||
config.NameServerGroups[i] = &nbdns.NameServerGroup{
|
config.NameServerGroups[i] = &nbdns.NameServerGroup{
|
||||||
ID: fmt.Sprintf("group%d", i),
|
ID: fmt.Sprintf("group%d", i),
|
||||||
Primary: i == 0,
|
Primary: i == 0,
|
||||||
Domains: []string{fmt.Sprintf("domain%d.com", i)},
|
Domains: domain.List{domain.Domain(fmt.Sprintf("domain%d.com", i))},
|
||||||
SearchDomainsEnabled: true,
|
SearchDomainsEnabled: true,
|
||||||
NameServers: []nbdns.NameServer{
|
NameServers: []nbdns.NameServer{
|
||||||
{
|
{
|
||||||
@@ -547,7 +548,7 @@ func TestDNSAccountPeersUpdate(t *testing.T) {
|
|||||||
Port: dns.DefaultDNSPort,
|
Port: dns.DefaultDNSPort,
|
||||||
}},
|
}},
|
||||||
[]string{"groupB"},
|
[]string{"groupB"},
|
||||||
true, []string{}, true, userID, false,
|
true, domain.List{}, true, userID, false,
|
||||||
)
|
)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
@@ -580,7 +581,7 @@ func TestDNSAccountPeersUpdate(t *testing.T) {
|
|||||||
Port: dns.DefaultDNSPort,
|
Port: dns.DefaultDNSPort,
|
||||||
}},
|
}},
|
||||||
[]string{"groupA"},
|
[]string{"groupA"},
|
||||||
true, []string{}, true, userID, false,
|
true, domain.List{}, true, userID, false,
|
||||||
)
|
)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ type MockAccountManager struct {
|
|||||||
GetPATFunc func(ctx context.Context, accountID string, initiatorUserID string, targetUserId string, tokenID string) (*types.PersonalAccessToken, error)
|
GetPATFunc func(ctx context.Context, accountID string, initiatorUserID string, targetUserId string, tokenID string) (*types.PersonalAccessToken, error)
|
||||||
GetAllPATsFunc func(ctx context.Context, accountID string, initiatorUserID string, targetUserId string) ([]*types.PersonalAccessToken, error)
|
GetAllPATsFunc func(ctx context.Context, accountID string, initiatorUserID string, targetUserId string) ([]*types.PersonalAccessToken, error)
|
||||||
GetNameServerGroupFunc func(ctx context.Context, accountID, userID, nsGroupID string) (*nbdns.NameServerGroup, error)
|
GetNameServerGroupFunc func(ctx context.Context, accountID, userID, nsGroupID string) (*nbdns.NameServerGroup, error)
|
||||||
CreateNameServerGroupFunc func(ctx context.Context, accountID string, name, description string, nameServerList []nbdns.NameServer, groups []string, primary bool, domains []string, enabled bool, userID string, searchDomainsEnabled bool) (*nbdns.NameServerGroup, error)
|
CreateNameServerGroupFunc func(ctx context.Context, accountID string, name, description string, nameServerList []nbdns.NameServer, groups []string, primary bool, domains domain.List, enabled bool, userID string, searchDomainsEnabled bool) (*nbdns.NameServerGroup, error)
|
||||||
SaveNameServerGroupFunc func(ctx context.Context, accountID, userID string, nsGroupToSave *nbdns.NameServerGroup) error
|
SaveNameServerGroupFunc func(ctx context.Context, accountID, userID string, nsGroupToSave *nbdns.NameServerGroup) error
|
||||||
DeleteNameServerGroupFunc func(ctx context.Context, accountID, nsGroupID, userID string) error
|
DeleteNameServerGroupFunc func(ctx context.Context, accountID, nsGroupID, userID string) error
|
||||||
ListNameServerGroupsFunc func(ctx context.Context, accountID string, userID string) ([]*nbdns.NameServerGroup, error)
|
ListNameServerGroupsFunc func(ctx context.Context, accountID string, userID string) ([]*nbdns.NameServerGroup, error)
|
||||||
@@ -566,7 +566,7 @@ func (am *MockAccountManager) GetNameServerGroup(ctx context.Context, accountID,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CreateNameServerGroup mocks CreateNameServerGroup of the AccountManager interface
|
// CreateNameServerGroup mocks CreateNameServerGroup of the AccountManager interface
|
||||||
func (am *MockAccountManager) CreateNameServerGroup(ctx context.Context, accountID string, name, description string, nameServerList []nbdns.NameServer, groups []string, primary bool, domains []string, enabled bool, userID string, searchDomainsEnabled bool) (*nbdns.NameServerGroup, error) {
|
func (am *MockAccountManager) CreateNameServerGroup(ctx context.Context, accountID string, name, description string, nameServerList []nbdns.NameServer, groups []string, primary bool, domains domain.List, enabled bool, userID string, searchDomainsEnabled bool) (*nbdns.NameServerGroup, error) {
|
||||||
if am.CreateNameServerGroupFunc != nil {
|
if am.CreateNameServerGroupFunc != nil {
|
||||||
return am.CreateNameServerGroupFunc(ctx, accountID, name, description, nameServerList, groups, primary, domains, enabled, userID, searchDomainsEnabled)
|
return am.CreateNameServerGroupFunc(ctx, accountID, name, description, nameServerList, groups, primary, domains, enabled, userID, searchDomainsEnabled)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
nbdns "github.com/netbirdio/netbird/dns"
|
nbdns "github.com/netbirdio/netbird/dns"
|
||||||
|
"github.com/netbirdio/netbird/management/domain"
|
||||||
"github.com/netbirdio/netbird/management/server/activity"
|
"github.com/netbirdio/netbird/management/server/activity"
|
||||||
"github.com/netbirdio/netbird/management/server/integrations/port_forwarding"
|
"github.com/netbirdio/netbird/management/server/integrations/port_forwarding"
|
||||||
nbpeer "github.com/netbirdio/netbird/management/server/peer"
|
nbpeer "github.com/netbirdio/netbird/management/server/peer"
|
||||||
@@ -41,7 +42,7 @@ func TestCreateNameServerGroup(t *testing.T) {
|
|||||||
groups []string
|
groups []string
|
||||||
nameServers []nbdns.NameServer
|
nameServers []nbdns.NameServer
|
||||||
primary bool
|
primary bool
|
||||||
domains []string
|
domains domain.List
|
||||||
searchDomains bool
|
searchDomains bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,7 +103,7 @@ func TestCreateNameServerGroup(t *testing.T) {
|
|||||||
description: "super",
|
description: "super",
|
||||||
groups: []string{group1ID},
|
groups: []string{group1ID},
|
||||||
primary: false,
|
primary: false,
|
||||||
domains: []string{validDomain},
|
domains: domain.List{validDomain},
|
||||||
nameServers: []nbdns.NameServer{
|
nameServers: []nbdns.NameServer{
|
||||||
{
|
{
|
||||||
IP: netip.MustParseAddr("1.1.1.1"),
|
IP: netip.MustParseAddr("1.1.1.1"),
|
||||||
@@ -123,7 +124,7 @@ func TestCreateNameServerGroup(t *testing.T) {
|
|||||||
Name: "super",
|
Name: "super",
|
||||||
Description: "super",
|
Description: "super",
|
||||||
Primary: false,
|
Primary: false,
|
||||||
Domains: []string{"example.com"},
|
Domains: domain.List{"example.com"},
|
||||||
Groups: []string{group1ID},
|
Groups: []string{group1ID},
|
||||||
NameServers: []nbdns.NameServer{
|
NameServers: []nbdns.NameServer{
|
||||||
{
|
{
|
||||||
@@ -360,7 +361,7 @@ func TestCreateNameServerGroup(t *testing.T) {
|
|||||||
name: "super",
|
name: "super",
|
||||||
description: "super",
|
description: "super",
|
||||||
groups: []string{group1ID},
|
groups: []string{group1ID},
|
||||||
domains: []string{invalidDomain},
|
domains: domain.List{invalidDomain},
|
||||||
nameServers: []nbdns.NameServer{
|
nameServers: []nbdns.NameServer{
|
||||||
{
|
{
|
||||||
IP: netip.MustParseAddr("1.1.1.1"),
|
IP: netip.MustParseAddr("1.1.1.1"),
|
||||||
@@ -447,8 +448,8 @@ func TestSaveNameServerGroup(t *testing.T) {
|
|||||||
validGroups := []string{group2ID}
|
validGroups := []string{group2ID}
|
||||||
invalidGroups := []string{"nonExisting"}
|
invalidGroups := []string{"nonExisting"}
|
||||||
disabledPrimary := false
|
disabledPrimary := false
|
||||||
validDomains := []string{validDomain}
|
validDomains := domain.List{validDomain}
|
||||||
invalidDomains := []string{invalidDomain}
|
invalidDomains := domain.List{invalidDomain}
|
||||||
|
|
||||||
validNameServerList := []nbdns.NameServer{
|
validNameServerList := []nbdns.NameServer{
|
||||||
{
|
{
|
||||||
@@ -491,7 +492,7 @@ func TestSaveNameServerGroup(t *testing.T) {
|
|||||||
newID *string
|
newID *string
|
||||||
newName *string
|
newName *string
|
||||||
newPrimary *bool
|
newPrimary *bool
|
||||||
newDomains []string
|
newDomains domain.List
|
||||||
newNSList []nbdns.NameServer
|
newNSList []nbdns.NameServer
|
||||||
newGroups []string
|
newGroups []string
|
||||||
skipCopying bool
|
skipCopying bool
|
||||||
@@ -908,6 +909,11 @@ func TestValidateDomain(t *testing.T) {
|
|||||||
domain: "example.",
|
domain: "example.",
|
||||||
errFunc: require.NoError,
|
errFunc: require.NoError,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "Valid domain name with double hyphen",
|
||||||
|
domain: "xn--bcher-kva.com",
|
||||||
|
errFunc: require.NoError,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "Invalid wildcard domain name",
|
name: "Invalid wildcard domain name",
|
||||||
domain: "*.example",
|
domain: "*.example",
|
||||||
@@ -924,8 +930,8 @@ func TestValidateDomain(t *testing.T) {
|
|||||||
errFunc: require.Error,
|
errFunc: require.Error,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Invalid domain name with double hyphen",
|
name: "Invalid domain name with double dot",
|
||||||
domain: "test--example.com",
|
domain: "example..com",
|
||||||
errFunc: require.Error,
|
errFunc: require.Error,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -1009,7 +1015,7 @@ func TestNameServerAccountPeersUpdate(t *testing.T) {
|
|||||||
Port: nbdns.DefaultDNSPort,
|
Port: nbdns.DefaultDNSPort,
|
||||||
}},
|
}},
|
||||||
[]string{"groupA"},
|
[]string{"groupA"},
|
||||||
true, []string{}, true, userID, false,
|
true, domain.List{}, true, userID, false,
|
||||||
)
|
)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
@@ -1054,7 +1060,7 @@ func TestNameServerAccountPeersUpdate(t *testing.T) {
|
|||||||
Port: nbdns.DefaultDNSPort,
|
Port: nbdns.DefaultDNSPort,
|
||||||
}},
|
}},
|
||||||
[]string{"groupB"},
|
[]string{"groupB"},
|
||||||
true, []string{}, true, userID, false,
|
true, domain.List{}, true, userID, false,
|
||||||
)
|
)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
|||||||
@@ -1108,7 +1108,7 @@ func TestToSyncResponse(t *testing.T) {
|
|||||||
Port: nbdns.DefaultDNSPort,
|
Port: nbdns.DefaultDNSPort,
|
||||||
}},
|
}},
|
||||||
Primary: true,
|
Primary: true,
|
||||||
Domains: []string{"example.com"},
|
Domains: domain.List{"example.com"},
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
SearchDomainsEnabled: true,
|
SearchDomainsEnabled: true,
|
||||||
},
|
},
|
||||||
@@ -1121,7 +1121,7 @@ func TestToSyncResponse(t *testing.T) {
|
|||||||
}},
|
}},
|
||||||
Groups: []string{"group1"},
|
Groups: []string{"group1"},
|
||||||
Primary: true,
|
Primary: true,
|
||||||
Domains: []string{"example.com"},
|
Domains: domain.List{"example.com"},
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
SearchDomainsEnabled: true,
|
SearchDomainsEnabled: true,
|
||||||
},
|
},
|
||||||
@@ -1995,7 +1995,7 @@ func TestPeerAccountPeersUpdate(t *testing.T) {
|
|||||||
Port: nbdns.DefaultDNSPort,
|
Port: nbdns.DefaultDNSPort,
|
||||||
}},
|
}},
|
||||||
[]string{"groupC"},
|
[]string{"groupC"},
|
||||||
true, []string{}, true, userID, false,
|
true, domain.List{}, true, userID, false,
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user