mirror of
https://github.com/bitwarden/browser
synced 2025-12-15 07:43:35 +00:00
[PM-21912] Require userID for KeyService's hasUserKey (#14890)
* Update keyService hasUserKey to require userId and remove unused/duplicate methods * Update lock component consumer * Update send commands to pass in userId * update SSO login to pass in userID * Update bw serve to pass in userID * remove unneeded method from electron-key.service
This commit is contained in:
@@ -54,7 +54,7 @@ export abstract class SendService implements UserKeyRotationDataProvider<SendWit
|
||||
/**
|
||||
* @deprecated Only use in CLI
|
||||
*/
|
||||
getAllDecryptedFromState: () => Promise<SendView[]>;
|
||||
getAllDecryptedFromState: (userId: UserId) => Promise<SendView[]>;
|
||||
}
|
||||
|
||||
export abstract class InternalSendService extends SendService {
|
||||
|
||||
@@ -467,10 +467,21 @@ describe("SendService", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("getAllDecryptedFromState", async () => {
|
||||
const sends = await sendService.getAllDecryptedFromState();
|
||||
describe("getAllDecryptedFromState", () => {
|
||||
it("returns already decrypted sends in state", async () => {
|
||||
const sends = await sendService.getAllDecryptedFromState(mockUserId);
|
||||
|
||||
expect(sends[0]).toMatchObject(testSendViewData("1", "Test Send"));
|
||||
expect(sends[0]).toMatchObject(testSendViewData("1", "Test Send"));
|
||||
});
|
||||
|
||||
it("throws if no decrypted sends in state and there is no userKey", async () => {
|
||||
decryptedState.nextState(null);
|
||||
keyService.hasUserKey.mockResolvedValue(false);
|
||||
|
||||
await expect(sendService.getAllDecryptedFromState(mockUserId)).rejects.toThrow(
|
||||
"No user key found.",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getRotatedData", () => {
|
||||
|
||||
@@ -199,14 +199,14 @@ export class SendService implements InternalSendServiceAbstraction {
|
||||
return response;
|
||||
}
|
||||
|
||||
async getAllDecryptedFromState(): Promise<SendView[]> {
|
||||
async getAllDecryptedFromState(userId: UserId): Promise<SendView[]> {
|
||||
let decSends = await this.stateProvider.getDecryptedSends();
|
||||
if (decSends != null) {
|
||||
return decSends;
|
||||
}
|
||||
|
||||
decSends = [];
|
||||
const hasKey = await this.keyService.hasUserKey();
|
||||
const hasKey = await this.keyService.hasUserKey(userId);
|
||||
if (!hasKey) {
|
||||
throw new Error("No user key found.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user