mirror of
https://github.com/netbirdio/netbird.git
synced 2025-01-31 10:31:58 +01:00
fix user and setup key tests
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
This commit is contained in:
parent
41acacfba5
commit
1ed44b810c
@ -354,11 +354,11 @@ func TestSetupKey_Copy(t *testing.T) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSetupKeyAccountPeerUpdate(t *testing.T) {
|
func TestSetupKeyAccountPeersUpdate(t *testing.T) {
|
||||||
manager, account, peer1, peer2, peer3 := setupNetworkMapTest(t)
|
manager, account, peer1, peer2, peer3 := setupNetworkMapTest(t)
|
||||||
|
|
||||||
err := manager.SaveGroup(context.Background(), account.Id, userID, &nbgroup.Group{
|
err := manager.SaveGroup(context.Background(), account.Id, userID, &nbgroup.Group{
|
||||||
ID: "group-id",
|
ID: "groupA",
|
||||||
Name: "GroupA",
|
Name: "GroupA",
|
||||||
Peers: []string{peer1.ID, peer2.ID, peer3.ID},
|
Peers: []string{peer1.ID, peer2.ID, peer3.ID},
|
||||||
})
|
})
|
||||||
@ -370,14 +370,14 @@ func TestSetupKeyAccountPeerUpdate(t *testing.T) {
|
|||||||
Rules: []*PolicyRule{
|
Rules: []*PolicyRule{
|
||||||
{
|
{
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
Sources: []string{"group-id"},
|
Sources: []string{"groupA"},
|
||||||
Destinations: []string{"group-id"},
|
Destinations: []string{"group"},
|
||||||
Bidirectional: true,
|
Bidirectional: true,
|
||||||
Action: PolicyTrafficActionAccept,
|
Action: PolicyTrafficActionAccept,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
err = manager.SavePolicy(context.Background(), account.Id, userID, &policy)
|
err = manager.SavePolicy(context.Background(), account.Id, userID, &policy, false)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
updMsg := manager.peersUpdateManager.CreateChannel(context.Background(), peer1.ID)
|
updMsg := manager.peersUpdateManager.CreateChannel(context.Background(), peer1.ID)
|
||||||
@ -386,6 +386,8 @@ func TestSetupKeyAccountPeerUpdate(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
var setupKey *SetupKey
|
var setupKey *SetupKey
|
||||||
|
|
||||||
|
// Creating setup key should not update account peers and not send peer update
|
||||||
t.Run("creating setup key", func(t *testing.T) {
|
t.Run("creating setup key", func(t *testing.T) {
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
@ -394,9 +396,7 @@ func TestSetupKeyAccountPeerUpdate(t *testing.T) {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
setupKey, err = manager.CreateSetupKey(context.Background(), account.Id, "key1", SetupKeyReusable, time.Hour, nil, 999, userID, false)
|
setupKey, err = manager.CreateSetupKey(context.Background(), account.Id, "key1", SetupKeyReusable, time.Hour, nil, 999, userID, false)
|
||||||
if err != nil {
|
assert.NoError(t, err)
|
||||||
t.Fatal("error creating setup key")
|
|
||||||
}
|
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-done:
|
case <-done:
|
||||||
|
@ -1256,12 +1256,12 @@ func TestDefaultAccountManager_SaveUser(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUserAccountPeerUpdate(t *testing.T) {
|
func TestUserAccountPeersUpdate(t *testing.T) {
|
||||||
// account groups propagation is enabled
|
// account groups propagation is enabled
|
||||||
manager, account, peer1, peer2, peer3 := setupNetworkMapTest(t)
|
manager, account, peer1, peer2, peer3 := setupNetworkMapTest(t)
|
||||||
|
|
||||||
err := manager.SaveGroup(context.Background(), account.Id, userID, &nbgroup.Group{
|
err := manager.SaveGroup(context.Background(), account.Id, userID, &nbgroup.Group{
|
||||||
ID: "group-id",
|
ID: "groupA",
|
||||||
Name: "GroupA",
|
Name: "GroupA",
|
||||||
Peers: []string{peer1.ID, peer2.ID, peer3.ID},
|
Peers: []string{peer1.ID, peer2.ID, peer3.ID},
|
||||||
})
|
})
|
||||||
@ -1273,14 +1273,14 @@ func TestUserAccountPeerUpdate(t *testing.T) {
|
|||||||
Rules: []*PolicyRule{
|
Rules: []*PolicyRule{
|
||||||
{
|
{
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
Sources: []string{"group-id"},
|
Sources: []string{"groupA"},
|
||||||
Destinations: []string{"group-id"},
|
Destinations: []string{"groupA"},
|
||||||
Bidirectional: true,
|
Bidirectional: true,
|
||||||
Action: PolicyTrafficActionAccept,
|
Action: PolicyTrafficActionAccept,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
err = manager.SavePolicy(context.Background(), account.Id, userID, &policy)
|
err = manager.SavePolicy(context.Background(), account.Id, userID, &policy, false)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
updMsg := manager.peersUpdateManager.CreateChannel(context.Background(), peer1.ID)
|
updMsg := manager.peersUpdateManager.CreateChannel(context.Background(), peer1.ID)
|
||||||
@ -1394,14 +1394,12 @@ func TestUserAccountPeerUpdate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
_ = peer4
|
|
||||||
|
|
||||||
peer4UpdMsg := manager.peersUpdateManager.CreateChannel(context.Background(), peer4.ID)
|
peer4UpdMsg := manager.peersUpdateManager.CreateChannel(context.Background(), peer4.ID)
|
||||||
t.Cleanup(func() {
|
t.Cleanup(func() {
|
||||||
manager.peersUpdateManager.CloseChannel(context.Background(), peer4.ID)
|
manager.peersUpdateManager.CloseChannel(context.Background(), peer4.ID)
|
||||||
})
|
})
|
||||||
|
|
||||||
// deleting user with linked peers should update account peers and no send peer update
|
// deleting user with linked peers should update account peers and send peer update
|
||||||
t.Run("deleting user with linked peers", func(t *testing.T) {
|
t.Run("deleting user with linked peers", func(t *testing.T) {
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
|
Loading…
Reference in New Issue
Block a user