mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-14 18:51:04 +00:00
Merged via squash.
Prepared head SHA: ca58fb77a8
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Reviewed-by: @mbelinky
87 lines
2.2 KiB
TypeScript
87 lines
2.2 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import type { OpenClawConfig } from "../runtime-api.js";
|
|
import { resolveWebhooksPluginConfig } from "./config.js";
|
|
|
|
describe("resolveWebhooksPluginConfig", () => {
|
|
it("resolves default paths and SecretRef-backed secrets", async () => {
|
|
const routes = await resolveWebhooksPluginConfig({
|
|
pluginConfig: {
|
|
routes: {
|
|
zapier: {
|
|
sessionKey: "agent:main:main",
|
|
secret: {
|
|
source: "env",
|
|
provider: "default",
|
|
id: "OPENCLAW_WEBHOOK_SECRET",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
cfg: {} as OpenClawConfig,
|
|
env: {
|
|
OPENCLAW_WEBHOOK_SECRET: "shared-secret",
|
|
},
|
|
});
|
|
|
|
expect(routes).toEqual([
|
|
{
|
|
routeId: "zapier",
|
|
path: "/plugins/webhooks/zapier",
|
|
sessionKey: "agent:main:main",
|
|
secret: "shared-secret",
|
|
controllerId: "webhooks/zapier",
|
|
},
|
|
]);
|
|
});
|
|
|
|
it("skips routes whose secret cannot be resolved", async () => {
|
|
const warn = vi.fn();
|
|
|
|
const routes = await resolveWebhooksPluginConfig({
|
|
pluginConfig: {
|
|
routes: {
|
|
missing: {
|
|
sessionKey: "agent:main:main",
|
|
secret: {
|
|
source: "env",
|
|
provider: "default",
|
|
id: "MISSING_SECRET",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
cfg: {} as OpenClawConfig,
|
|
env: {},
|
|
logger: { warn } as never,
|
|
});
|
|
|
|
expect(routes).toEqual([]);
|
|
expect(warn).toHaveBeenCalledWith(
|
|
expect.stringContaining("[webhooks] skipping route missing:"),
|
|
);
|
|
});
|
|
|
|
it("rejects duplicate normalized paths", async () => {
|
|
await expect(
|
|
resolveWebhooksPluginConfig({
|
|
pluginConfig: {
|
|
routes: {
|
|
first: {
|
|
path: "/plugins/webhooks/shared",
|
|
sessionKey: "agent:main:main",
|
|
secret: "a",
|
|
},
|
|
second: {
|
|
path: "/plugins/webhooks/shared/",
|
|
sessionKey: "agent:main:other",
|
|
secret: "b",
|
|
},
|
|
},
|
|
},
|
|
cfg: {} as OpenClawConfig,
|
|
env: {},
|
|
}),
|
|
).rejects.toThrow(/conflicts with routes\.first\.path/i);
|
|
});
|
|
});
|