add tests for storePinKeyEncryptedUserKey()
This commit is contained in:
parent
00e305ce6f
commit
dec5a561e2
|
@ -123,7 +123,7 @@ describe("PinService", () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("get/clear/create pinKeyEncryptedUserKey methods", () => {
|
describe("get/clear/create/store pinKeyEncryptedUserKey methods", () => {
|
||||||
describe("getPinKeyEncryptedUserKey()", () => {
|
describe("getPinKeyEncryptedUserKey()", () => {
|
||||||
it("should get the pinKeyEncryptedUserKey of the specified userId", async () => {
|
it("should get the pinKeyEncryptedUserKey of the specified userId", async () => {
|
||||||
await sut.getPinKeyEncryptedUserKey(mockUserId);
|
await sut.getPinKeyEncryptedUserKey(mockUserId);
|
||||||
|
@ -176,6 +176,48 @@ describe("PinService", () => {
|
||||||
sut.createPinKeyEncryptedUserKey(mockPin, undefined, mockUserId),
|
sut.createPinKeyEncryptedUserKey(mockPin, undefined, mockUserId),
|
||||||
).rejects.toThrow("No UserKey provided. Cannot create pinKeyEncryptedUserKey.");
|
).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()", () => {
|
describe("makePinKey()", () => {
|
||||||
it("should make a PinKey", async () => {
|
it("should make a PinKey", async () => {
|
||||||
keyGenerationService.deriveKeyFromPassword.mockResolvedValue(mockPinKey);
|
keyGenerationService.deriveKeyFromPassword.mockResolvedValue(mockPinKey);
|
||||||
|
|
Loading…
Reference in New Issue