openclaw/src/security/audit-extra.sync.test.ts

48 lines
1.7 KiB
TypeScript

import { describe, expect, it } from "vitest";
import type { OpenClawConfig } from "../config/config.js";
import { collectAttackSurfaceSummaryFindings } from "./audit-extra.sync.js";
import { safeEqualSecret } from "./secret-equal.js";
describe("collectAttackSurfaceSummaryFindings", () => {
it.each([
{
name: "distinguishes external webhooks from internal hooks when only internal hooks are enabled",
cfg: {
hooks: { internal: { enabled: true } },
} satisfies OpenClawConfig,
expectedDetail: ["hooks.webhooks: disabled", "hooks.internal: enabled"],
},
{
name: "reports both hook systems as enabled when both are configured",
cfg: {
hooks: { enabled: true, internal: { enabled: true } },
} satisfies OpenClawConfig,
expectedDetail: ["hooks.webhooks: enabled", "hooks.internal: enabled"],
},
{
name: "reports both hook systems as disabled when neither is configured",
cfg: {} satisfies OpenClawConfig,
expectedDetail: ["hooks.webhooks: disabled", "hooks.internal: disabled"],
},
])("$name", ({ cfg, expectedDetail }) => {
const [finding] = collectAttackSurfaceSummaryFindings(cfg);
expect(finding.checkId).toBe("summary.attack_surface");
for (const snippet of expectedDetail) {
expect(finding.detail).toContain(snippet);
}
});
});
describe("safeEqualSecret", () => {
it.each([
["secret-token", "secret-token", true],
["secret-token", "secret-tokEn", false],
["short", "much-longer", false],
[undefined, "secret", false],
["secret", undefined, false],
[null, "secret", false],
] as const)("compares %o and %o", (left, right, expected) => {
expect(safeEqualSecret(left, right)).toBe(expected);
});
});