mirror of
https://github.com/netbirdio/netbird.git
synced 2025-06-28 21:51:40 +02:00
Fix tests
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
This commit is contained in:
parent
0c0fd380bd
commit
2d7f08c609
@ -500,8 +500,7 @@ func TestGroupAccountPeersUpdate(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// adding a group to policy
|
// adding a group to policy
|
||||||
err = manager.SavePolicy(context.Background(), account.Id, userID, &Policy{
|
_, err = manager.SavePolicy(context.Background(), account.Id, userID, &Policy{
|
||||||
ID: "policy",
|
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
Rules: []*PolicyRule{
|
Rules: []*PolicyRule{
|
||||||
{
|
{
|
||||||
@ -512,7 +511,7 @@ func TestGroupAccountPeersUpdate(t *testing.T) {
|
|||||||
Action: PolicyTrafficActionAccept,
|
Action: PolicyTrafficActionAccept,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, false)
|
})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// Saving a group linked to policy should update account peers and send peer update
|
// Saving a group linked to policy should update account peers and send peer update
|
||||||
|
@ -38,12 +38,12 @@ func initPoliciesTestData(policies ...*server.Policy) *Policies {
|
|||||||
}
|
}
|
||||||
return policy, nil
|
return policy, nil
|
||||||
},
|
},
|
||||||
SavePolicyFunc: func(_ context.Context, _, _ string, policy *server.Policy, _ bool) error {
|
SavePolicyFunc: func(_ context.Context, _, _ string, policy *server.Policy) (*server.Policy, error) {
|
||||||
if !strings.HasPrefix(policy.ID, "id-") {
|
if !strings.HasPrefix(policy.ID, "id-") {
|
||||||
policy.ID = "id-was-set"
|
policy.ID = "id-was-set"
|
||||||
policy.Rules[0].ID = "id-was-set"
|
policy.Rules[0].ID = "id-was-set"
|
||||||
}
|
}
|
||||||
return nil
|
return policy, nil
|
||||||
},
|
},
|
||||||
GetAllGroupsFunc: func(ctx context.Context, accountID, userID string) ([]*nbgroup.Group, error) {
|
GetAllGroupsFunc: func(ctx context.Context, accountID, userID string) ([]*nbgroup.Group, error) {
|
||||||
return []*nbgroup.Group{{ID: "F"}, {ID: "G"}}, nil
|
return []*nbgroup.Group{{ID: "F"}, {ID: "G"}}, nil
|
||||||
|
@ -283,14 +283,12 @@ func TestAccountManager_GetNetworkMapWithPolicy(t *testing.T) {
|
|||||||
var (
|
var (
|
||||||
group1 nbgroup.Group
|
group1 nbgroup.Group
|
||||||
group2 nbgroup.Group
|
group2 nbgroup.Group
|
||||||
policy Policy
|
|
||||||
)
|
)
|
||||||
|
|
||||||
group1.ID = xid.New().String()
|
group1.ID = xid.New().String()
|
||||||
group2.ID = xid.New().String()
|
group2.ID = xid.New().String()
|
||||||
group1.Name = "src"
|
group1.Name = "src"
|
||||||
group2.Name = "dst"
|
group2.Name = "dst"
|
||||||
policy.ID = xid.New().String()
|
|
||||||
group1.Peers = append(group1.Peers, peer1.ID)
|
group1.Peers = append(group1.Peers, peer1.ID)
|
||||||
group2.Peers = append(group2.Peers, peer2.ID)
|
group2.Peers = append(group2.Peers, peer2.ID)
|
||||||
|
|
||||||
@ -305,18 +303,20 @@ func TestAccountManager_GetNetworkMapWithPolicy(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
policy.Name = "test"
|
policy := &Policy{
|
||||||
policy.Enabled = true
|
Name: "test",
|
||||||
policy.Rules = []*PolicyRule{
|
Enabled: true,
|
||||||
{
|
Rules: []*PolicyRule{
|
||||||
Enabled: true,
|
{
|
||||||
Sources: []string{group1.ID},
|
Enabled: true,
|
||||||
Destinations: []string{group2.ID},
|
Sources: []string{group1.ID},
|
||||||
Bidirectional: true,
|
Destinations: []string{group2.ID},
|
||||||
Action: PolicyTrafficActionAccept,
|
Bidirectional: true,
|
||||||
|
Action: PolicyTrafficActionAccept,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
err = manager.SavePolicy(context.Background(), account.Id, userID, &policy, false)
|
policy, err = manager.SavePolicy(context.Background(), account.Id, userID, policy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("expecting rule to be added, got failure %v", err)
|
t.Errorf("expecting rule to be added, got failure %v", err)
|
||||||
return
|
return
|
||||||
@ -364,7 +364,7 @@ func TestAccountManager_GetNetworkMapWithPolicy(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
policy.Enabled = false
|
policy.Enabled = false
|
||||||
err = manager.SavePolicy(context.Background(), account.Id, userID, &policy, true)
|
_, err = manager.SavePolicy(context.Background(), account.Id, userID, policy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("expecting rule to be added, got failure %v", err)
|
t.Errorf("expecting rule to be added, got failure %v", err)
|
||||||
return
|
return
|
||||||
@ -1445,8 +1445,7 @@ func TestPeerAccountPeersUpdate(t *testing.T) {
|
|||||||
|
|
||||||
// Adding peer to group linked with policy should update account peers and send peer update
|
// Adding peer to group linked with policy should update account peers and send peer update
|
||||||
t.Run("adding peer to group linked with policy", func(t *testing.T) {
|
t.Run("adding peer to group linked with policy", func(t *testing.T) {
|
||||||
err = manager.SavePolicy(context.Background(), account.Id, userID, &Policy{
|
_, err = manager.SavePolicy(context.Background(), account.Id, userID, &Policy{
|
||||||
ID: "policy",
|
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
Rules: []*PolicyRule{
|
Rules: []*PolicyRule{
|
||||||
{
|
{
|
||||||
@ -1457,7 +1456,7 @@ func TestPeerAccountPeersUpdate(t *testing.T) {
|
|||||||
Action: PolicyTrafficActionAccept,
|
Action: PolicyTrafficActionAccept,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, false)
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
|
@ -7,7 +7,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/rs/xid"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"golang.org/x/exp/slices"
|
"golang.org/x/exp/slices"
|
||||||
|
|
||||||
@ -859,14 +858,23 @@ func TestPolicyAccountPeersUpdate(t *testing.T) {
|
|||||||
manager.peersUpdateManager.CloseChannel(context.Background(), peer1.ID)
|
manager.peersUpdateManager.CloseChannel(context.Background(), peer1.ID)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
var policyWithGroupRulesNoPeers *Policy
|
||||||
|
var policyWithDestinationPeersOnly *Policy
|
||||||
|
var policyWithSourceAndDestinationPeers *Policy
|
||||||
|
|
||||||
// Saving policy with rule groups with no peers should not update account's peers and not send peer update
|
// Saving policy with rule groups with no peers should not update account's peers and not send peer update
|
||||||
t.Run("saving policy with rule groups with no peers", func(t *testing.T) {
|
t.Run("saving policy with rule groups with no peers", func(t *testing.T) {
|
||||||
policy := Policy{
|
done := make(chan struct{})
|
||||||
ID: "policy-rule-groups-no-peers",
|
go func() {
|
||||||
Enabled: true,
|
peerShouldNotReceiveUpdate(t, updMsg)
|
||||||
|
close(done)
|
||||||
|
}()
|
||||||
|
|
||||||
|
policyWithGroupRulesNoPeers, err = manager.SavePolicy(context.Background(), account.Id, userID, &Policy{
|
||||||
|
AccountID: account.Id,
|
||||||
|
Enabled: true,
|
||||||
Rules: []*PolicyRule{
|
Rules: []*PolicyRule{
|
||||||
{
|
{
|
||||||
ID: xid.New().String(),
|
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
Sources: []string{"groupB"},
|
Sources: []string{"groupB"},
|
||||||
Destinations: []string{"groupC"},
|
Destinations: []string{"groupC"},
|
||||||
@ -874,15 +882,7 @@ func TestPolicyAccountPeersUpdate(t *testing.T) {
|
|||||||
Action: PolicyTrafficActionAccept,
|
Action: PolicyTrafficActionAccept,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
})
|
||||||
|
|
||||||
done := make(chan struct{})
|
|
||||||
go func() {
|
|
||||||
peerShouldNotReceiveUpdate(t, updMsg)
|
|
||||||
close(done)
|
|
||||||
}()
|
|
||||||
|
|
||||||
err := manager.SavePolicy(context.Background(), account.Id, userID, &policy, false)
|
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
@ -895,12 +895,17 @@ func TestPolicyAccountPeersUpdate(t *testing.T) {
|
|||||||
// Saving policy with source group containing peers, but destination group without peers should
|
// Saving policy with source group containing peers, but destination group without peers should
|
||||||
// update account's peers and send peer update
|
// update account's peers and send peer update
|
||||||
t.Run("saving policy where source has peers but destination does not", func(t *testing.T) {
|
t.Run("saving policy where source has peers but destination does not", func(t *testing.T) {
|
||||||
policy := Policy{
|
done := make(chan struct{})
|
||||||
ID: "policy-source-has-peers-destination-none",
|
go func() {
|
||||||
Enabled: true,
|
peerShouldReceiveUpdate(t, updMsg)
|
||||||
|
close(done)
|
||||||
|
}()
|
||||||
|
|
||||||
|
_, err = manager.SavePolicy(context.Background(), account.Id, userID, &Policy{
|
||||||
|
AccountID: account.Id,
|
||||||
|
Enabled: true,
|
||||||
Rules: []*PolicyRule{
|
Rules: []*PolicyRule{
|
||||||
{
|
{
|
||||||
ID: xid.New().String(),
|
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
Sources: []string{"groupA"},
|
Sources: []string{"groupA"},
|
||||||
Destinations: []string{"groupB"},
|
Destinations: []string{"groupB"},
|
||||||
@ -909,15 +914,7 @@ func TestPolicyAccountPeersUpdate(t *testing.T) {
|
|||||||
Action: PolicyTrafficActionAccept,
|
Action: PolicyTrafficActionAccept,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
})
|
||||||
|
|
||||||
done := make(chan struct{})
|
|
||||||
go func() {
|
|
||||||
peerShouldReceiveUpdate(t, updMsg)
|
|
||||||
close(done)
|
|
||||||
}()
|
|
||||||
|
|
||||||
err := manager.SavePolicy(context.Background(), account.Id, userID, &policy, false)
|
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
@ -930,13 +927,18 @@ func TestPolicyAccountPeersUpdate(t *testing.T) {
|
|||||||
// Saving policy with destination group containing peers, but source group without peers should
|
// Saving policy with destination group containing peers, but source group without peers should
|
||||||
// update account's peers and send peer update
|
// update account's peers and send peer update
|
||||||
t.Run("saving policy where destination has peers but source does not", func(t *testing.T) {
|
t.Run("saving policy where destination has peers but source does not", func(t *testing.T) {
|
||||||
policy := Policy{
|
done := make(chan struct{})
|
||||||
ID: "policy-destination-has-peers-source-none",
|
go func() {
|
||||||
Enabled: true,
|
peerShouldReceiveUpdate(t, updMsg)
|
||||||
|
close(done)
|
||||||
|
}()
|
||||||
|
|
||||||
|
policyWithDestinationPeersOnly, err = manager.SavePolicy(context.Background(), account.Id, userID, &Policy{
|
||||||
|
AccountID: account.Id,
|
||||||
|
Enabled: true,
|
||||||
Rules: []*PolicyRule{
|
Rules: []*PolicyRule{
|
||||||
{
|
{
|
||||||
ID: xid.New().String(),
|
Enabled: true,
|
||||||
Enabled: false,
|
|
||||||
Sources: []string{"groupC"},
|
Sources: []string{"groupC"},
|
||||||
Destinations: []string{"groupD"},
|
Destinations: []string{"groupD"},
|
||||||
Bidirectional: true,
|
Bidirectional: true,
|
||||||
@ -944,15 +946,7 @@ func TestPolicyAccountPeersUpdate(t *testing.T) {
|
|||||||
Action: PolicyTrafficActionAccept,
|
Action: PolicyTrafficActionAccept,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
})
|
||||||
|
|
||||||
done := make(chan struct{})
|
|
||||||
go func() {
|
|
||||||
peerShouldReceiveUpdate(t, updMsg)
|
|
||||||
close(done)
|
|
||||||
}()
|
|
||||||
|
|
||||||
err := manager.SavePolicy(context.Background(), account.Id, userID, &policy, false)
|
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
@ -965,12 +959,17 @@ func TestPolicyAccountPeersUpdate(t *testing.T) {
|
|||||||
// Saving policy with destination and source groups containing peers should update account's peers
|
// Saving policy with destination and source groups containing peers should update account's peers
|
||||||
// and send peer update
|
// and send peer update
|
||||||
t.Run("saving policy with source and destination groups with peers", func(t *testing.T) {
|
t.Run("saving policy with source and destination groups with peers", func(t *testing.T) {
|
||||||
policy := Policy{
|
done := make(chan struct{})
|
||||||
ID: "policy-source-destination-peers",
|
go func() {
|
||||||
Enabled: true,
|
peerShouldReceiveUpdate(t, updMsg)
|
||||||
|
close(done)
|
||||||
|
}()
|
||||||
|
|
||||||
|
policyWithSourceAndDestinationPeers, err = manager.SavePolicy(context.Background(), account.Id, userID, &Policy{
|
||||||
|
AccountID: account.Id,
|
||||||
|
Enabled: true,
|
||||||
Rules: []*PolicyRule{
|
Rules: []*PolicyRule{
|
||||||
{
|
{
|
||||||
ID: xid.New().String(),
|
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
Sources: []string{"groupA"},
|
Sources: []string{"groupA"},
|
||||||
Destinations: []string{"groupD"},
|
Destinations: []string{"groupD"},
|
||||||
@ -978,15 +977,7 @@ func TestPolicyAccountPeersUpdate(t *testing.T) {
|
|||||||
Action: PolicyTrafficActionAccept,
|
Action: PolicyTrafficActionAccept,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
})
|
||||||
|
|
||||||
done := make(chan struct{})
|
|
||||||
go func() {
|
|
||||||
peerShouldReceiveUpdate(t, updMsg)
|
|
||||||
close(done)
|
|
||||||
}()
|
|
||||||
|
|
||||||
err := manager.SavePolicy(context.Background(), account.Id, userID, &policy, false)
|
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
@ -999,28 +990,14 @@ func TestPolicyAccountPeersUpdate(t *testing.T) {
|
|||||||
// Disabling policy with destination and source groups containing peers should update account's peers
|
// Disabling policy with destination and source groups containing peers should update account's peers
|
||||||
// and send peer update
|
// and send peer update
|
||||||
t.Run("disabling policy with source and destination groups with peers", func(t *testing.T) {
|
t.Run("disabling policy with source and destination groups with peers", func(t *testing.T) {
|
||||||
policy := Policy{
|
|
||||||
ID: "policy-source-destination-peers",
|
|
||||||
Enabled: false,
|
|
||||||
Rules: []*PolicyRule{
|
|
||||||
{
|
|
||||||
ID: xid.New().String(),
|
|
||||||
Enabled: true,
|
|
||||||
Sources: []string{"groupA"},
|
|
||||||
Destinations: []string{"groupD"},
|
|
||||||
Bidirectional: true,
|
|
||||||
Action: PolicyTrafficActionAccept,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
peerShouldReceiveUpdate(t, updMsg)
|
peerShouldReceiveUpdate(t, updMsg)
|
||||||
close(done)
|
close(done)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
err := manager.SavePolicy(context.Background(), account.Id, userID, &policy, true)
|
policyWithSourceAndDestinationPeers.Enabled = false
|
||||||
|
policyWithSourceAndDestinationPeers, err = manager.SavePolicy(context.Background(), account.Id, userID, policyWithSourceAndDestinationPeers)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
@ -1033,29 +1010,15 @@ func TestPolicyAccountPeersUpdate(t *testing.T) {
|
|||||||
// Updating disabled policy with destination and source groups containing peers should not update account's peers
|
// Updating disabled policy with destination and source groups containing peers should not update account's peers
|
||||||
// or send peer update
|
// or send peer update
|
||||||
t.Run("updating disabled policy with source and destination groups with peers", func(t *testing.T) {
|
t.Run("updating disabled policy with source and destination groups with peers", func(t *testing.T) {
|
||||||
policy := Policy{
|
|
||||||
ID: "policy-source-destination-peers",
|
|
||||||
Description: "updated description",
|
|
||||||
Enabled: false,
|
|
||||||
Rules: []*PolicyRule{
|
|
||||||
{
|
|
||||||
ID: xid.New().String(),
|
|
||||||
Enabled: true,
|
|
||||||
Sources: []string{"groupA"},
|
|
||||||
Destinations: []string{"groupA"},
|
|
||||||
Bidirectional: true,
|
|
||||||
Action: PolicyTrafficActionAccept,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
peerShouldNotReceiveUpdate(t, updMsg)
|
peerShouldNotReceiveUpdate(t, updMsg)
|
||||||
close(done)
|
close(done)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
err := manager.SavePolicy(context.Background(), account.Id, userID, &policy, true)
|
policyWithSourceAndDestinationPeers.Description = "updated description"
|
||||||
|
policyWithSourceAndDestinationPeers.Rules[0].Destinations = []string{"groupA"}
|
||||||
|
policyWithSourceAndDestinationPeers, err = manager.SavePolicy(context.Background(), account.Id, userID, policyWithSourceAndDestinationPeers)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
@ -1068,28 +1031,14 @@ func TestPolicyAccountPeersUpdate(t *testing.T) {
|
|||||||
// Enabling policy with destination and source groups containing peers should update account's peers
|
// Enabling policy with destination and source groups containing peers should update account's peers
|
||||||
// and send peer update
|
// and send peer update
|
||||||
t.Run("enabling policy with source and destination groups with peers", func(t *testing.T) {
|
t.Run("enabling policy with source and destination groups with peers", func(t *testing.T) {
|
||||||
policy := Policy{
|
|
||||||
ID: "policy-source-destination-peers",
|
|
||||||
Enabled: true,
|
|
||||||
Rules: []*PolicyRule{
|
|
||||||
{
|
|
||||||
ID: xid.New().String(),
|
|
||||||
Enabled: true,
|
|
||||||
Sources: []string{"groupA"},
|
|
||||||
Destinations: []string{"groupD"},
|
|
||||||
Bidirectional: true,
|
|
||||||
Action: PolicyTrafficActionAccept,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
peerShouldReceiveUpdate(t, updMsg)
|
peerShouldReceiveUpdate(t, updMsg)
|
||||||
close(done)
|
close(done)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
err := manager.SavePolicy(context.Background(), account.Id, userID, &policy, true)
|
policyWithSourceAndDestinationPeers.Enabled = true
|
||||||
|
policyWithSourceAndDestinationPeers, err = manager.SavePolicy(context.Background(), account.Id, userID, policyWithSourceAndDestinationPeers)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
@ -1101,15 +1050,13 @@ func TestPolicyAccountPeersUpdate(t *testing.T) {
|
|||||||
|
|
||||||
// Deleting policy should trigger account peers update and send peer update
|
// Deleting policy should trigger account peers update and send peer update
|
||||||
t.Run("deleting policy with source and destination groups with peers", func(t *testing.T) {
|
t.Run("deleting policy with source and destination groups with peers", func(t *testing.T) {
|
||||||
policyID := "policy-source-destination-peers"
|
|
||||||
|
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
peerShouldReceiveUpdate(t, updMsg)
|
peerShouldReceiveUpdate(t, updMsg)
|
||||||
close(done)
|
close(done)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
err := manager.DeletePolicy(context.Background(), account.Id, policyID, userID)
|
err := manager.DeletePolicy(context.Background(), account.Id, policyWithSourceAndDestinationPeers.ID, userID)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
@ -1123,14 +1070,13 @@ func TestPolicyAccountPeersUpdate(t *testing.T) {
|
|||||||
// Deleting policy with destination group containing peers, but source group without peers should
|
// Deleting policy with destination group containing peers, but source group without peers should
|
||||||
// update account's peers and send peer update
|
// update account's peers and send peer update
|
||||||
t.Run("deleting policy where destination has peers but source does not", func(t *testing.T) {
|
t.Run("deleting policy where destination has peers but source does not", func(t *testing.T) {
|
||||||
policyID := "policy-destination-has-peers-source-none"
|
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
peerShouldReceiveUpdate(t, updMsg)
|
peerShouldReceiveUpdate(t, updMsg)
|
||||||
close(done)
|
close(done)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
err := manager.DeletePolicy(context.Background(), account.Id, policyID, userID)
|
err := manager.DeletePolicy(context.Background(), account.Id, policyWithDestinationPeersOnly.ID, userID)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
@ -1142,14 +1088,13 @@ func TestPolicyAccountPeersUpdate(t *testing.T) {
|
|||||||
|
|
||||||
// Deleting policy with no peers in groups should not update account's peers and not send peer update
|
// Deleting policy with no peers in groups should not update account's peers and not send peer update
|
||||||
t.Run("deleting policy with no peers in groups", func(t *testing.T) {
|
t.Run("deleting policy with no peers in groups", func(t *testing.T) {
|
||||||
policyID := "policy-rule-groups-no-peers"
|
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
peerShouldNotReceiveUpdate(t, updMsg)
|
peerShouldNotReceiveUpdate(t, updMsg)
|
||||||
close(done)
|
close(done)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
err := manager.DeletePolicy(context.Background(), account.Id, policyID, userID)
|
err := manager.DeletePolicy(context.Background(), account.Id, policyWithGroupRulesNoPeers.ID, userID)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
|
@ -5,7 +5,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/rs/xid"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
@ -210,12 +209,10 @@ func TestPostureCheckAccountPeersUpdate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
policy := Policy{
|
policy := &Policy{
|
||||||
ID: "policyA",
|
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
Rules: []*PolicyRule{
|
Rules: []*PolicyRule{
|
||||||
{
|
{
|
||||||
ID: xid.New().String(),
|
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
Sources: []string{"groupA"},
|
Sources: []string{"groupA"},
|
||||||
Destinations: []string{"groupA"},
|
Destinations: []string{"groupA"},
|
||||||
@ -234,7 +231,7 @@ func TestPostureCheckAccountPeersUpdate(t *testing.T) {
|
|||||||
close(done)
|
close(done)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
err := manager.SavePolicy(context.Background(), account.Id, userID, &policy, false)
|
policy, err = manager.SavePolicy(context.Background(), account.Id, userID, policy)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
@ -282,8 +279,7 @@ func TestPostureCheckAccountPeersUpdate(t *testing.T) {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
policy.SourcePostureChecks = []string{}
|
policy.SourcePostureChecks = []string{}
|
||||||
|
_, err := manager.SavePolicy(context.Background(), account.Id, userID, policy)
|
||||||
err := manager.SavePolicy(context.Background(), account.Id, userID, &policy, true)
|
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
@ -316,12 +312,10 @@ func TestPostureCheckAccountPeersUpdate(t *testing.T) {
|
|||||||
|
|
||||||
// Updating linked posture check to policy with no peers should not trigger account peers update and not send peer update
|
// Updating linked posture check to policy with no peers should not trigger account peers update and not send peer update
|
||||||
t.Run("updating linked posture check to policy with no peers", func(t *testing.T) {
|
t.Run("updating linked posture check to policy with no peers", func(t *testing.T) {
|
||||||
policy = Policy{
|
_, err = manager.SavePolicy(context.Background(), account.Id, userID, &Policy{
|
||||||
ID: "policyB",
|
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
Rules: []*PolicyRule{
|
Rules: []*PolicyRule{
|
||||||
{
|
{
|
||||||
ID: xid.New().String(),
|
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
Sources: []string{"groupB"},
|
Sources: []string{"groupB"},
|
||||||
Destinations: []string{"groupC"},
|
Destinations: []string{"groupC"},
|
||||||
@ -330,8 +324,7 @@ func TestPostureCheckAccountPeersUpdate(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
SourcePostureChecks: []string{postureCheckB.ID},
|
SourcePostureChecks: []string{postureCheckB.ID},
|
||||||
}
|
})
|
||||||
err = manager.SavePolicy(context.Background(), account.Id, userID, &policy, false)
|
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
@ -362,12 +355,11 @@ func TestPostureCheckAccountPeersUpdate(t *testing.T) {
|
|||||||
t.Cleanup(func() {
|
t.Cleanup(func() {
|
||||||
manager.peersUpdateManager.CloseChannel(context.Background(), peer2.ID)
|
manager.peersUpdateManager.CloseChannel(context.Background(), peer2.ID)
|
||||||
})
|
})
|
||||||
policy = Policy{
|
|
||||||
ID: "policyB",
|
_, err = manager.SavePolicy(context.Background(), account.Id, userID, &Policy{
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
Rules: []*PolicyRule{
|
Rules: []*PolicyRule{
|
||||||
{
|
{
|
||||||
ID: xid.New().String(),
|
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
Sources: []string{"groupB"},
|
Sources: []string{"groupB"},
|
||||||
Destinations: []string{"groupA"},
|
Destinations: []string{"groupA"},
|
||||||
@ -376,9 +368,7 @@ func TestPostureCheckAccountPeersUpdate(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
SourcePostureChecks: []string{postureCheckB.ID},
|
SourcePostureChecks: []string{postureCheckB.ID},
|
||||||
}
|
})
|
||||||
|
|
||||||
err = manager.SavePolicy(context.Background(), account.Id, userID, &policy, true)
|
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
@ -405,8 +395,7 @@ func TestPostureCheckAccountPeersUpdate(t *testing.T) {
|
|||||||
// Updating linked client posture check to policy where source has peers but destination does not,
|
// Updating linked client posture check to policy where source has peers but destination does not,
|
||||||
// should trigger account peers update and send peer update
|
// should trigger account peers update and send peer update
|
||||||
t.Run("updating linked posture check to policy where source has peers but destination does not", func(t *testing.T) {
|
t.Run("updating linked posture check to policy where source has peers but destination does not", func(t *testing.T) {
|
||||||
policy = Policy{
|
_, err = manager.SavePolicy(context.Background(), account.Id, userID, &Policy{
|
||||||
ID: "policyB",
|
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
Rules: []*PolicyRule{
|
Rules: []*PolicyRule{
|
||||||
{
|
{
|
||||||
@ -418,8 +407,7 @@ func TestPostureCheckAccountPeersUpdate(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
SourcePostureChecks: []string{postureCheckB.ID},
|
SourcePostureChecks: []string{postureCheckB.ID},
|
||||||
}
|
})
|
||||||
err = manager.SavePolicy(context.Background(), account.Id, userID, &policy, true)
|
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
@ -490,12 +478,9 @@ func TestArePostureCheckChangesAffectPeers(t *testing.T) {
|
|||||||
require.NoError(t, err, "failed to save postureCheckB")
|
require.NoError(t, err, "failed to save postureCheckB")
|
||||||
|
|
||||||
policy := &Policy{
|
policy := &Policy{
|
||||||
ID: "policyA",
|
|
||||||
AccountID: account.Id,
|
AccountID: account.Id,
|
||||||
Rules: []*PolicyRule{
|
Rules: []*PolicyRule{
|
||||||
{
|
{
|
||||||
ID: "ruleA",
|
|
||||||
PolicyID: "policyA",
|
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
Sources: []string{"groupA"},
|
Sources: []string{"groupA"},
|
||||||
Destinations: []string{"groupA"},
|
Destinations: []string{"groupA"},
|
||||||
@ -504,7 +489,7 @@ func TestArePostureCheckChangesAffectPeers(t *testing.T) {
|
|||||||
SourcePostureChecks: []string{postureCheckA.ID},
|
SourcePostureChecks: []string{postureCheckA.ID},
|
||||||
}
|
}
|
||||||
|
|
||||||
err = manager.SavePolicy(context.Background(), account.Id, userID, policy, false)
|
policy, err = manager.SavePolicy(context.Background(), account.Id, adminUserID, policy)
|
||||||
require.NoError(t, err, "failed to save policy")
|
require.NoError(t, err, "failed to save policy")
|
||||||
|
|
||||||
t.Run("posture check exists and is linked to policy with peers", func(t *testing.T) {
|
t.Run("posture check exists and is linked to policy with peers", func(t *testing.T) {
|
||||||
@ -528,7 +513,7 @@ func TestArePostureCheckChangesAffectPeers(t *testing.T) {
|
|||||||
t.Run("posture check is linked to policy with no peers in source groups", func(t *testing.T) {
|
t.Run("posture check is linked to policy with no peers in source groups", func(t *testing.T) {
|
||||||
policy.Rules[0].Sources = []string{"groupB"}
|
policy.Rules[0].Sources = []string{"groupB"}
|
||||||
policy.Rules[0].Destinations = []string{"groupA"}
|
policy.Rules[0].Destinations = []string{"groupA"}
|
||||||
err = manager.SavePolicy(context.Background(), account.Id, userID, policy, true)
|
_, err = manager.SavePolicy(context.Background(), account.Id, adminUserID, policy)
|
||||||
require.NoError(t, err, "failed to update policy")
|
require.NoError(t, err, "failed to update policy")
|
||||||
|
|
||||||
result, err := arePostureCheckChangesAffectPeers(context.Background(), manager.Store, account.Id, postureCheckA.ID)
|
result, err := arePostureCheckChangesAffectPeers(context.Background(), manager.Store, account.Id, postureCheckA.ID)
|
||||||
@ -539,7 +524,7 @@ func TestArePostureCheckChangesAffectPeers(t *testing.T) {
|
|||||||
t.Run("posture check is linked to policy with no peers in destination groups", func(t *testing.T) {
|
t.Run("posture check is linked to policy with no peers in destination groups", func(t *testing.T) {
|
||||||
policy.Rules[0].Sources = []string{"groupA"}
|
policy.Rules[0].Sources = []string{"groupA"}
|
||||||
policy.Rules[0].Destinations = []string{"groupB"}
|
policy.Rules[0].Destinations = []string{"groupB"}
|
||||||
err = manager.SavePolicy(context.Background(), account.Id, userID, policy, true)
|
_, err = manager.SavePolicy(context.Background(), account.Id, adminUserID, policy)
|
||||||
require.NoError(t, err, "failed to update policy")
|
require.NoError(t, err, "failed to update policy")
|
||||||
|
|
||||||
result, err := arePostureCheckChangesAffectPeers(context.Background(), manager.Store, account.Id, postureCheckA.ID)
|
result, err := arePostureCheckChangesAffectPeers(context.Background(), manager.Store, account.Id, postureCheckA.ID)
|
||||||
@ -560,7 +545,7 @@ func TestArePostureCheckChangesAffectPeers(t *testing.T) {
|
|||||||
t.Run("posture check is linked to policy with non-existent group", func(t *testing.T) {
|
t.Run("posture check is linked to policy with non-existent group", func(t *testing.T) {
|
||||||
policy.Rules[0].Sources = []string{"nonExistentGroup"}
|
policy.Rules[0].Sources = []string{"nonExistentGroup"}
|
||||||
policy.Rules[0].Destinations = []string{"nonExistentGroup"}
|
policy.Rules[0].Destinations = []string{"nonExistentGroup"}
|
||||||
err = manager.SavePolicy(context.Background(), account.Id, userID, policy, true)
|
_, err = manager.SavePolicy(context.Background(), account.Id, adminUserID, policy)
|
||||||
require.NoError(t, err, "failed to update policy")
|
require.NoError(t, err, "failed to update policy")
|
||||||
|
|
||||||
result, err := arePostureCheckChangesAffectPeers(context.Background(), manager.Store, account.Id, postureCheckA.ID)
|
result, err := arePostureCheckChangesAffectPeers(context.Background(), manager.Store, account.Id, postureCheckA.ID)
|
||||||
|
@ -1214,12 +1214,11 @@ func TestGetNetworkMap_RouteSync(t *testing.T) {
|
|||||||
|
|
||||||
defaultRule := rules[0]
|
defaultRule := rules[0]
|
||||||
newPolicy := defaultRule.Copy()
|
newPolicy := defaultRule.Copy()
|
||||||
newPolicy.ID = xid.New().String()
|
|
||||||
newPolicy.Name = "peer1 only"
|
newPolicy.Name = "peer1 only"
|
||||||
newPolicy.Rules[0].Sources = []string{newGroup.ID}
|
newPolicy.Rules[0].Sources = []string{newGroup.ID}
|
||||||
newPolicy.Rules[0].Destinations = []string{newGroup.ID}
|
newPolicy.Rules[0].Destinations = []string{newGroup.ID}
|
||||||
|
|
||||||
err = am.SavePolicy(context.Background(), account.Id, userID, newPolicy, false)
|
_, err = am.SavePolicy(context.Background(), account.Id, userID, newPolicy)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
err = am.DeletePolicy(context.Background(), account.Id, defaultRule.ID, userID)
|
err = am.DeletePolicy(context.Background(), account.Id, defaultRule.ID, userID)
|
||||||
|
@ -390,8 +390,7 @@ func TestSetupKeyAccountPeersUpdate(t *testing.T) {
|
|||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
policy := Policy{
|
policy := &Policy{
|
||||||
ID: "policy",
|
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
Rules: []*PolicyRule{
|
Rules: []*PolicyRule{
|
||||||
{
|
{
|
||||||
@ -403,7 +402,7 @@ func TestSetupKeyAccountPeersUpdate(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
err = manager.SavePolicy(context.Background(), account.Id, userID, &policy, false)
|
_, err = manager.SavePolicy(context.Background(), account.Id, userID, policy)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
updMsg := manager.peersUpdateManager.CreateChannel(context.Background(), peer1.ID)
|
updMsg := manager.peersUpdateManager.CreateChannel(context.Background(), peer1.ID)
|
||||||
|
@ -1279,8 +1279,7 @@ func TestUserAccountPeersUpdate(t *testing.T) {
|
|||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
policy := Policy{
|
policy := &Policy{
|
||||||
ID: "policy",
|
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
Rules: []*PolicyRule{
|
Rules: []*PolicyRule{
|
||||||
{
|
{
|
||||||
@ -1292,7 +1291,7 @@ func TestUserAccountPeersUpdate(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
err = manager.SavePolicy(context.Background(), account.Id, userID, &policy, false)
|
_, err = manager.SavePolicy(context.Background(), account.Id, userID, policy)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
updMsg := manager.peersUpdateManager.CreateChannel(context.Background(), peer1.ID)
|
updMsg := manager.peersUpdateManager.CreateChannel(context.Background(), peer1.ID)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user