Skip to content

Commit

Permalink
Fixing account equality (#3220)
Browse files Browse the repository at this point in the history
Fixing account equality
  • Loading branch information
BovineOx authored Mar 12, 2024
1 parent cbe6511 commit 9a3e689
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 7 additions & 2 deletions Core/Core/Credentials/AccountManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,10 @@ public static void UpgradeAccount(string id)
account.serverInfo.url = upgradeUri.ToString().TrimEnd('/');
account.serverInfo.frontend2 = true;

s_accountStorage.UpdateObject(account.id, JsonConvert.SerializeObject(account));
// setting the id to null will force it to be recreated
account.id = null;

s_accountStorage.UpdateObject(account.id!, JsonConvert.SerializeObject(account));
}

/// <summary>
Expand All @@ -281,7 +284,9 @@ public static IEnumerable<Account> GetAccounts(string serverUrl)

foreach (var acc in accounts)
{
if (acc.serverInfo.url == serverUrl && !filtered.Any(x => x.id != acc.id))
// we use the userInfo to detect the same account rather than the account.id
// which should NOT match for essentially the same accounts but on different servers - i.e. FE1 & FE2
if (acc.serverInfo.url == serverUrl && !filtered.Any(x => x.userInfo.id == acc.userInfo.id))
{
filtered.Add(acc);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public static IEnumerable<TestCaseData> MigrationTestCase()
Account newAccount = CreateTestAccount(NEW_URL, new(OLD_URL), null);
Account otherAccount = CreateTestAccount(OTHER_URL, null, null);

// new account user must match old account user id
newAccount.userInfo.id = oldAccount.userInfo.id;

List<Account> givenAccounts = new() { oldAccount, newAccount, otherAccount };

yield return new TestCaseData(givenAccounts, NEW_URL, new[] { newAccount })
Expand Down Expand Up @@ -69,7 +72,7 @@ private static Account CreateTestAccount(string url, Uri movedFrom, Uri movedTo)
},
userInfo = new UserInfo
{
id = new Guid().ToString(),
id = Guid.NewGuid().ToString(),
email = "[email protected]",
name = "user"
}
Expand Down

0 comments on commit 9a3e689

Please sign in to comment.