Files
openclaw/src/config/types.secrets.resolution.test.ts
T
Josh Avant 1769fb2aa1 fix(secrets): align SecretRef inspect/strict behavior across preload/runtime paths (#66818)
* Config: add inspect/strict SecretRef string resolver

* CLI: pass resolved/source config snapshots to plugin preload

* Slack: keep HTTP route registration config-only

* Providers: normalize SecretRef handling for auth and web tools

* Secrets: add Exa web search target to registry and docs

* Telegram: resolve env SecretRef tokens at runtime

* Agents: resolve custom provider env SecretRef ids

* Providers: fail closed on blocked SecretRef fallback

* Telegram: enforce env SecretRef policy for runtime token refs

* Status/Providers/Telegram: tighten SecretRef preload and fallback handling

* Providers: enforce env SecretRef policy checks in fallback auth paths

* fix: add SecretRef lifecycle changelog entry (#66818) (thanks @joshavant)
2026-04-14 17:59:28 -05:00

81 lines
2.3 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { normalizeResolvedSecretInputString, resolveSecretInputString } from "./types.secrets.js";
describe("resolveSecretInputString", () => {
it("returns available for non-empty string values", () => {
expect(
resolveSecretInputString({
value: " abc123 ",
path: "models.providers.openai.apiKey",
}),
).toEqual({
status: "available",
value: "abc123",
ref: null,
});
});
it("returns configured_unavailable for unresolved refs in inspect mode", () => {
expect(
resolveSecretInputString({
value: { source: "env", provider: "default", id: "OPENAI_API_KEY" },
path: "models.providers.openai.apiKey",
mode: "inspect",
}),
).toEqual({
status: "configured_unavailable",
value: undefined,
ref: { source: "env", provider: "default", id: "OPENAI_API_KEY" },
});
});
it("uses explicit refValue in inspect mode", () => {
expect(
resolveSecretInputString({
value: "",
refValue: { source: "env", provider: "default", id: "OPENAI_API_KEY" },
path: "profiles.default.key",
mode: "inspect",
}),
).toEqual({
status: "configured_unavailable",
value: undefined,
ref: { source: "env", provider: "default", id: "OPENAI_API_KEY" },
});
});
it("returns missing when no value or ref is configured", () => {
expect(
resolveSecretInputString({
value: "",
path: "models.providers.openai.apiKey",
mode: "inspect",
}),
).toEqual({
status: "missing",
value: undefined,
ref: null,
});
});
it("throws for unresolved refs in strict mode", () => {
expect(() =>
resolveSecretInputString({
value: { source: "env", provider: "default", id: "OPENAI_API_KEY" },
path: "models.providers.openai.apiKey",
}),
).toThrow(/unresolved SecretRef/);
});
});
describe("normalizeResolvedSecretInputString", () => {
it("keeps strict unresolved-ref behavior", () => {
expect(() =>
normalizeResolvedSecretInputString({
value: { source: "env", provider: "default", id: "OPENAI_API_KEY" },
path: "models.providers.openai.apiKey",
}),
).toThrow(/unresolved SecretRef/);
});
});