mirror of
https://github.com/netbirdio/netbird.git
synced 2025-01-23 22:38:36 +01:00
[management] remove peer from group on delete (#3223)
This commit is contained in:
parent
78da6b42ad
commit
8c965434ae
@ -145,14 +145,14 @@ func BenchmarkGetAllPeers(b *testing.B) {
|
|||||||
|
|
||||||
func BenchmarkDeletePeer(b *testing.B) {
|
func BenchmarkDeletePeer(b *testing.B) {
|
||||||
var expectedMetrics = map[string]testing_tools.PerformanceMetrics{
|
var expectedMetrics = map[string]testing_tools.PerformanceMetrics{
|
||||||
"Peers - XS": {MinMsPerOpLocal: 0, MaxMsPerOpLocal: 4, MinMsPerOpCICD: 2, MaxMsPerOpCICD: 15},
|
"Peers - XS": {MinMsPerOpLocal: 0, MaxMsPerOpLocal: 4, MinMsPerOpCICD: 2, MaxMsPerOpCICD: 16},
|
||||||
"Peers - S": {MinMsPerOpLocal: 0, MaxMsPerOpLocal: 4, MinMsPerOpCICD: 2, MaxMsPerOpCICD: 15},
|
"Peers - S": {MinMsPerOpLocal: 0, MaxMsPerOpLocal: 4, MinMsPerOpCICD: 2, MaxMsPerOpCICD: 16},
|
||||||
"Peers - M": {MinMsPerOpLocal: 0, MaxMsPerOpLocal: 4, MinMsPerOpCICD: 2, MaxMsPerOpCICD: 15},
|
"Peers - M": {MinMsPerOpLocal: 0, MaxMsPerOpLocal: 4, MinMsPerOpCICD: 2, MaxMsPerOpCICD: 16},
|
||||||
"Peers - L": {MinMsPerOpLocal: 0, MaxMsPerOpLocal: 4, MinMsPerOpCICD: 2, MaxMsPerOpCICD: 15},
|
"Peers - L": {MinMsPerOpLocal: 0, MaxMsPerOpLocal: 4, MinMsPerOpCICD: 2, MaxMsPerOpCICD: 16},
|
||||||
"Groups - L": {MinMsPerOpLocal: 0, MaxMsPerOpLocal: 4, MinMsPerOpCICD: 2, MaxMsPerOpCICD: 15},
|
"Groups - L": {MinMsPerOpLocal: 0, MaxMsPerOpLocal: 4, MinMsPerOpCICD: 2, MaxMsPerOpCICD: 16},
|
||||||
"Users - L": {MinMsPerOpLocal: 0, MaxMsPerOpLocal: 4, MinMsPerOpCICD: 2, MaxMsPerOpCICD: 15},
|
"Users - L": {MinMsPerOpLocal: 0, MaxMsPerOpLocal: 4, MinMsPerOpCICD: 2, MaxMsPerOpCICD: 16},
|
||||||
"Setup Keys - L": {MinMsPerOpLocal: 0, MaxMsPerOpLocal: 4, MinMsPerOpCICD: 2, MaxMsPerOpCICD: 15},
|
"Setup Keys - L": {MinMsPerOpLocal: 0, MaxMsPerOpLocal: 4, MinMsPerOpCICD: 2, MaxMsPerOpCICD: 16},
|
||||||
"Peers - XL": {MinMsPerOpLocal: 0, MaxMsPerOpLocal: 4, MinMsPerOpCICD: 2, MaxMsPerOpCICD: 15},
|
"Peers - XL": {MinMsPerOpLocal: 0, MaxMsPerOpLocal: 4, MinMsPerOpCICD: 2, MaxMsPerOpCICD: 16},
|
||||||
}
|
}
|
||||||
|
|
||||||
log.SetOutput(io.Discard)
|
log.SetOutput(io.Discard)
|
||||||
|
@ -380,6 +380,19 @@ func (am *DefaultAccountManager) DeletePeer(ctx context.Context, accountID, peer
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
groups, err := transaction.GetPeerGroups(ctx, store.LockingStrengthUpdate, accountID, peerID)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to get peer groups: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, group := range groups {
|
||||||
|
group.RemovePeer(peerID)
|
||||||
|
err = transaction.SaveGroup(ctx, store.LockingStrengthUpdate, group)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to save group: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
eventsToStore, err = deletePeers(ctx, am, transaction, accountID, userID, []*nbpeer.Peer{peer})
|
eventsToStore, err = deletePeers(ctx, am, transaction, accountID, userID, []*nbpeer.Peer{peer})
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
|
@ -1728,3 +1728,52 @@ func TestPeerAccountPeersUpdate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_DeletePeer(t *testing.T) {
|
||||||
|
manager, err := createManager(t)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// account with an admin and a regular user
|
||||||
|
accountID := "test_account"
|
||||||
|
adminUser := "account_creator"
|
||||||
|
account := newAccountWithId(context.Background(), accountID, adminUser, "")
|
||||||
|
account.Peers = map[string]*nbpeer.Peer{
|
||||||
|
"peer1": {
|
||||||
|
ID: "peer1",
|
||||||
|
AccountID: accountID,
|
||||||
|
},
|
||||||
|
"peer2": {
|
||||||
|
ID: "peer2",
|
||||||
|
AccountID: accountID,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
account.Groups = map[string]*types.Group{
|
||||||
|
"group1": {
|
||||||
|
ID: "group1",
|
||||||
|
Name: "Group1",
|
||||||
|
Peers: []string{"peer1", "peer2"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
err = manager.Store.SaveAccount(context.Background(), account)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = manager.DeletePeer(context.Background(), accountID, "peer1", adminUser)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("DeletePeer failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = manager.GetPeer(context.Background(), accountID, "peer1", adminUser)
|
||||||
|
assert.Error(t, err)
|
||||||
|
|
||||||
|
group, err := manager.GetGroup(context.Background(), accountID, "group1", adminUser)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.NotContains(t, group.Peers, "peer1")
|
||||||
|
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user