mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-29 12:55:21 +01:00
Correct and test changeover point for userId source in storage migration (#8990)
This commit is contained in:
parent
3acbffa072
commit
200b0f7534
@ -235,6 +235,11 @@ export function mockMigrationHelper(
|
|||||||
helper.setToUser(userId, keyDefinition, value),
|
helper.setToUser(userId, keyDefinition, value),
|
||||||
);
|
);
|
||||||
mockHelper.getAccounts.mockImplementation(() => helper.getAccounts());
|
mockHelper.getAccounts.mockImplementation(() => helper.getAccounts());
|
||||||
|
mockHelper.getKnownUserIds.mockImplementation(() => helper.getKnownUserIds());
|
||||||
|
mockHelper.removeFromGlobal.mockImplementation((keyDefinition) =>
|
||||||
|
helper.removeFromGlobal(keyDefinition),
|
||||||
|
);
|
||||||
|
mockHelper.remove.mockImplementation((key) => helper.remove(key));
|
||||||
|
|
||||||
mockHelper.type = helper.type;
|
mockHelper.type = helper.type;
|
||||||
|
|
||||||
|
@ -175,8 +175,8 @@ export class MigrationHelper {
|
|||||||
* Helper method to read known users ids.
|
* Helper method to read known users ids.
|
||||||
*/
|
*/
|
||||||
async getKnownUserIds(): Promise<string[]> {
|
async getKnownUserIds(): Promise<string[]> {
|
||||||
if (this.currentVersion < 61) {
|
if (this.currentVersion < 60) {
|
||||||
return knownAccountUserIdsBuilderPre61(this.storageService);
|
return knownAccountUserIdsBuilderPre60(this.storageService);
|
||||||
} else {
|
} else {
|
||||||
return knownAccountUserIdsBuilder(this.storageService);
|
return knownAccountUserIdsBuilder(this.storageService);
|
||||||
}
|
}
|
||||||
@ -245,7 +245,7 @@ function globalKeyBuilderPre9(): string {
|
|||||||
throw Error("No key builder should be used for versions prior to 9.");
|
throw Error("No key builder should be used for versions prior to 9.");
|
||||||
}
|
}
|
||||||
|
|
||||||
async function knownAccountUserIdsBuilderPre61(
|
async function knownAccountUserIdsBuilderPre60(
|
||||||
storageService: AbstractStorageService,
|
storageService: AbstractStorageService,
|
||||||
): Promise<string[]> {
|
): Promise<string[]> {
|
||||||
return (await storageService.get<string[]>("authenticatedAccounts")) ?? [];
|
return (await storageService.get<string[]>("authenticatedAccounts")) ?? [];
|
||||||
|
@ -51,19 +51,15 @@ const rollbackJson = () => {
|
|||||||
},
|
},
|
||||||
global_account_accounts: {
|
global_account_accounts: {
|
||||||
user1: {
|
user1: {
|
||||||
profile: {
|
|
||||||
email: "user1",
|
email: "user1",
|
||||||
name: "User 1",
|
name: "User 1",
|
||||||
emailVerified: true,
|
emailVerified: true,
|
||||||
},
|
},
|
||||||
},
|
|
||||||
user2: {
|
user2: {
|
||||||
profile: {
|
|
||||||
email: "",
|
email: "",
|
||||||
emailVerified: false,
|
emailVerified: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
global_account_activeAccountId: "user1",
|
global_account_activeAccountId: "user1",
|
||||||
global_account_activity: {
|
global_account_activity: {
|
||||||
user1: "2021-01-01T00:00:00.000Z",
|
user1: "2021-01-01T00:00:00.000Z",
|
||||||
|
@ -38,8 +38,8 @@ export class KnownAccountsMigrator extends Migrator<59, 60> {
|
|||||||
}
|
}
|
||||||
async rollback(helper: MigrationHelper): Promise<void> {
|
async rollback(helper: MigrationHelper): Promise<void> {
|
||||||
// authenticated account are removed, but the accounts record also contains logged out accounts. Best we can do is to add them all back
|
// authenticated account are removed, but the accounts record also contains logged out accounts. Best we can do is to add them all back
|
||||||
const accounts = (await helper.getFromGlobal<Record<string, unknown>>(ACCOUNT_ACCOUNTS)) ?? {};
|
const userIds = (await helper.getKnownUserIds()) ?? [];
|
||||||
await helper.set("authenticatedAccounts", Object.keys(accounts));
|
await helper.set("authenticatedAccounts", userIds);
|
||||||
await helper.removeFromGlobal(ACCOUNT_ACCOUNTS);
|
await helper.removeFromGlobal(ACCOUNT_ACCOUNTS);
|
||||||
|
|
||||||
// Active Account Id
|
// Active Account Id
|
||||||
|
Loading…
Reference in New Issue
Block a user