openclaw/src/wizard/onboarding.secret-input.test.ts
Vincent Koc e4d80ed556
CI: restore main detect-secrets scan (#38438)
* Tests: stabilize detect-secrets fixtures

* Tests: fix rebased detect-secrets false positives

* Docs: keep snippets valid under detect-secrets

* Tests: finalize detect-secrets false-positive fixes

* Tests: reduce detect-secrets false positives

* Tests: keep detect-secrets pragmas inline

* Tests: remediate next detect-secrets batch

* Tests: tighten detect-secrets allowlists

* Tests: stabilize detect-secrets formatter drift
2026-03-07 10:06:35 -08:00

52 lines
1.5 KiB
TypeScript

import { describe, expect, it } from "vitest";
import type { OpenClawConfig } from "../config/config.js";
import { resolveOnboardingSecretInputString } from "./onboarding.secret-input.js";
function makeConfig(): OpenClawConfig {
return {
secrets: {
providers: {
default: { source: "env" },
},
},
} as OpenClawConfig;
}
describe("resolveOnboardingSecretInputString", () => {
it("resolves env-template SecretInput strings", async () => {
const resolved = await resolveOnboardingSecretInputString({
config: makeConfig(),
value: "${OPENCLAW_GATEWAY_PASSWORD}",
path: "gateway.auth.password",
env: {
OPENCLAW_GATEWAY_PASSWORD: "gateway-secret", // pragma: allowlist secret
},
});
expect(resolved).toBe("gateway-secret");
});
it("returns plaintext strings when value is not a SecretRef", async () => {
const resolved = await resolveOnboardingSecretInputString({
config: makeConfig(),
value: "plain-text",
path: "gateway.auth.password",
});
expect(resolved).toBe("plain-text");
});
it("throws with path context when env-template SecretRef cannot resolve", async () => {
await expect(
resolveOnboardingSecretInputString({
config: makeConfig(),
value: "${OPENCLAW_GATEWAY_PASSWORD}",
path: "gateway.auth.password",
env: {},
}),
).rejects.toThrow(
'gateway.auth.password: failed to resolve SecretRef "env:default:OPENCLAW_GATEWAY_PASSWORD"',
);
});
});