mirror of
https://github.com/netbirdio/netbird.git
synced 2024-12-14 10:50:45 +01:00
refactor peer and user
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
This commit is contained in:
parent
53218f99bc
commit
13aa9f7198
@ -263,8 +263,7 @@ func (am *DefaultAccountManager) UpdatePeer(ctx context.Context, accountID, user
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
expired, _ := peer.LoginExpired(account.Settings.PeerLoginExpiration)
|
if peerLabelUpdated {
|
||||||
if peerLabelUpdated || (expired && peer.LoginExpirationEnabled) {
|
|
||||||
am.updateAccountPeers(ctx, account)
|
am.updateAccountPeers(ctx, account)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1435,31 +1435,6 @@ func TestPeerAccountPeersUpdate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// Updating expired peer and peer expiration is enabled should update account peers and send peer update
|
|
||||||
t.Run("updating expired peer and peer expiration is enabled", func(t *testing.T) {
|
|
||||||
err = manager.Store.SavePeerStatus(account.Id, peer4.ID, nbpeer.PeerStatus{
|
|
||||||
Connected: false,
|
|
||||||
LastSeen: time.Now().Add(-48 * time.Hour),
|
|
||||||
LoginExpired: true,
|
|
||||||
})
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
done := make(chan struct{})
|
|
||||||
go func() {
|
|
||||||
peerShouldReceiveUpdate(t, updMsg)
|
|
||||||
close(done)
|
|
||||||
}()
|
|
||||||
|
|
||||||
_, err = manager.UpdatePeer(context.Background(), account.Id, userID, peer4)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
select {
|
|
||||||
case <-done:
|
|
||||||
case <-time.After(time.Second):
|
|
||||||
t.Error("timeout waiting for peerShouldReceiveUpdate")
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// Deleting peer with linked group to policy should update account peers and send peer update
|
// Deleting peer with linked group to policy should update account peers and send peer update
|
||||||
t.Run("deleting peer with linked group to policy", func(t *testing.T) {
|
t.Run("deleting peer with linked group to policy", func(t *testing.T) {
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
|
@ -827,7 +827,7 @@ func (am *DefaultAccountManager) SaveOrAddUsers(ctx context.Context, accountID,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if areUsersLinkedToPeers(account, userIDs) && account.Settings.GroupsPropagationEnabled {
|
if account.Settings.GroupsPropagationEnabled && areUsersLinkedToPeers(account, userIDs) {
|
||||||
am.updateAccountPeers(ctx, account)
|
am.updateAccountPeers(ctx, account)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1213,7 +1213,7 @@ func (am *DefaultAccountManager) DeleteRegularUsers(ctx context.Context, account
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if hadPeers && !updateAccountPeers {
|
if hadPeers {
|
||||||
updateAccountPeers = true
|
updateAccountPeers = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1301,7 +1301,7 @@ func TestUserAccountPeersUpdate(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Creating a new regular user should not update account peers and not send peer update
|
// Creating a new regular user should not update account peers and not send peer update
|
||||||
t.Run("creating new regular user", func(t *testing.T) {
|
t.Run("creating new regular user with no groups", func(t *testing.T) {
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
peerShouldNotReceiveUpdate(t, updMsg)
|
peerShouldNotReceiveUpdate(t, updMsg)
|
||||||
|
Loading…
Reference in New Issue
Block a user