mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-24 22:39:09 +02:00
fix tests
This commit is contained in:
@@ -1279,7 +1279,7 @@ func (am *DefaultAccountManager) SyncUserJWTGroups(ctx context.Context, userAuth
|
|||||||
var hasChanges bool
|
var hasChanges bool
|
||||||
var user *types.User
|
var user *types.User
|
||||||
err = am.Store.ExecuteInTransaction(ctx, func(transaction store.Store) error {
|
err = am.Store.ExecuteInTransaction(ctx, func(transaction store.Store) error {
|
||||||
user, err = transaction.GetUserByUserID(ctx, store.LockingStrengthUpdate, userAuth.UserId)
|
user, err = transaction.GetUserByUserID(ctx, store.LockingStrengthShare, userAuth.UserId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error getting user: %w", err)
|
return fmt.Errorf("error getting user: %w", err)
|
||||||
}
|
}
|
||||||
@@ -1314,7 +1314,7 @@ func (am *DefaultAccountManager) SyncUserJWTGroups(ctx context.Context, userAuth
|
|||||||
|
|
||||||
// Propagate changes to peers if group propagation is enabled
|
// Propagate changes to peers if group propagation is enabled
|
||||||
if settings.GroupsPropagationEnabled {
|
if settings.GroupsPropagationEnabled {
|
||||||
groups, err = transaction.GetAccountGroups(ctx, store.LockingStrengthUpdate, userAuth.AccountId)
|
groups, err = transaction.GetAccountGroups(ctx, store.LockingStrengthShare, userAuth.AccountId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error getting account groups: %w", err)
|
return fmt.Errorf("error getting account groups: %w", err)
|
||||||
}
|
}
|
||||||
@@ -1899,7 +1899,7 @@ func (am *DefaultAccountManager) UpdateToPrimaryAccount(ctx context.Context, acc
|
|||||||
// propagateUserGroupMemberships propagates all account users' group memberships to their peers.
|
// propagateUserGroupMemberships propagates all account users' group memberships to their peers.
|
||||||
// Returns true if any groups were modified, true if those updates affect peers and an error.
|
// Returns true if any groups were modified, true if those updates affect peers and an error.
|
||||||
func propagateUserGroupMemberships(ctx context.Context, transaction store.Store, accountID string) (groupsUpdated bool, peersAffected bool, err error) {
|
func propagateUserGroupMemberships(ctx context.Context, transaction store.Store, accountID string) (groupsUpdated bool, peersAffected bool, err error) {
|
||||||
groups, err := transaction.GetAccountGroups(ctx, store.LockingStrengthUpdate, accountID)
|
groups, err := transaction.GetAccountGroups(ctx, store.LockingStrengthShare, accountID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, false, err
|
return false, false, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2617,6 +2617,7 @@ func TestAccount_GetNextInactivePeerExpiration(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAccount_SetJWTGroups(t *testing.T) {
|
func TestAccount_SetJWTGroups(t *testing.T) {
|
||||||
|
t.Setenv("NETBIRD_STORE_ENGINE", "postgres")
|
||||||
manager, err := createManager(t)
|
manager, err := createManager(t)
|
||||||
require.NoError(t, err, "unable to create account manager")
|
require.NoError(t, err, "unable to create account manager")
|
||||||
|
|
||||||
|
|||||||
@@ -460,7 +460,7 @@ func (s *SqlStore) SaveGroups(ctx context.Context, lockStrength LockingStrength,
|
|||||||
}
|
}
|
||||||
|
|
||||||
return s.db.Transaction(func(tx *gorm.DB) error {
|
return s.db.Transaction(func(tx *gorm.DB) error {
|
||||||
result := tx.Session(&gorm.Session{FullSaveAssociations: true}).
|
result := tx.
|
||||||
Clauses(
|
Clauses(
|
||||||
clause.Locking{Strength: string(lockStrength)},
|
clause.Locking{Strength: string(lockStrength)},
|
||||||
clause.OnConflict{
|
clause.OnConflict{
|
||||||
@@ -475,8 +475,6 @@ func (s *SqlStore) SaveGroups(ctx context.Context, lockStrength LockingStrength,
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, g := range groups {
|
for _, g := range groups {
|
||||||
g.StoreGroupPeers()
|
|
||||||
|
|
||||||
if err := tx.Model(&g).
|
if err := tx.Model(&g).
|
||||||
Association("GroupPeers").
|
Association("GroupPeers").
|
||||||
Replace(g.GroupPeers); err != nil {
|
Replace(g.GroupPeers); err != nil {
|
||||||
|
|||||||
@@ -1371,12 +1371,11 @@ func TestSqlStore_SaveGroups(t *testing.T) {
|
|||||||
GroupPeers: []types.GroupPeer{},
|
GroupPeers: []types.GroupPeer{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ID: "group-2",
|
ID: "group-2",
|
||||||
AccountID: accountID,
|
AccountID: accountID,
|
||||||
Issued: "integration",
|
Issued: "integration",
|
||||||
Peers: []string{"peer3", "peer4"},
|
Peers: []string{"peer3", "peer4"},
|
||||||
Resources: []types.Resource{},
|
Resources: []types.Resource{},
|
||||||
GroupPeers: []types.GroupPeer{},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
err = store.SaveGroups(context.Background(), LockingStrengthUpdate, accountID, groups)
|
err = store.SaveGroups(context.Background(), LockingStrengthUpdate, accountID, groups)
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ func (g *Group) LoadGroupPeers() {
|
|||||||
for i, peer := range g.GroupPeers {
|
for i, peer := range g.GroupPeers {
|
||||||
g.Peers[i] = peer.PeerID
|
g.Peers[i] = peer.PeerID
|
||||||
}
|
}
|
||||||
g.GroupPeers = nil
|
g.GroupPeers = []GroupPeer{}
|
||||||
}
|
}
|
||||||
func (g *Group) StoreGroupPeers() {
|
func (g *Group) StoreGroupPeers() {
|
||||||
g.GroupPeers = make([]GroupPeer, len(g.Peers))
|
g.GroupPeers = make([]GroupPeer, len(g.Peers))
|
||||||
@@ -55,7 +55,7 @@ func (g *Group) StoreGroupPeers() {
|
|||||||
PeerID: peer,
|
PeerID: peer,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g.Peers = nil
|
g.Peers = []string{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// EventMeta returns activity event meta related to the group
|
// EventMeta returns activity event meta related to the group
|
||||||
|
|||||||
Reference in New Issue
Block a user