mirror of
https://github.com/bitwarden/browser
synced 2025-12-19 01:33:33 +00:00
* Change everything to Uint8Array related to https://github.com/jestjs/jest/issues/14379 * Work on failing type tests * Revert changes to custom matcher setup * Remove last BufferArrays from tests * Fix custom matcher type errors in vscode * Remove errant `.buffer` calls on Uint8Arrays * Encryption Pair should serialize Array Buffer and Uint8Array * Fix EncArrayBuffer encryption --------- Co-authored-by: Thomas Rittson <trittson@bitwarden.com>
42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
import { Utils } from "../../misc/utils";
|
|
|
|
import { EncryptionPair } from "./account";
|
|
|
|
describe("EncryptionPair", () => {
|
|
describe("toJSON", () => {
|
|
it("should populate decryptedSerialized for buffer arrays", () => {
|
|
const pair = new EncryptionPair<string, ArrayBuffer>();
|
|
pair.decrypted = Utils.fromByteStringToArray("hello").buffer;
|
|
const json = pair.toJSON();
|
|
expect(json.decrypted).toEqual("hello");
|
|
});
|
|
|
|
it("should populate decryptedSerialized for TypesArrays", () => {
|
|
const pair = new EncryptionPair<string, Uint8Array>();
|
|
pair.decrypted = Utils.fromByteStringToArray("hello");
|
|
const json = pair.toJSON();
|
|
expect(json.decrypted).toEqual(new Uint8Array([104, 101, 108, 108, 111]));
|
|
});
|
|
|
|
it("should serialize encrypted and decrypted", () => {
|
|
const pair = new EncryptionPair<string, string>();
|
|
pair.encrypted = "hello";
|
|
pair.decrypted = "world";
|
|
const json = pair.toJSON();
|
|
expect(json.encrypted).toEqual("hello");
|
|
expect(json.decrypted).toEqual("world");
|
|
});
|
|
});
|
|
|
|
describe("fromJSON", () => {
|
|
it("should deserialize encrypted and decrypted", () => {
|
|
const pair = EncryptionPair.fromJSON({
|
|
encrypted: "hello",
|
|
decrypted: "world",
|
|
});
|
|
expect(pair.encrypted).toEqual("hello");
|
|
expect(pair.decrypted).toEqual("world");
|
|
});
|
|
});
|
|
});
|