Track HiveGrid Cloud planning reference
This commit is contained in:
1 parent
b3d5ea6764
commit
e341c5938a
5784 files changed
+1104929
-3
No files matched your search
@@ -0,0 +1,27 @@
|
||||
// @vitest-environment node
|
||||
import { afterEach, describe, expect, test } from "vitest";
|
||||
import CryptoApi from "./CryptoApi";
|
||||
|
||||
const previousCryptoSecret = process.env.CRYPTO_SECRET;
|
||||
|
||||
afterEach(() => {
|
||||
process.env.CRYPTO_SECRET = previousCryptoSecret;
|
||||
});
|
||||
|
||||
describe("CryptoApi", () => {
|
||||
test("encrypts and decrypts values with authenticated node crypto", () => {
|
||||
process.env.CRYPTO_SECRET = "test-crypto-secret";
|
||||
|
||||
const encrypted = CryptoApi.encrypt("secret value");
|
||||
|
||||
expect(encrypted).toMatch(/^v1:[A-Za-z0-9_-]+:[A-Za-z0-9_-]+:[A-Za-z0-9_-]+$/);
|
||||
expect(encrypted).not.toContain("secret value");
|
||||
expect(CryptoApi.decrypt(encrypted)).toBe("secret value");
|
||||
});
|
||||
|
||||
test("rejects malformed encrypted payloads", () => {
|
||||
process.env.CRYPTO_SECRET = "test-crypto-secret";
|
||||
|
||||
expect(() => CryptoApi.decrypt("legacy-or-corrupt-value")).toThrow("Invalid encrypted payload");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user