Files
openclaw-zero-token/media/inbound-path-policy.test.ts
sjhu 571e14a236 feat: upgrade to upstream v2026.3.28
Major upgrade from e26988a38 to upstream v2026.3.28 (f9b107928).
Key changes:
- Upstream src/, ui/, extensions/ (89 bundled extensions)
- Zero-token web providers preserved in src/zero-token/
- AskOnce plugin restored and registered as CLI command
- Added missing packages: @anthropic-ai/vertex-sdk, @modelcontextprotocol/sdk
- Fixed tsconfig rootDir, skipLibCheck for plugin-sdk DTS build
- Added askonce to bundled plugin metadata and package.json exports
- Fixed AskOnce CLI command registration (missing commands metadata)
- Restored AskOnce adapter imports (correct 5-level relative paths)
- Removed stale migration artifacts from root directory
2026-03-30 17:58:12 +08:00

145 lines
4.7 KiB
TypeScript

import { describe, expect, it } from "vitest";
import type { OpenClawConfig } from "../config/config.js";
import {
DEFAULT_IMESSAGE_ATTACHMENT_ROOTS,
isInboundPathAllowed,
isValidInboundPathRootPattern,
mergeInboundPathRoots,
resolveIMessageAttachmentRoots,
resolveIMessageRemoteAttachmentRoots,
} from "./inbound-path-policy.js";
describe("inbound-path-policy", () => {
function expectInboundRootPatternCase(pattern: string, expected: boolean) {
expect(isValidInboundPathRootPattern(pattern)).toBe(expected);
}
function expectInboundPathAllowedCase(filePath: string, expected: boolean) {
expect(
isInboundPathAllowed({ filePath, roots: ["/Users/*/Library/Messages/Attachments"] }),
).toBe(expected);
}
function expectResolvedIMessageRootsCase(resolve: () => string[], expected: readonly string[]) {
expect(resolve()).toEqual(expected);
}
function expectMergedInboundPathRootsCase(params: {
defaults: string[];
additions: string[];
expected: readonly string[];
}) {
expect(mergeInboundPathRoots(params.defaults, params.additions)).toEqual(params.expected);
}
it.each([
{ pattern: "/Users/*/Library/Messages/Attachments", expected: true },
{ pattern: "/Volumes/relay/attachments", expected: true },
{ pattern: "./attachments", expected: false },
{ pattern: "/Users/**/Attachments", expected: false },
] as const)("validates absolute root pattern %s", ({ pattern, expected }) => {
expectInboundRootPatternCase(pattern, expected);
});
it.each([
{
filePath: "/Users/alice/Library/Messages/Attachments/12/34/ABCDEF/IMG_0001.jpeg",
expected: true,
},
{
filePath: "/etc/passwd",
expected: false,
},
] as const)("matches wildcard roots for %s => $expected", ({ filePath, expected }) => {
expectInboundPathAllowedCase(filePath, expected);
});
const accountOverrideCfg = {
channels: {
imessage: {
attachmentRoots: ["/Users/*/Library/Messages/Attachments"],
remoteAttachmentRoots: ["/Volumes/shared/imessage"],
accounts: {
work: {
attachmentRoots: ["/Users/work/Library/Messages/Attachments"],
remoteAttachmentRoots: ["/srv/work/attachments"],
},
},
},
},
} as OpenClawConfig;
it.each([
{
name: "normalizes and de-duplicates merged roots",
run: () =>
expectMergedInboundPathRootsCase({
defaults: [
"/Users/*/Library/Messages/Attachments/",
"/Users/*/Library/Messages/Attachments",
],
additions: ["/Volumes/relay/attachments"],
expected: ["/Users/*/Library/Messages/Attachments", "/Volumes/relay/attachments"],
}),
},
{
name: "resolves configured attachment roots with account overrides",
run: () =>
expectResolvedIMessageRootsCase(
() => resolveIMessageAttachmentRoots({ cfg: accountOverrideCfg, accountId: "work" }),
["/Users/work/Library/Messages/Attachments", "/Users/*/Library/Messages/Attachments"],
),
},
{
name: "resolves configured remote attachment roots with account overrides",
run: () =>
expectResolvedIMessageRootsCase(
() =>
resolveIMessageRemoteAttachmentRoots({ cfg: accountOverrideCfg, accountId: "work" }),
[
"/srv/work/attachments",
"/Volumes/shared/imessage",
"/Users/work/Library/Messages/Attachments",
"/Users/*/Library/Messages/Attachments",
],
),
},
] as const)("$name", ({ run }) => {
run();
});
it.each([
{
name: "matches iMessage account ids case-insensitively for attachment roots",
resolve: () => {
const cfg = {
channels: {
imessage: {
accounts: {
Work: {
attachmentRoots: ["/Users/work/Library/Messages/Attachments"],
},
},
},
},
} as OpenClawConfig;
return resolveIMessageAttachmentRoots({ cfg, accountId: "work" });
},
expected: ["/Users/work/Library/Messages/Attachments", ...DEFAULT_IMESSAGE_ATTACHMENT_ROOTS],
},
{
name: "falls back to default iMessage attachment roots",
resolve: () => resolveIMessageAttachmentRoots({ cfg: {} as OpenClawConfig }),
expected: [...DEFAULT_IMESSAGE_ATTACHMENT_ROOTS],
},
{
name: "falls back to default iMessage remote attachment roots",
resolve: () => resolveIMessageRemoteAttachmentRoots({ cfg: {} as OpenClawConfig }),
expected: [...DEFAULT_IMESSAGE_ATTACHMENT_ROOTS],
},
] as const)("$name", ({ resolve, expected }) => {
expectResolvedIMessageRootsCase(resolve, expected);
});
});