1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-12 14:34:02 +00:00

clean up requests

This commit is contained in:
Matt Gibson
2024-11-21 07:17:04 -08:00
parent 9649f80dd0
commit 10b01f0f1f
3 changed files with 3 additions and 70 deletions

View File

@@ -1,66 +0,0 @@
import { makeEncString, makeStaticByteArray, makeSymmetricCryptoKey } from "../../../../spec";
import { TunnelVersion } from "../../../platform/communication-tunnel/communication-tunnel";
import {
KeyConnectorGetUserKeyRequest,
KeyConnectorSetUserKeyRequest,
} from "./key-connector-user-key.request";
describe("KeyConnectorSetUserKeyRequest", () => {
const masterKey = makeSymmetricCryptoKey(64);
const tunnel = {
protect: jest.fn(),
encapsulatedKey: makeEncString("encapsulatedKey"),
} as any;
const protectedKey = makeStaticByteArray(32, 100);
it("creates a cleartext instance", async () => {
tunnel.tunnelVersion = TunnelVersion.CLEAR_TEXT;
const request = await KeyConnectorSetUserKeyRequest.BuildForTunnel(tunnel, masterKey);
expect(request).toBeInstanceOf(KeyConnectorSetUserKeyRequest);
expect(request.key).toBe(masterKey.encKeyB64);
expect(request.encryptedKey).toBeUndefined();
expect(request.sharedKey).toBeUndefined();
expect(request.tunnelVersion).toBeUndefined();
});
it("creates an encapsulated instance", async () => {
tunnel.tunnelVersion = TunnelVersion.RSA_ENCAPSULATED_AES_256_GCM;
tunnel.protect.mockResolvedValue(protectedKey);
const request = await KeyConnectorSetUserKeyRequest.BuildForTunnel(tunnel, masterKey);
expect(request).toBeInstanceOf(KeyConnectorSetUserKeyRequest);
expect(request.key).toBeUndefined();
expect(request.sharedKey).toEqualBuffer(tunnel.encapsulatedKey.dataBytes);
expect(request.encryptedKey).toEqualBuffer(protectedKey);
expect(request.tunnelVersion).toBe(TunnelVersion.RSA_ENCAPSULATED_AES_256_GCM);
expect(tunnel.protect).toHaveBeenCalledWith(masterKey.encKey);
});
});
describe("KeyConnectorGetUserKeyRequest", () => {
const tunnel = {
protect: jest.fn(),
encapsulatedKey: makeEncString("encapsulatedKey"),
} as any;
it("creates a cleartext instance", async () => {
tunnel.tunnelVersion = TunnelVersion.CLEAR_TEXT;
const request = KeyConnectorGetUserKeyRequest.BuildForTunnel(tunnel);
expect(request).toBeInstanceOf(KeyConnectorGetUserKeyRequest);
expect(request.tunnelVersion).toBeUndefined();
expect(request.sharedKey).toBeUndefined();
});
it("creates an encapsulated instance", async () => {
tunnel.tunnelVersion = TunnelVersion.RSA_ENCAPSULATED_AES_256_GCM;
const request = KeyConnectorGetUserKeyRequest.BuildForTunnel(tunnel);
expect(request).toBeInstanceOf(KeyConnectorGetUserKeyRequest);
expect(request.tunnelVersion).toBe(TunnelVersion.RSA_ENCAPSULATED_AES_256_GCM);
expect(request.sharedKey).toEqualBuffer(tunnel.encapsulatedKey.dataBytes);
});
});

View File

@@ -1,9 +1,5 @@
import { UserId } from "../../../types/guid";
/**
* @typedef { import("../response/key-connector-init-communication.response").KeyConnectorInitCommunicationResponse } KeyConnectorInitCommunicationResponse
*/
export class KeyConnectorSetUserKeyRequest {
/**
*

View File

@@ -5,6 +5,9 @@ export class InitTunnelResponse extends BaseResponse {
readonly encapsulationKey: Uint8Array;
readonly tunnelVersion: TunnelVersion;
readonly tunnelIdentifier: string;
/**
* Can be used to pro-actively re-up tunnels in the future.
*/
readonly tunnelDurationSeconds: number;
constructor(response: any) {