1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-12 06:23:38 +00:00
This commit is contained in:
Bernd Schoolmann
2025-07-18 00:15:11 +02:00
parent bc2b075363
commit d5dbab1f0e
2 changed files with 8 additions and 43 deletions

View File

@@ -13,8 +13,8 @@ import { MasterKey, UserKey } from "../../../types/key";
import { EncString } from "../../crypto/models/enc-string";
import { InternalMasterPasswordServiceAbstraction } from "../abstractions/master-password.service.abstraction";
import {
MasterKeyWrappedUserKey,
MasterPasswordAuthenticationData,
MasterPasswordSalt,
MasterPasswordUnlockData,
} from "../types/master-password.types";
@@ -84,7 +84,7 @@ export class FakeMasterPasswordService implements InternalMasterPasswordServiceA
makeMasterPasswordAuthenticationData(
password: string,
kdf: KdfConfig,
salt: string,
salt: MasterPasswordSalt,
userId: UserId,
): Promise<MasterPasswordAuthenticationData> {
return this.mock.makeMasterPasswordAuthenticationData(password, kdf, salt, userId);
@@ -93,21 +93,12 @@ export class FakeMasterPasswordService implements InternalMasterPasswordServiceA
makeMasterPasswordUnlockData(
password: string,
kdf: KdfConfig,
salt: string,
salt: MasterPasswordSalt,
userKey: UserKey,
): Promise<MasterPasswordUnlockData> {
return this.mock.makeMasterPasswordUnlockData(password, kdf, salt, userKey);
}
makeMasterKeyWrappedUserKey(
password: string,
kdf: KdfConfig,
salt: string,
userKey: UserKey,
): Promise<MasterKeyWrappedUserKey> {
return this.mock.makeMasterKeyWrappedUserKey(password, kdf, salt, userKey);
}
unwrapUserKeyFromMasterPasswordUnlockData(
password: string,
masterPasswordUnlockData: MasterPasswordUnlockData,

View File

@@ -9,7 +9,6 @@ import { KdfConfig, KdfConfigService, PBKDF2KdfConfig } from "@bitwarden/key-man
import {
FakeAccountService,
makeEncString,
makeSymmetricCryptoKey,
mockAccountServiceWith,
} from "../../../../spec";
@@ -254,37 +253,12 @@ describe("MasterPasswordService", () => {
const userKey = makeSymmetricCryptoKey(64, 2) as UserKey;
it("wraps and unwraps user key with password", async () => {
const wrappedKey = await sut.makeMasterKeyWrappedUserKey(password, kdf, salt, userKey);
const unwrappedUserkey = await sut.unwrapUserKeyFromMasterPasswordUnlockData(password, {
kdf,
salt,
masterKeyWrappedUserKey: wrappedKey,
});
const unlockData = await sut.makeMasterPasswordUnlockData(password, kdf, salt, userKey);
const unwrappedUserkey = await sut.unwrapUserKeyFromMasterPasswordUnlockData(
password,
unlockData,
);
expect(unwrappedUserkey).toEqual(userKey);
});
});
describe("makeMasterPasswordUnlockData", () => {
const password = "test-password";
const kdf: KdfConfig = new PBKDF2KdfConfig(600_000);
const salt = "test@bitwarden.com" as MasterPasswordSalt;
const userKey = makeSymmetricCryptoKey(32, 2) as UserKey;
beforeEach(() => {
jest
.spyOn(sut, "makeMasterKeyWrappedUserKey")
.mockResolvedValue(makeEncString("wrapped-key") as any);
});
it("returns MasterPasswordUnlockData with correct fields", async () => {
const result = await sut.makeMasterPasswordUnlockData(password, kdf, salt, userKey);
expect(sut.makeMasterKeyWrappedUserKey).toHaveBeenCalledWith(password, kdf, salt, userKey);
expect(result).toEqual({
salt,
kdf,
masterKeyWrappedUserKey: makeEncString("wrapped-key"),
});
});
});
});