mirror of
https://github.com/bitwarden/browser
synced 2025-12-15 15:53:27 +00:00
feat(auth-tech-debt): [PM-24103] Remove Get User Key to UserKey$ (#16589)
* fix(auth-tech-debt): [PM-24103] Remove Get User Key to UserKey$ - Fixed and updated tests. * fix(auth-tech-debt): [PM-24103] Remove Get User Key to UserKey$ - Fixed test variable being made more vague.
This commit is contained in:
committed by
GitHub
parent
9b2fbdba1c
commit
94cb1fe07b
@@ -17,6 +17,7 @@ import { CsprngArray } from "@bitwarden/common/types/csprng";
|
||||
import { UserId } from "@bitwarden/common/types/guid";
|
||||
import { UserKey, MasterKey, UserPrivateKey } from "@bitwarden/common/types/key";
|
||||
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
||||
import { newGuid } from "@bitwarden/guid";
|
||||
import { Argon2KdfConfig, KdfType, KeyService, PBKDF2KdfConfig } from "@bitwarden/key-management";
|
||||
|
||||
import { EmergencyAccessStatusType } from "../enums/emergency-access-status-type";
|
||||
@@ -44,6 +45,7 @@ describe("EmergencyAccessService", () => {
|
||||
|
||||
const mockNewUserKey = new SymmetricCryptoKey(new Uint8Array(64)) as UserKey;
|
||||
const mockTrustedPublicKeys = [Utils.fromUtf8ToArray("trustedPublicKey")];
|
||||
const mockUserId = newGuid() as UserId;
|
||||
|
||||
beforeAll(() => {
|
||||
emergencyAccessApiService = mock<EmergencyAccessApiService>();
|
||||
@@ -125,7 +127,7 @@ describe("EmergencyAccessService", () => {
|
||||
"mockUserPublicKeyEncryptedUserKey",
|
||||
);
|
||||
|
||||
keyService.getUserKey.mockResolvedValueOnce(mockUserKey);
|
||||
keyService.userKey$.mockReturnValue(of(mockUserKey));
|
||||
|
||||
encryptService.encapsulateKeyUnsigned.mockResolvedValueOnce(
|
||||
mockUserPublicKeyEncryptedUserKey,
|
||||
@@ -134,7 +136,7 @@ describe("EmergencyAccessService", () => {
|
||||
emergencyAccessApiService.postEmergencyAccessConfirm.mockResolvedValueOnce();
|
||||
|
||||
// Act
|
||||
await emergencyAccessService.confirm(id, granteeId, publicKey);
|
||||
await emergencyAccessService.confirm(id, granteeId, publicKey, mockUserId);
|
||||
|
||||
// Assert
|
||||
expect(emergencyAccessApiService.postEmergencyAccessConfirm).toHaveBeenCalledWith(id, {
|
||||
|
||||
@@ -175,11 +175,17 @@ export class EmergencyAccessService
|
||||
* Step 3 of the 3 step setup flow.
|
||||
* Intended for grantor.
|
||||
* @param id emergency access id
|
||||
* @param token secret token provided in email
|
||||
* @param granteeId id of the grantee
|
||||
* @param publicKey public key of grantee
|
||||
* @param activeUserId the active user's id
|
||||
*/
|
||||
async confirm(id: string, granteeId: string, publicKey: Uint8Array): Promise<void> {
|
||||
const userKey = await this.keyService.getUserKey();
|
||||
async confirm(
|
||||
id: string,
|
||||
granteeId: string,
|
||||
publicKey: Uint8Array,
|
||||
activeUserId: UserId,
|
||||
): Promise<void> {
|
||||
const userKey = await firstValueFrom(this.keyService.userKey$(activeUserId));
|
||||
if (!userKey) {
|
||||
throw new Error("No user key found");
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// FIXME: Update this file to be type safe and remove this and next line
|
||||
// @ts-strict-ignore
|
||||
import { Component, OnInit } from "@angular/core";
|
||||
import { lastValueFrom, Observable, firstValueFrom, switchMap } from "rxjs";
|
||||
import { lastValueFrom, Observable, firstValueFrom, switchMap, map } from "rxjs";
|
||||
|
||||
import { PremiumBadgeComponent } from "@bitwarden/angular/billing/components/premium-badge";
|
||||
import { UserNamePipe } from "@bitwarden/angular/pipes/user-name.pipe";
|
||||
@@ -165,7 +165,15 @@ export class EmergencyAccessComponent implements OnInit {
|
||||
});
|
||||
const result = await lastValueFrom(dialogRef.closed);
|
||||
if (result === EmergencyAccessConfirmDialogResult.Confirmed) {
|
||||
await this.emergencyAccessService.confirm(contact.id, contact.granteeId, publicKey);
|
||||
const activeUserId = await firstValueFrom(
|
||||
this.accountService.activeAccount$.pipe(getUserId),
|
||||
);
|
||||
await this.emergencyAccessService.confirm(
|
||||
contact.id,
|
||||
contact.granteeId,
|
||||
publicKey,
|
||||
activeUserId,
|
||||
);
|
||||
updateUser();
|
||||
this.toastService.showToast({
|
||||
variant: "success",
|
||||
@@ -176,10 +184,14 @@ export class EmergencyAccessComponent implements OnInit {
|
||||
return;
|
||||
}
|
||||
|
||||
const activeUserId = await firstValueFrom(
|
||||
this.accountService.activeAccount$.pipe(map((a) => a?.id)),
|
||||
);
|
||||
this.actionPromise = this.emergencyAccessService.confirm(
|
||||
contact.id,
|
||||
contact.granteeId,
|
||||
publicKey,
|
||||
activeUserId,
|
||||
);
|
||||
await this.actionPromise;
|
||||
updateUser();
|
||||
|
||||
Reference in New Issue
Block a user