1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 16:23:44 +00:00
Files
browser/libs/common/src/models/domain/encryption-pair.spec.ts
Matt Gibson 77bbd3a863 Add to/fromJSON methods to State and Accounts
This is needed since all storage in manifest v3 is key-value-pair-based
and session storage of most data is actually serialized into an
encrypted string.
2022-08-31 17:05:07 -04:00

45 lines
1.4 KiB
TypeScript

import { Utils } from "@bitwarden/common/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.decryptedSerialized).toEqual("hello");
});
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",
decryptedSerialized: null,
});
expect(pair.encrypted).toEqual("hello");
expect(pair.decrypted).toEqual("world");
});
it("should deserialize decryptedSerialized for buffer arrays", () => {
const pair = EncryptionPair.fromJSON<string, ArrayBuffer>({
encrypted: "encrypted",
decrypted: null,
decryptedSerialized: "hello",
});
expect(pair.decrypted).toEqual(Utils.fromByteStringToArray("hello").buffer);
});
});
});