mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-12 12:41:10 +00:00
refactor(test): table-drive legacy config policy assertions
This commit is contained in:
@@ -26,6 +26,27 @@ async function expectLoadRejectionPreservesField(params: {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function expectValidConfigValue(params: {
|
||||||
|
config: unknown;
|
||||||
|
readValue: (config: unknown) => unknown;
|
||||||
|
expectedValue: unknown;
|
||||||
|
}) {
|
||||||
|
const res = validateConfigObject(params.config);
|
||||||
|
expect(res.ok).toBe(true);
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error("expected config to be valid");
|
||||||
|
}
|
||||||
|
expect(params.readValue(res.config)).toBe(params.expectedValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
function expectInvalidIssuePath(config: unknown, expectedPath: string) {
|
||||||
|
const res = validateConfigObject(config);
|
||||||
|
expect(res.ok).toBe(false);
|
||||||
|
if (!res.ok) {
|
||||||
|
expect(res.issues[0]?.path).toBe(expectedPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
describe("legacy config detection", () => {
|
describe("legacy config detection", () => {
|
||||||
it('accepts imessage.dmPolicy="open" with allowFrom "*"', async () => {
|
it('accepts imessage.dmPolicy="open" with allowFrom "*"', async () => {
|
||||||
const res = validateConfigObject({
|
const res = validateConfigObject({
|
||||||
@@ -36,40 +57,49 @@ describe("legacy config detection", () => {
|
|||||||
expect(res.config.channels?.imessage?.dmPolicy).toBe("open");
|
expect(res.config.channels?.imessage?.dmPolicy).toBe("open");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
it("defaults imessage.dmPolicy to pairing when imessage section exists", async () => {
|
it.each([
|
||||||
const res = validateConfigObject({ channels: { imessage: {} } });
|
[
|
||||||
expect(res.ok).toBe(true);
|
"defaults imessage.dmPolicy to pairing when imessage section exists",
|
||||||
if (res.ok) {
|
{ channels: { imessage: {} } },
|
||||||
expect(res.config.channels?.imessage?.dmPolicy).toBe("pairing");
|
(config: unknown) =>
|
||||||
}
|
(config as { channels?: { imessage?: { dmPolicy?: string } } }).channels?.imessage
|
||||||
});
|
?.dmPolicy,
|
||||||
it("defaults imessage.groupPolicy to allowlist when imessage section exists", async () => {
|
"pairing",
|
||||||
const res = validateConfigObject({ channels: { imessage: {} } });
|
],
|
||||||
expect(res.ok).toBe(true);
|
[
|
||||||
if (res.ok) {
|
"defaults imessage.groupPolicy to allowlist when imessage section exists",
|
||||||
expect(res.config.channels?.imessage?.groupPolicy).toBe("allowlist");
|
{ channels: { imessage: {} } },
|
||||||
}
|
(config: unknown) =>
|
||||||
});
|
(config as { channels?: { imessage?: { groupPolicy?: string } } }).channels?.imessage
|
||||||
it("defaults discord.groupPolicy to allowlist when discord section exists", async () => {
|
?.groupPolicy,
|
||||||
const res = validateConfigObject({ channels: { discord: {} } });
|
"allowlist",
|
||||||
expect(res.ok).toBe(true);
|
],
|
||||||
if (res.ok) {
|
[
|
||||||
expect(res.config.channels?.discord?.groupPolicy).toBe("allowlist");
|
"defaults discord.groupPolicy to allowlist when discord section exists",
|
||||||
}
|
{ channels: { discord: {} } },
|
||||||
});
|
(config: unknown) =>
|
||||||
it("defaults slack.groupPolicy to allowlist when slack section exists", async () => {
|
(config as { channels?: { discord?: { groupPolicy?: string } } }).channels?.discord
|
||||||
const res = validateConfigObject({ channels: { slack: {} } });
|
?.groupPolicy,
|
||||||
expect(res.ok).toBe(true);
|
"allowlist",
|
||||||
if (res.ok) {
|
],
|
||||||
expect(res.config.channels?.slack?.groupPolicy).toBe("allowlist");
|
[
|
||||||
}
|
"defaults slack.groupPolicy to allowlist when slack section exists",
|
||||||
});
|
{ channels: { slack: {} } },
|
||||||
it("defaults msteams.groupPolicy to allowlist when msteams section exists", async () => {
|
(config: unknown) =>
|
||||||
const res = validateConfigObject({ channels: { msteams: {} } });
|
(config as { channels?: { slack?: { groupPolicy?: string } } }).channels?.slack
|
||||||
expect(res.ok).toBe(true);
|
?.groupPolicy,
|
||||||
if (res.ok) {
|
"allowlist",
|
||||||
expect(res.config.channels?.msteams?.groupPolicy).toBe("allowlist");
|
],
|
||||||
}
|
[
|
||||||
|
"defaults msteams.groupPolicy to allowlist when msteams section exists",
|
||||||
|
{ channels: { msteams: {} } },
|
||||||
|
(config: unknown) =>
|
||||||
|
(config as { channels?: { msteams?: { groupPolicy?: string } } }).channels?.msteams
|
||||||
|
?.groupPolicy,
|
||||||
|
"allowlist",
|
||||||
|
],
|
||||||
|
])("%s", (_name, config, readValue, expectedValue) => {
|
||||||
|
expectValidConfigValue({ config, readValue, expectedValue });
|
||||||
});
|
});
|
||||||
it("rejects unsafe executable config values", async () => {
|
it("rejects unsafe executable config values", async () => {
|
||||||
const res = validateConfigObject({
|
const res = validateConfigObject({
|
||||||
@@ -98,52 +128,46 @@ describe("legacy config detection", () => {
|
|||||||
});
|
});
|
||||||
expect(res.ok).toBe(true);
|
expect(res.ok).toBe(true);
|
||||||
});
|
});
|
||||||
it('rejects discord.dm.policy="open" without allowFrom "*"', async () => {
|
it.each([
|
||||||
const res = validateConfigObject({
|
[
|
||||||
channels: { discord: { dm: { policy: "open", allowFrom: ["123"] } } },
|
'rejects discord.dm.policy="open" without allowFrom "*"',
|
||||||
|
{ channels: { discord: { dm: { policy: "open", allowFrom: ["123"] } } } },
|
||||||
|
"channels.discord.dm.allowFrom",
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'rejects discord.dmPolicy="open" without allowFrom "*"',
|
||||||
|
{ channels: { discord: { dmPolicy: "open", allowFrom: ["123"] } } },
|
||||||
|
"channels.discord.allowFrom",
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'rejects slack.dm.policy="open" without allowFrom "*"',
|
||||||
|
{ channels: { slack: { dm: { policy: "open", allowFrom: ["U123"] } } } },
|
||||||
|
"channels.slack.dm.allowFrom",
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'rejects slack.dmPolicy="open" without allowFrom "*"',
|
||||||
|
{ channels: { slack: { dmPolicy: "open", allowFrom: ["U123"] } } },
|
||||||
|
"channels.slack.allowFrom",
|
||||||
|
],
|
||||||
|
])("%s", (_name, config, expectedPath) => {
|
||||||
|
expectInvalidIssuePath(config, expectedPath);
|
||||||
});
|
});
|
||||||
expect(res.ok).toBe(false);
|
|
||||||
if (!res.ok) {
|
it.each([
|
||||||
expect(res.issues[0]?.path).toBe("channels.discord.dm.allowFrom");
|
{
|
||||||
}
|
name: 'accepts discord dm.allowFrom="*" with top-level allowFrom alias',
|
||||||
});
|
config: {
|
||||||
it('rejects discord.dmPolicy="open" without allowFrom "*"', async () => {
|
|
||||||
const res = validateConfigObject({
|
|
||||||
channels: { discord: { dmPolicy: "open", allowFrom: ["123"] } },
|
|
||||||
});
|
|
||||||
expect(res.ok).toBe(false);
|
|
||||||
if (!res.ok) {
|
|
||||||
expect(res.issues[0]?.path).toBe("channels.discord.allowFrom");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
it('accepts discord dm.allowFrom="*" with top-level allowFrom alias', async () => {
|
|
||||||
const res = validateConfigObject({
|
|
||||||
channels: { discord: { dm: { policy: "open", allowFrom: ["123"] }, allowFrom: ["*"] } },
|
channels: { discord: { dm: { policy: "open", allowFrom: ["123"] }, allowFrom: ["*"] } },
|
||||||
});
|
},
|
||||||
expect(res.ok).toBe(true);
|
},
|
||||||
});
|
{
|
||||||
it('rejects slack.dm.policy="open" without allowFrom "*"', async () => {
|
name: 'accepts slack dm.allowFrom="*" with top-level allowFrom alias',
|
||||||
const res = validateConfigObject({
|
config: {
|
||||||
channels: { slack: { dm: { policy: "open", allowFrom: ["U123"] } } },
|
|
||||||
});
|
|
||||||
expect(res.ok).toBe(false);
|
|
||||||
if (!res.ok) {
|
|
||||||
expect(res.issues[0]?.path).toBe("channels.slack.dm.allowFrom");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
it('rejects slack.dmPolicy="open" without allowFrom "*"', async () => {
|
|
||||||
const res = validateConfigObject({
|
|
||||||
channels: { slack: { dmPolicy: "open", allowFrom: ["U123"] } },
|
|
||||||
});
|
|
||||||
expect(res.ok).toBe(false);
|
|
||||||
if (!res.ok) {
|
|
||||||
expect(res.issues[0]?.path).toBe("channels.slack.allowFrom");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
it('accepts slack dm.allowFrom="*" with top-level allowFrom alias', async () => {
|
|
||||||
const res = validateConfigObject({
|
|
||||||
channels: { slack: { dm: { policy: "open", allowFrom: ["U123"] }, allowFrom: ["*"] } },
|
channels: { slack: { dm: { policy: "open", allowFrom: ["U123"] }, allowFrom: ["*"] } },
|
||||||
});
|
},
|
||||||
|
},
|
||||||
|
])("$name", ({ config }) => {
|
||||||
|
const res = validateConfigObject(config);
|
||||||
expect(res.ok).toBe(true);
|
expect(res.ok).toBe(true);
|
||||||
});
|
});
|
||||||
it("rejects legacy agent.model string", async () => {
|
it("rejects legacy agent.model string", async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user