fix tests for login strategies, vault-export, and fake MP service

This commit is contained in:
rr-bw 2024-04-25 11:02:37 -07:00
parent 379a674af3
commit d9fed46a04
No known key found for this signature in database
GPG Key ID: 3FA13C3ADEE51D5D
7 changed files with 18 additions and 10 deletions

View File

@ -346,7 +346,7 @@ export class LockComponent implements OnInit, OnDestroy {
this.pinLockType = await this.pinService.getPinLockType(userId);
let ephemeralPinSet = await this.pinService.getPinKeyEncryptedUserKeyEphemeral(userId);
ephemeralPinSet ||= new EncString(await this.pinService.getOldPinKeyEncryptedMasterKey(userId)); // TODO-rr-bw: verify
ephemeralPinSet ||= new EncString(await this.pinService.getOldPinKeyEncryptedMasterKey(userId));
this.pinEnabled =
(this.pinLockType === "EPHEMERAL" && !!ephemeralPinSet) || this.pinLockType === "PERSISTENT";

View File

@ -157,7 +157,7 @@ describe("PasswordLoginStrategy", () => {
const userKey = new SymmetricCryptoKey(new Uint8Array(64).buffer as CsprngArray) as UserKey;
masterPasswordService.masterKeySubject.next(masterKey);
masterPasswordService.decryptUserKeyWithMasterKey.mockResolvedValue(userKey);
masterPasswordService.mock.decryptUserKeyWithMasterKey.mockResolvedValue(userKey);
await passwordLoginStrategy.logIn(credentials);

View File

@ -38,7 +38,7 @@ const PIN_KEY_ENCRYPTED_USER_KEY = new UserKeyDefinition<EncryptedString>(
"pinKeyEncryptedUserKey",
{
deserializer: (jsonValue) => jsonValue,
clearOn: ["logout"], // TODO-rr-bw: verify
clearOn: ["logout"],
},
);
@ -198,19 +198,19 @@ export class PinService implements PinServiceAbstraction {
const pinKey = await this.makePinKey(
pin,
(await firstValueFrom(this.accountService.activeAccount$))?.email, // TODO-rr-bw: verify (could this user possibly be different from the UserId passed in?)
(await firstValueFrom(this.accountService.activeAccount$))?.email,
await this.stateService.getKdfType({ userId }),
await this.stateService.getKdfConfig({ userId }),
);
return await this.encryptService.encrypt(userKey.key, pinKey); // TODO-rr-bw: verify that I can use encryptService.encrypt instead of cryptoService.encrypt
return await this.encryptService.encrypt(userKey.key, pinKey);
}
async createProtectedPin(pin: string, userKey: UserKey) {
if (!userKey) {
throw new Error("No UserKey provided. Cannot create protectedPin.");
}
return await this.encryptService.encrypt(pin, userKey); // TODO-rr-bw: verify that I can use encryptService.encrypt instead of cryptoService.encrypt
return await this.encryptService.encrypt(pin, userKey);
}
async makePinKey(pin: string, salt: string, kdf: KdfType, kdfConfig: KdfConfig): Promise<PinKey> {
@ -439,11 +439,11 @@ export class PinService implements PinServiceAbstraction {
}
case "EPHEMERAL": {
const pinKeyEncryptedUserKey = await this.getPinKeyEncryptedUserKeyEphemeral(userId);
const oldPinKeyEncryptedMasterKey = await this.getOldPinKeyEncryptedMasterKey(userId); // TODO-rr-bw: verify
const oldPinKeyEncryptedMasterKey = await this.getOldPinKeyEncryptedMasterKey(userId);
return {
pinKeyEncryptedUserKey,
oldPinKeyEncryptedMasterKey: oldPinKeyEncryptedMasterKey // TODO-rr-bw: verify
oldPinKeyEncryptedMasterKey: oldPinKeyEncryptedMasterKey
? new EncString(oldPinKeyEncryptedMasterKey)
: undefined,
};

View File

@ -67,6 +67,6 @@ export class FakeMasterPasswordService implements InternalMasterPasswordServiceA
userKey?: EncString,
userId?: string,
): Promise<UserKey> {
return false as any; // TODO-rr-bw
return this.mock.decryptUserKeyWithMasterKey(masterKey, userKey, userId);
}
}

View File

@ -769,7 +769,7 @@ export class CryptoService implements CryptoServiceAbstraction {
await this.pinService.storePinKeyEncryptedUserKey(
pinKeyEncryptedUserKey,
noPreExistingPersistentKey, // TODO-rr-bw: verify
noPreExistingPersistentKey,
userId,
);
// We can't always clear deprecated keys because the pin is only

View File

@ -1,5 +1,6 @@
import { mock, MockProxy } from "jest-mock-extended";
import { PinServiceAbstraction } from "@bitwarden/auth/common";
import { KdfConfig } from "@bitwarden/common/auth/models/domain/kdf-config";
import { CipherWithIdExport } from "@bitwarden/common/models/export/cipher-with-ids.export";
import { CryptoFunctionService } from "@bitwarden/common/platform/abstractions/crypto-function.service";
@ -142,6 +143,7 @@ describe("VaultExportService", () => {
let exportService: IndividualVaultExportService;
let cryptoFunctionService: MockProxy<CryptoFunctionService>;
let cipherService: MockProxy<CipherService>;
let pinService: MockProxy<PinServiceAbstraction>;
let folderService: MockProxy<FolderService>;
let cryptoService: MockProxy<CryptoService>;
let stateService: MockProxy<StateService>;
@ -149,6 +151,7 @@ describe("VaultExportService", () => {
beforeEach(() => {
cryptoFunctionService = mock<CryptoFunctionService>();
cipherService = mock<CipherService>();
pinService = mock<PinServiceAbstraction>();
folderService = mock<FolderService>();
cryptoService = mock<CryptoService>();
stateService = mock<StateService>();
@ -162,6 +165,7 @@ describe("VaultExportService", () => {
exportService = new IndividualVaultExportService(
folderService,
cipherService,
pinService,
cryptoService,
cryptoFunctionService,
stateService,

View File

@ -1,5 +1,6 @@
import { mock, MockProxy } from "jest-mock-extended";
import { PinServiceAbstraction } from "@bitwarden/auth/common";
import { KdfConfig } from "@bitwarden/common/auth/models/domain/kdf-config";
import { CipherWithIdExport } from "@bitwarden/common/models/export/cipher-with-ids.export";
import { CryptoFunctionService } from "@bitwarden/common/platform/abstractions/crypto-function.service";
@ -142,6 +143,7 @@ describe("VaultExportService", () => {
let exportService: IndividualVaultExportService;
let cryptoFunctionService: MockProxy<CryptoFunctionService>;
let cipherService: MockProxy<CipherService>;
let pinService: MockProxy<PinServiceAbstraction>;
let folderService: MockProxy<FolderService>;
let cryptoService: MockProxy<CryptoService>;
let stateService: MockProxy<StateService>;
@ -149,6 +151,7 @@ describe("VaultExportService", () => {
beforeEach(() => {
cryptoFunctionService = mock<CryptoFunctionService>();
cipherService = mock<CipherService>();
pinService = mock<PinServiceAbstraction>();
folderService = mock<FolderService>();
cryptoService = mock<CryptoService>();
stateService = mock<StateService>();
@ -162,6 +165,7 @@ describe("VaultExportService", () => {
exportService = new IndividualVaultExportService(
folderService,
cipherService,
pinService,
cryptoService,
cryptoFunctionService,
stateService,