mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 21:14:31 +00:00
test: table-drive utils and channel-match cases
This commit is contained in:
@@ -42,44 +42,44 @@ describe("resolveChannelEntryMatch", () => {
|
||||
});
|
||||
|
||||
describe("resolveChannelEntryMatchWithFallback", () => {
|
||||
it("prefers direct matches over parent and wildcard", () => {
|
||||
const entries = { a: { allow: true }, parent: { allow: false }, "*": { allow: false } };
|
||||
const match = resolveChannelEntryMatchWithFallback({
|
||||
entries,
|
||||
keys: ["a"],
|
||||
parentKeys: ["parent"],
|
||||
wildcardKey: "*",
|
||||
});
|
||||
expect(match.entry).toBe(entries.a);
|
||||
expect(match.matchSource).toBe("direct");
|
||||
expect(match.matchKey).toBe("a");
|
||||
});
|
||||
const fallbackCases = [
|
||||
{
|
||||
name: "prefers direct matches over parent and wildcard",
|
||||
entries: { a: { allow: true }, parent: { allow: false }, "*": { allow: false } },
|
||||
args: { keys: ["a"], parentKeys: ["parent"], wildcardKey: "*" },
|
||||
expectedEntryKey: "a",
|
||||
expectedSource: "direct",
|
||||
expectedMatchKey: "a",
|
||||
},
|
||||
{
|
||||
name: "falls back to parent when direct misses",
|
||||
entries: { parent: { allow: false }, "*": { allow: true } },
|
||||
args: { keys: ["missing"], parentKeys: ["parent"], wildcardKey: "*" },
|
||||
expectedEntryKey: "parent",
|
||||
expectedSource: "parent",
|
||||
expectedMatchKey: "parent",
|
||||
},
|
||||
{
|
||||
name: "falls back to wildcard when no direct or parent match",
|
||||
entries: { "*": { allow: true } },
|
||||
args: { keys: ["missing"], parentKeys: ["still-missing"], wildcardKey: "*" },
|
||||
expectedEntryKey: "*",
|
||||
expectedSource: "wildcard",
|
||||
expectedMatchKey: "*",
|
||||
},
|
||||
] as const;
|
||||
|
||||
it("falls back to parent when direct misses", () => {
|
||||
const entries = { parent: { allow: false }, "*": { allow: true } };
|
||||
const match = resolveChannelEntryMatchWithFallback({
|
||||
entries,
|
||||
keys: ["missing"],
|
||||
parentKeys: ["parent"],
|
||||
wildcardKey: "*",
|
||||
for (const testCase of fallbackCases) {
|
||||
it(testCase.name, () => {
|
||||
const match = resolveChannelEntryMatchWithFallback({
|
||||
entries: testCase.entries,
|
||||
...testCase.args,
|
||||
});
|
||||
expect(match.entry).toBe(testCase.entries[testCase.expectedEntryKey]);
|
||||
expect(match.matchSource).toBe(testCase.expectedSource);
|
||||
expect(match.matchKey).toBe(testCase.expectedMatchKey);
|
||||
});
|
||||
expect(match.entry).toBe(entries.parent);
|
||||
expect(match.matchSource).toBe("parent");
|
||||
expect(match.matchKey).toBe("parent");
|
||||
});
|
||||
|
||||
it("falls back to wildcard when no direct or parent match", () => {
|
||||
const entries = { "*": { allow: true } };
|
||||
const match = resolveChannelEntryMatchWithFallback({
|
||||
entries,
|
||||
keys: ["missing"],
|
||||
parentKeys: ["still-missing"],
|
||||
wildcardKey: "*",
|
||||
});
|
||||
expect(match.entry).toBe(entries["*"]);
|
||||
expect(match.matchSource).toBe("wildcard");
|
||||
expect(match.matchKey).toBe("*");
|
||||
});
|
||||
}
|
||||
|
||||
it("matches normalized keys when normalizeKey is provided", () => {
|
||||
const entries = { "My Team": { allow: true } };
|
||||
@@ -153,44 +153,52 @@ describe("validateSenderIdentity", () => {
|
||||
});
|
||||
|
||||
describe("resolveNestedAllowlistDecision", () => {
|
||||
it("allows when outer allowlist is disabled", () => {
|
||||
expect(
|
||||
resolveNestedAllowlistDecision({
|
||||
const cases = [
|
||||
{
|
||||
name: "allows when outer allowlist is disabled",
|
||||
value: {
|
||||
outerConfigured: false,
|
||||
outerMatched: false,
|
||||
innerConfigured: false,
|
||||
innerMatched: false,
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("blocks when outer allowlist is configured but missing match", () => {
|
||||
expect(
|
||||
resolveNestedAllowlistDecision({
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
name: "blocks when outer allowlist is configured but missing match",
|
||||
value: {
|
||||
outerConfigured: true,
|
||||
outerMatched: false,
|
||||
innerConfigured: false,
|
||||
innerMatched: false,
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("requires inner match when inner allowlist is configured", () => {
|
||||
expect(
|
||||
resolveNestedAllowlistDecision({
|
||||
},
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
name: "requires inner match when inner allowlist is configured",
|
||||
value: {
|
||||
outerConfigured: true,
|
||||
outerMatched: true,
|
||||
innerConfigured: true,
|
||||
innerMatched: false,
|
||||
}),
|
||||
).toBe(false);
|
||||
expect(
|
||||
resolveNestedAllowlistDecision({
|
||||
},
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
name: "allows when both outer and inner allowlists match",
|
||||
value: {
|
||||
outerConfigured: true,
|
||||
outerMatched: true,
|
||||
innerConfigured: true,
|
||||
innerMatched: true,
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
] as const;
|
||||
|
||||
for (const testCase of cases) {
|
||||
it(testCase.name, () => {
|
||||
expect(resolveNestedAllowlistDecision(testCase.value)).toBe(testCase.expected);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user