mirror of
https://github.com/bitwarden/browser
synced 2026-02-04 10:43:47 +00:00
Update legacy kdf state on master password unlock sync
This commit is contained in:
@@ -3,7 +3,7 @@ import { of } from "rxjs";
|
||||
|
||||
import { newGuid } from "@bitwarden/guid";
|
||||
// eslint-disable-next-line no-restricted-imports
|
||||
import { Argon2KdfConfig, KeyService } from "@bitwarden/key-management";
|
||||
import { Argon2KdfConfig, KdfConfigService, KeyService } from "@bitwarden/key-management";
|
||||
import { UserId } from "@bitwarden/user-core";
|
||||
|
||||
import { HashPurpose } from "../../../platform/enums";
|
||||
@@ -23,6 +23,7 @@ describe("DefaultMasterPasswordUnlockService", () => {
|
||||
|
||||
let masterPasswordService: MockProxy<InternalMasterPasswordServiceAbstraction>;
|
||||
let keyService: MockProxy<KeyService>;
|
||||
let kdfService: MockProxy<KdfConfigService>;
|
||||
|
||||
const mockMasterPassword = "testExample";
|
||||
const mockUserId = newGuid() as UserId;
|
||||
@@ -41,8 +42,9 @@ describe("DefaultMasterPasswordUnlockService", () => {
|
||||
beforeEach(() => {
|
||||
masterPasswordService = mock<InternalMasterPasswordServiceAbstraction>();
|
||||
keyService = mock<KeyService>();
|
||||
kdfService = mock<KdfConfigService>();
|
||||
|
||||
sut = new DefaultMasterPasswordUnlockService(masterPasswordService, keyService);
|
||||
sut = new DefaultMasterPasswordUnlockService(masterPasswordService, keyService, kdfService);
|
||||
|
||||
masterPasswordService.masterPasswordUnlockData$.mockReturnValue(
|
||||
of(mockMasterPasswordUnlockData),
|
||||
@@ -126,6 +128,10 @@ describe("DefaultMasterPasswordUnlockService", () => {
|
||||
);
|
||||
expect(masterPasswordService.setMasterKeyHash).toHaveBeenCalledWith(mockKeyHash, mockUserId);
|
||||
expect(masterPasswordService.setMasterKey).toHaveBeenCalledWith(mockMasterKey, mockUserId);
|
||||
expect(kdfService.setKdfConfig).toHaveBeenCalledWith(
|
||||
mockUserId,
|
||||
mockMasterPasswordUnlockData.kdf,
|
||||
);
|
||||
});
|
||||
|
||||
it("throws an error if masterKey construction fails", async () => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { firstValueFrom } from "rxjs";
|
||||
|
||||
// eslint-disable-next-line no-restricted-imports
|
||||
import { KeyService } from "@bitwarden/key-management";
|
||||
import { KdfConfigService, KeyService } from "@bitwarden/key-management";
|
||||
import { UserId } from "@bitwarden/user-core";
|
||||
|
||||
import { HashPurpose } from "../../../platform/enums";
|
||||
@@ -14,6 +14,7 @@ export class DefaultMasterPasswordUnlockService implements MasterPasswordUnlockS
|
||||
constructor(
|
||||
private readonly masterPasswordService: InternalMasterPasswordServiceAbstraction,
|
||||
private readonly keyService: KeyService,
|
||||
private readonly kdfService: KdfConfigService,
|
||||
) {}
|
||||
|
||||
async unlockWithMasterPassword(masterPassword: string, userId: UserId): Promise<UserKey> {
|
||||
@@ -71,5 +72,6 @@ export class DefaultMasterPasswordUnlockService implements MasterPasswordUnlockS
|
||||
|
||||
await this.masterPasswordService.setMasterKeyHash(localKeyHash, userId);
|
||||
await this.masterPasswordService.setMasterKey(masterKey, userId);
|
||||
await this.kdfService.setKdfConfig(userId, masterPasswordUnlockData.kdf);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user