mirror of
https://github.com/bitwarden/browser
synced 2025-12-19 01:33:33 +00:00
[PM-22133] Require userID for clearStoredUserKey (#14973)
This commit is contained in:
@@ -410,6 +410,45 @@ describe("keyService", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("clearStoredUserKey", () => {
|
||||
describe("input validation", () => {
|
||||
const invalidUserIdTestCases = [
|
||||
{ keySuffix: KeySuffixOptions.Auto, userId: null as unknown as UserId },
|
||||
{ keySuffix: KeySuffixOptions.Auto, userId: undefined as unknown as UserId },
|
||||
{ keySuffix: KeySuffixOptions.Pin, userId: null as unknown as UserId },
|
||||
{ keySuffix: KeySuffixOptions.Pin, userId: undefined as unknown as UserId },
|
||||
];
|
||||
test.each(invalidUserIdTestCases)(
|
||||
"throws when keySuffix is $keySuffix and userId is $userId",
|
||||
async ({ keySuffix, userId }) => {
|
||||
await expect(keyService.clearStoredUserKey(keySuffix, userId)).rejects.toThrow(
|
||||
"UserId is required",
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe("with Auto key suffix", () => {
|
||||
it("UserKeyAutoUnlock is cleared and pin keys are not cleared", async () => {
|
||||
await keyService.clearStoredUserKey(KeySuffixOptions.Auto, mockUserId);
|
||||
|
||||
expect(stateService.setUserKeyAutoUnlock).toHaveBeenCalledWith(null, {
|
||||
userId: mockUserId,
|
||||
});
|
||||
expect(pinService.clearPinKeyEncryptedUserKeyEphemeral).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("with PIN key suffix", () => {
|
||||
it("pin keys are cleared and user key auto unlock not", async () => {
|
||||
await keyService.clearStoredUserKey(KeySuffixOptions.Pin, mockUserId);
|
||||
|
||||
expect(stateService.setUserKeyAutoUnlock).not.toHaveBeenCalled();
|
||||
expect(pinService.clearPinKeyEncryptedUserKeyEphemeral).toHaveBeenCalledWith(mockUserId);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("clearKeys", () => {
|
||||
test.each([null as unknown as UserId, undefined as unknown as UserId])(
|
||||
"throws when the provided userId is %s",
|
||||
|
||||
Reference in New Issue
Block a user