1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-18 17:23:37 +00:00

[PM-19532] - Add Fingerprint phrase to cli auth request (#14556)

* first pass at adding fingerprint phrase to auth requests

* Moved call to getFingerprint into the service layer. Added a new method for getting auth requests. Updated tests.

* Fixing the import

* Renaming to WithFingerprint
This commit is contained in:
Jared McCannon
2025-05-06 10:50:48 -05:00
committed by GitHub
parent 855dad7fcc
commit 5176345584
7 changed files with 110 additions and 6 deletions

View File

@@ -83,6 +83,64 @@ describe("OrganizationAuthRequestService", () => {
});
});
describe("listPendingRequestsWithDetails", () => {
it("should retrieve the fingerprint phrase for each request and return the new result", async () => {
jest.spyOn(organizationAuthRequestApiService, "listPendingRequests");
const organizationId = "organizationId";
const pendingAuthRequest = new PendingAuthRequestView();
pendingAuthRequest.id = "requestId1";
pendingAuthRequest.userId = "userId1";
pendingAuthRequest.organizationUserId = "userId1";
pendingAuthRequest.email = "email1";
pendingAuthRequest.publicKey = "publicKey1";
pendingAuthRequest.requestDeviceIdentifier = "requestDeviceIdentifier1";
pendingAuthRequest.requestDeviceType = "requestDeviceType1";
pendingAuthRequest.requestIpAddress = "requestIpAddress1";
pendingAuthRequest.creationDate = new Date();
const mockPendingAuthRequests = [pendingAuthRequest];
organizationAuthRequestApiService.listPendingRequests
.calledWith(organizationId)
.mockResolvedValue(mockPendingAuthRequests);
const fingerprintPhrase = ["fingerprint", "phrase"];
keyService.getFingerprint
.calledWith(pendingAuthRequest.email, expect.any(Uint8Array))
.mockResolvedValue(fingerprintPhrase);
const result =
await organizationAuthRequestService.listPendingRequestsWithFingerprint(organizationId);
expect(result).toHaveLength(1);
expect(result).toEqual([
{ ...pendingAuthRequest, fingerprintPhrase: fingerprintPhrase.join("-") },
]);
expect(organizationAuthRequestApiService.listPendingRequests).toHaveBeenCalledWith(
organizationId,
);
});
it("should return empty list if no results and not call keyService", async () => {
jest.spyOn(organizationAuthRequestApiService, "listPendingRequests");
const organizationId = "organizationId";
organizationAuthRequestApiService.listPendingRequests
.calledWith(organizationId)
.mockResolvedValue([]);
const result =
await organizationAuthRequestService.listPendingRequestsWithFingerprint(organizationId);
expect(result).toHaveLength(0);
expect(keyService.getFingerprint).not.toHaveBeenCalled();
expect(organizationAuthRequestApiService.listPendingRequests).toHaveBeenCalledWith(
organizationId,
);
});
});
describe("denyPendingRequests", () => {
it("should deny the specified pending auth requests", async () => {
jest.spyOn(organizationAuthRequestApiService, "denyPendingRequests");

View File

@@ -11,6 +11,7 @@ import { KeyService } from "@bitwarden/key-management";
import { OrganizationAuthRequestApiService } from "./organization-auth-request-api.service";
import { OrganizationAuthRequestUpdateRequest } from "./organization-auth-request-update.request";
import { PendingAuthRequestWithFingerprintView } from "./pending-auth-request-with-fingerprint.view";
import { PendingAuthRequestView } from "./pending-auth-request.view";
export class OrganizationAuthRequestService {
@@ -25,6 +26,16 @@ export class OrganizationAuthRequestService {
return await this.organizationAuthRequestApiService.listPendingRequests(organizationId);
}
async listPendingRequestsWithFingerprint(
organizationId: string,
): Promise<PendingAuthRequestWithFingerprintView[]> {
return Promise.all(
((await this.listPendingRequests(organizationId)) ?? []).map(
async (r) => await PendingAuthRequestWithFingerprintView.fromView(r, this.keyService),
),
);
}
async denyPendingRequests(organizationId: string, ...requestIds: string[]): Promise<void> {
await this.organizationAuthRequestApiService.denyPendingRequests(organizationId, ...requestIds);
}

View File

@@ -0,0 +1,27 @@
import { Utils } from "@bitwarden/common/platform/misc/utils";
import { KeyService } from "@bitwarden/key-management";
import { PendingAuthRequestView } from "./pending-auth-request.view";
export class PendingAuthRequestWithFingerprintView extends PendingAuthRequestView {
fingerprintPhrase: string = "";
static async fromView(
view: PendingAuthRequestView,
keyService: KeyService,
): Promise<PendingAuthRequestWithFingerprintView> {
const requestWithDetailsView = Object.assign(
new PendingAuthRequestWithFingerprintView(),
view,
) as PendingAuthRequestWithFingerprintView;
requestWithDetailsView.fingerprintPhrase = (
await keyService.getFingerprint(
requestWithDetailsView.email,
Utils.fromB64ToArray(requestWithDetailsView.publicKey),
)
)?.join("-");
return requestWithDetailsView;
}
}