add tests for storePinKeyEncryptedUserKey()

This commit is contained in:
rr-bw 2024-05-01 17:08:55 -07:00
parent 00e305ce6f
commit dec5a561e2
No known key found for this signature in database
GPG Key ID: 3FA13C3ADEE51D5D
1 changed files with 43 additions and 11 deletions

View File

@ -123,7 +123,7 @@ describe("PinService", () => {
});
});
describe("get/clear/create pinKeyEncryptedUserKey methods", () => {
describe("get/clear/create/store pinKeyEncryptedUserKey methods", () => {
describe("getPinKeyEncryptedUserKey()", () => {
it("should get the pinKeyEncryptedUserKey of the specified userId", async () => {
await sut.getPinKeyEncryptedUserKey(mockUserId);
@ -176,6 +176,48 @@ describe("PinService", () => {
sut.createPinKeyEncryptedUserKey(mockPin, undefined, mockUserId),
).rejects.toThrow("No UserKey provided. Cannot create pinKeyEncryptedUserKey.");
});
it("should create a pinKeyEncryptedUserKey", async () => {
sut.makePinKey = jest.fn().mockResolvedValue(mockPinKey);
await sut.createPinKeyEncryptedUserKey(mockPin, mockUserKey, mockUserId);
expect(encryptService.encrypt).toHaveBeenCalledWith(mockUserKey.key, mockPinKey);
});
});
describe("storePinKeyEncryptedUserKey", () => {
it("should store a pinKeyEncryptedUserKey (persistent version) when 'storeAsEphemeral' is false", async () => {
const storeAsEphemeral = false;
await sut.storePinKeyEncryptedUserKey(
pinKeyEncryptedUserKeyPersistant,
storeAsEphemeral,
mockUserId,
);
expect(stateProvider.mock.setUserState).toHaveBeenCalledWith(
PIN_KEY_ENCRYPTED_USER_KEY,
pinKeyEncryptedUserKeyPersistant.encryptedString,
mockUserId,
);
});
it("should store a pinKeyEncryptedUserKeyEphemeral when 'storeAsEphemeral' is true", async () => {
const storeAsEphemeral = true;
await sut.storePinKeyEncryptedUserKey(
pinKeyEncryptedUserKeyEphemeral,
storeAsEphemeral,
mockUserId,
);
expect(stateProvider.mock.setUserState).toHaveBeenCalledWith(
PIN_KEY_ENCRYPTED_USER_KEY_EPHEMERAL,
pinKeyEncryptedUserKeyEphemeral.encryptedString,
mockUserId,
);
});
});
});
@ -243,16 +285,6 @@ describe("PinService", () => {
});
});
describe("createPinKeyEncryptedUserKey()", () => {
it("should create a pinKeyEncryptedUserKey", async () => {
sut.makePinKey = jest.fn().mockResolvedValue(mockPinKey);
await sut.createPinKeyEncryptedUserKey(mockPin, mockUserKey, mockUserId);
expect(encryptService.encrypt).toHaveBeenCalledWith(mockUserKey.key, mockPinKey);
});
});
describe("makePinKey()", () => {
it("should make a PinKey", async () => {
keyGenerationService.deriveKeyFromPassword.mockResolvedValue(mockPinKey);