mirror of
https://github.com/netbirdio/netbird.git
synced 2025-08-15 01:32:56 +02:00
switch PATs to map and add deletion
This commit is contained in:
@ -51,7 +51,7 @@ func TestUser_AddPATToUser(t *testing.T) {
|
||||
LastUsed: time.Time{},
|
||||
}
|
||||
|
||||
err = am.AddPATToUser("account_id", "testuser", pat)
|
||||
err = am.AddPATToUser("account_id", "testuser", &pat)
|
||||
if err != nil {
|
||||
t.Fatalf("Error when adding PAT to user: %s", err)
|
||||
}
|
||||
@ -71,3 +71,60 @@ func TestUser_AddPATToUser(t *testing.T) {
|
||||
}
|
||||
assert.Equal(t, "testuser", userID)
|
||||
}
|
||||
|
||||
func TestUser_DeletePAT(t *testing.T) {
|
||||
store := newStore(t)
|
||||
account := newAccountWithId("account_id", "testuser", "")
|
||||
account.Peers["testpeer"] = &Peer{
|
||||
Key: "peerkey",
|
||||
SetupKey: "peerkeysetupkey",
|
||||
IP: net.IP{127, 0, 0, 1},
|
||||
Meta: PeerSystemMeta{},
|
||||
Name: "peer name",
|
||||
Status: &PeerStatus{Connected: true, LastSeen: time.Now()},
|
||||
}
|
||||
account.Users["user1"] = &User{
|
||||
Id: "user1",
|
||||
Role: "admin",
|
||||
AutoGroups: nil,
|
||||
PATs: map[string]*PersonalAccessToken{
|
||||
"tokenID": {
|
||||
ID: "tokenID",
|
||||
Description: "some Description",
|
||||
HashedToken: "SoMeHaShEdToKeN",
|
||||
ExpirationDate: time.Now().AddDate(0, 0, 7),
|
||||
CreatedBy: "user1",
|
||||
CreatedAt: time.Now(),
|
||||
LastUsed: time.Now(),
|
||||
},
|
||||
},
|
||||
}
|
||||
err := store.SaveAccount(account)
|
||||
if err != nil {
|
||||
t.Fatalf("Error when saving account: %s", err)
|
||||
}
|
||||
|
||||
am := DefaultAccountManager{
|
||||
Store: store,
|
||||
cacheMux: sync.Mutex{},
|
||||
cacheLoading: nil,
|
||||
peersUpdateManager: nil,
|
||||
idpManager: nil,
|
||||
cacheManager: nil,
|
||||
ctx: nil,
|
||||
eventStore: nil,
|
||||
singleAccountMode: false,
|
||||
singleAccountModeDomain: "",
|
||||
dnsDomain: "",
|
||||
peerLoginExpiry: nil,
|
||||
}
|
||||
|
||||
err = am.DeletePAT("account_id", "user1", "tokenID")
|
||||
if err != nil {
|
||||
t.Fatalf("Error when adding PAT to user: %s", err)
|
||||
}
|
||||
|
||||
assert.Nil(t, store.Accounts["account_id"].Users["user1"].PATs["tokenID"])
|
||||
assert.Empty(t, store.HashedPAT2TokenID["SoMeHaShEdToKeN"])
|
||||
assert.Empty(t, store.TokenID2UserID["tokenID"])
|
||||
}
|
||||
|
Reference in New Issue
Block a user