/ opencodehub / tests / unit / workflow-secret-crypto.test.ts
Swadhin Biswas test(qa): add e2e, integration, unit, and load coverage · 3/6/2026
1c29e63
26 lines · 883 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { describe, expect, it } from "vitest";
import {
  decryptWorkflowSecret,
  encryptWorkflowSecret,
  isEncryptedWorkflowSecret,
} from "@/lib/workflow-secret-crypto";

describe("workflow secret crypto", () => {
  it("encrypts and decrypts values", () => {
    process.env.WORKFLOW_SECRET_ENCRYPTION_KEY =
      "workflow-secret-encryption-key-for-tests-32+";
    const plain = "runner-registration-token-123";
    const encrypted = encryptWorkflowSecret(plain);

    expect(isEncryptedWorkflowSecret(encrypted)).toBe(true);
    expect(encrypted).not.toContain(plain);
    expect(decryptWorkflowSecret(encrypted)).toBe(plain);
  });

  it("supports legacy plaintext values for backward compatibility", () => {
    const plain = "legacy-plaintext-secret";
    expect(isEncryptedWorkflowSecret(plain)).toBe(false);
    expect(decryptWorkflowSecret(plain)).toBe(plain);
  });
});