mirror of
https://github.com/netbirdio/netbird.git
synced 2025-06-20 17:58:02 +02:00
[management] Delete service users with account manager (#3793)
This commit is contained in:
parent
ac135ab11d
commit
ebda0fc538
@ -603,11 +603,15 @@ func (am *DefaultAccountManager) DeleteAccount(ctx context.Context, accountID, u
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, otherUser := range account.Users {
|
for _, otherUser := range account.Users {
|
||||||
if otherUser.IsServiceUser {
|
if otherUser.Id == userID {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if otherUser.Id == userID {
|
if otherUser.IsServiceUser {
|
||||||
|
err = am.deleteServiceUser(ctx, accountID, userID, otherUser)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -853,6 +853,42 @@ func TestAccountManager_DeleteAccount(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
account.Users["service-user-1"] = &types.User{
|
||||||
|
Id: "service-user-1",
|
||||||
|
Role: types.UserRoleAdmin,
|
||||||
|
IsServiceUser: true,
|
||||||
|
Issued: types.UserIssuedAPI,
|
||||||
|
PATs: map[string]*types.PersonalAccessToken{
|
||||||
|
"pat-1": {
|
||||||
|
ID: "pat-1",
|
||||||
|
UserID: "service-user-1",
|
||||||
|
Name: "service-user-1",
|
||||||
|
HashedToken: "hashedToken",
|
||||||
|
CreatedAt: time.Now(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
account.Users[userId] = &types.User{
|
||||||
|
Id: "service-user-2",
|
||||||
|
Role: types.UserRoleUser,
|
||||||
|
IsServiceUser: true,
|
||||||
|
Issued: types.UserIssuedAPI,
|
||||||
|
PATs: map[string]*types.PersonalAccessToken{
|
||||||
|
"pat-2": {
|
||||||
|
ID: "pat-2",
|
||||||
|
UserID: userId,
|
||||||
|
Name: userId,
|
||||||
|
HashedToken: "hashedToken",
|
||||||
|
CreatedAt: time.Now(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
err = manager.Store.SaveAccount(context.Background(), account)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
err = manager.DeleteAccount(context.Background(), account.Id, userId)
|
err = manager.DeleteAccount(context.Background(), account.Id, userId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@ -862,6 +898,14 @@ func TestAccountManager_DeleteAccount(t *testing.T) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal(fmt.Errorf("expected to get an error when trying to get deleted account, got %v", getAccount))
|
t.Fatal(fmt.Errorf("expected to get an error when trying to get deleted account, got %v", getAccount))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pats, err := manager.Store.GetUserPATs(context.Background(), store.LockingStrengthShare, "service-user-1")
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Len(t, pats, 0)
|
||||||
|
|
||||||
|
pats, err = manager.Store.GetUserPATs(context.Background(), store.LockingStrengthShare, userId)
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Len(t, pats, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkTest_GetAccountWithclaims(b *testing.B) {
|
func BenchmarkTest_GetAccountWithclaims(b *testing.B) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user