Fix setup keys

This commit is contained in:
braginini
2024-04-17 19:48:09 +02:00
parent 41d4dd2aff
commit e6628ec231
2 changed files with 19 additions and 1 deletions

View File

@@ -163,7 +163,10 @@ func (s *SqliteStore) SaveAccount(account *Account) error {
// operate over a fresh copy as we will modify its fields
accCopy := account.Copy()
accCopy.SetupKeysG = make([]SetupKey, 0, len(accCopy.SetupKeys))
for _, key := range accCopy.SetupKeys {
for id, key := range accCopy.SetupKeys {
key.Id = id
//we need an explicit reference to the account as it is missing for some reason
key.AccountID = accCopy.Id
accCopy.SetupKeysG = append(accCopy.SetupKeysG, *key)
}

View File

@@ -107,6 +107,9 @@ func TestSqlite_SaveAccount_Large(t *testing.T) {
SearchDomainsEnabled: false,
}
account.NameServerGroups[nameserver.ID] = nameserver
setupKey := GenerateDefaultSetupKey()
account.SetupKeys[setupKey.Id] = setupKey
}
err = store.SaveAccount(account)
@@ -153,6 +156,18 @@ func TestSqlite_SaveAccount_Large(t *testing.T) {
numPerAccount, len(a.NameServerGroups))
return
}
if a != nil && len(a.NameServerGroups) != numPerAccount {
t.Errorf("expecting Account to have %d NameServerGroups stored after SaveAccount(), got %d",
numPerAccount, len(a.NameServerGroups))
return
}
if a != nil && len(a.SetupKeys) != numPerAccount+1 {
t.Errorf("expecting Account to have %d SetupKeys stored after SaveAccount(), got %d",
numPerAccount+1, len(a.SetupKeys))
return
}
}
func TestSqlite_SaveAccount(t *testing.T) {