mirror of https://github.com/openclaw/openclaw.git
88 lines
2.8 KiB
TypeScript
88 lines
2.8 KiB
TypeScript
import { beforeAll, describe, expect, it, vi } from "vitest";
|
|
import type { CoreConfig } from "./types.js";
|
|
|
|
vi.mock("../../../src/config/bundled-channel-config-runtime.js", () => ({
|
|
getBundledChannelRuntimeMap: () => new Map(),
|
|
getBundledChannelConfigSchemaMap: () => new Map(),
|
|
}));
|
|
|
|
vi.mock("../../../src/channels/plugins/bundled.js", () => ({
|
|
bundledChannelPlugins: [],
|
|
bundledChannelSetupPlugins: [],
|
|
}));
|
|
|
|
let nextcloudTalkPlugin: typeof import("./channel.js").nextcloudTalkPlugin;
|
|
let NextcloudTalkConfigSchema: typeof import("./config-schema.js").NextcloudTalkConfigSchema;
|
|
|
|
beforeAll(async () => {
|
|
({ nextcloudTalkPlugin } = await import("./channel.js"));
|
|
({ NextcloudTalkConfigSchema } = await import("./config-schema.js"));
|
|
});
|
|
|
|
describe("nextcloud talk channel core", () => {
|
|
it("accepts SecretRef botSecret and apiPassword at top-level", () => {
|
|
const result = NextcloudTalkConfigSchema.safeParse({
|
|
baseUrl: "https://cloud.example.com",
|
|
botSecret: { source: "env", provider: "default", id: "NEXTCLOUD_TALK_BOT_SECRET" },
|
|
apiUser: "bot",
|
|
apiPassword: { source: "env", provider: "default", id: "NEXTCLOUD_TALK_API_PASSWORD" },
|
|
});
|
|
expect(result.success).toBe(true);
|
|
});
|
|
|
|
it("accepts SecretRef botSecret and apiPassword on account", () => {
|
|
const result = NextcloudTalkConfigSchema.safeParse({
|
|
accounts: {
|
|
main: {
|
|
baseUrl: "https://cloud.example.com",
|
|
botSecret: {
|
|
source: "env",
|
|
provider: "default",
|
|
id: "NEXTCLOUD_TALK_MAIN_BOT_SECRET",
|
|
},
|
|
apiUser: "bot",
|
|
apiPassword: {
|
|
source: "env",
|
|
provider: "default",
|
|
id: "NEXTCLOUD_TALK_MAIN_API_PASSWORD",
|
|
},
|
|
},
|
|
},
|
|
});
|
|
expect(result.success).toBe(true);
|
|
});
|
|
|
|
it("normalizes trimmed DM allowlist prefixes to lowercase ids", () => {
|
|
const resolveDmPolicy = nextcloudTalkPlugin.security?.resolveDmPolicy;
|
|
if (!resolveDmPolicy) {
|
|
throw new Error("resolveDmPolicy unavailable");
|
|
}
|
|
|
|
const cfg = {
|
|
channels: {
|
|
"nextcloud-talk": {
|
|
baseUrl: "https://cloud.example.com",
|
|
botSecret: "secret",
|
|
dmPolicy: "allowlist",
|
|
allowFrom: [" nc:User-Id "],
|
|
},
|
|
},
|
|
} as CoreConfig;
|
|
|
|
const result = resolveDmPolicy({
|
|
cfg,
|
|
account: nextcloudTalkPlugin.config.resolveAccount(cfg, "default"),
|
|
});
|
|
if (!result) {
|
|
throw new Error("nextcloud-talk resolveDmPolicy returned null");
|
|
}
|
|
|
|
expect(result.policy).toBe("allowlist");
|
|
expect(result.allowFrom).toEqual([" nc:User-Id "]);
|
|
expect(result.normalizeEntry?.(" nc:User-Id ")).toBe("user-id");
|
|
expect(nextcloudTalkPlugin.pairing?.normalizeAllowEntry?.(" nextcloud-talk:User-Id ")).toBe(
|
|
"user-id",
|
|
);
|
|
});
|
|
});
|