@openclaw/synology-chat 2026.2.22 → 2026.5.1-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api.ts +3 -0
- package/channel-plugin-api.ts +1 -0
- package/contract-api.ts +1 -0
- package/index.ts +11 -12
- package/openclaw.plugin.json +35 -1
- package/package.json +20 -5
- package/setup-api.ts +1 -0
- package/setup-entry.ts +9 -0
- package/src/accounts.ts +107 -43
- package/src/approval-auth.test.ts +17 -0
- package/src/approval-auth.ts +22 -0
- package/src/channel.integration.test.ts +191 -0
- package/src/channel.test-mocks.ts +176 -0
- package/src/channel.test.ts +467 -174
- package/src/channel.ts +325 -278
- package/src/client.test.ts +296 -44
- package/src/client.ts +217 -24
- package/src/config-schema.ts +11 -0
- package/src/core.test.ts +373 -0
- package/src/gateway-runtime.ts +212 -0
- package/src/inbound-context.ts +10 -0
- package/src/inbound-turn.ts +171 -0
- package/src/runtime.ts +8 -20
- package/src/security-audit.test.ts +66 -0
- package/src/security-audit.ts +28 -0
- package/src/security.ts +67 -53
- package/src/session-key.ts +21 -0
- package/src/setup-surface.ts +338 -0
- package/src/test-http-utils.ts +75 -0
- package/src/types.ts +13 -14
- package/src/webhook-handler.test.ts +418 -75
- package/src/webhook-handler.ts +569 -138
- package/tsconfig.json +16 -0
- package/src/accounts.test.ts +0 -133
- package/src/security.test.ts +0 -98
package/api.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { synologyChatPlugin } from "./src/channel.js";
|
package/contract-api.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { collectSynologyChatSecurityAuditFindings } from "./src/security-audit.js";
|
package/index.ts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { emptyPluginConfigSchema } from "openclaw/plugin-sdk";
|
|
3
|
-
import { createSynologyChatPlugin } from "./src/channel.js";
|
|
4
|
-
import { setSynologyRuntime } from "./src/runtime.js";
|
|
1
|
+
import { defineBundledChannelEntry } from "openclaw/plugin-sdk/channel-entry-contract";
|
|
5
2
|
|
|
6
|
-
|
|
3
|
+
export default defineBundledChannelEntry({
|
|
7
4
|
id: "synology-chat",
|
|
8
5
|
name: "Synology Chat",
|
|
9
6
|
description: "Native Synology Chat channel plugin for OpenClaw",
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
importMetaUrl: import.meta.url,
|
|
8
|
+
plugin: {
|
|
9
|
+
specifier: "./channel-plugin-api.js",
|
|
10
|
+
exportName: "synologyChatPlugin",
|
|
14
11
|
},
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
runtime: {
|
|
13
|
+
specifier: "./api.js",
|
|
14
|
+
exportName: "setSynologyRuntime",
|
|
15
|
+
},
|
|
16
|
+
});
|
package/openclaw.plugin.json
CHANGED
|
@@ -1,9 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "synology-chat",
|
|
3
|
-
"
|
|
3
|
+
"activation": {
|
|
4
|
+
"onStartup": false
|
|
5
|
+
},
|
|
6
|
+
"channels": [
|
|
7
|
+
"synology-chat"
|
|
8
|
+
],
|
|
9
|
+
"channelEnvVars": {
|
|
10
|
+
"synology-chat": [
|
|
11
|
+
"SYNOLOGY_CHAT_TOKEN",
|
|
12
|
+
"SYNOLOGY_CHAT_INCOMING_URL",
|
|
13
|
+
"SYNOLOGY_NAS_HOST",
|
|
14
|
+
"SYNOLOGY_ALLOWED_USER_IDS",
|
|
15
|
+
"SYNOLOGY_RATE_LIMIT",
|
|
16
|
+
"OPENCLAW_BOT_NAME"
|
|
17
|
+
]
|
|
18
|
+
},
|
|
4
19
|
"configSchema": {
|
|
5
20
|
"type": "object",
|
|
6
21
|
"additionalProperties": false,
|
|
7
22
|
"properties": {}
|
|
23
|
+
},
|
|
24
|
+
"channelConfigs": {
|
|
25
|
+
"synology-chat": {
|
|
26
|
+
"schema": {
|
|
27
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
28
|
+
"type": "object",
|
|
29
|
+
"properties": {
|
|
30
|
+
"dangerouslyAllowNameMatching": {
|
|
31
|
+
"type": "boolean"
|
|
32
|
+
},
|
|
33
|
+
"dangerouslyAllowInheritedWebhookPath": {
|
|
34
|
+
"type": "boolean"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"additionalProperties": {}
|
|
38
|
+
},
|
|
39
|
+
"label": "Synology Chat",
|
|
40
|
+
"description": "Connect your Synology NAS Chat to OpenClaw with full agent capabilities."
|
|
41
|
+
}
|
|
8
42
|
}
|
|
9
43
|
}
|
package/package.json
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openclaw/synology-chat",
|
|
3
|
-
"version": "2026.
|
|
3
|
+
"version": "2026.5.1-beta.1",
|
|
4
4
|
"description": "Synology Chat channel plugin for OpenClaw",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/openclaw/openclaw"
|
|
8
|
+
},
|
|
5
9
|
"type": "module",
|
|
6
10
|
"dependencies": {
|
|
7
|
-
"zod": "^4.
|
|
11
|
+
"zod": "^4.4.1"
|
|
8
12
|
},
|
|
9
13
|
"devDependencies": {
|
|
10
|
-
"openclaw": "workspace:*"
|
|
14
|
+
"@openclaw/plugin-sdk": "workspace:*"
|
|
11
15
|
},
|
|
12
16
|
"openclaw": {
|
|
13
17
|
"extensions": [
|
|
14
18
|
"./index.ts"
|
|
15
19
|
],
|
|
20
|
+
"setupEntry": "./setup-entry.ts",
|
|
16
21
|
"channel": {
|
|
17
22
|
"id": "synology-chat",
|
|
18
23
|
"label": "Synology Chat",
|
|
@@ -24,8 +29,18 @@
|
|
|
24
29
|
},
|
|
25
30
|
"install": {
|
|
26
31
|
"npmSpec": "@openclaw/synology-chat",
|
|
27
|
-
"
|
|
28
|
-
"
|
|
32
|
+
"defaultChoice": "npm",
|
|
33
|
+
"minHostVersion": ">=2026.4.10"
|
|
34
|
+
},
|
|
35
|
+
"compat": {
|
|
36
|
+
"pluginApi": ">=2026.4.10"
|
|
37
|
+
},
|
|
38
|
+
"build": {
|
|
39
|
+
"openclawVersion": "2026.5.1-beta.1"
|
|
40
|
+
},
|
|
41
|
+
"release": {
|
|
42
|
+
"publishToClawHub": true,
|
|
43
|
+
"publishToNpm": true
|
|
29
44
|
}
|
|
30
45
|
}
|
|
31
46
|
}
|
package/setup-api.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { synologyChatSetupAdapter, synologyChatSetupWizard } from "./src/setup-surface.js";
|
package/setup-entry.ts
ADDED
package/src/accounts.ts
CHANGED
|
@@ -3,85 +3,149 @@
|
|
|
3
3
|
* merges per-account overrides, falls back to environment variables.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import
|
|
6
|
+
import {
|
|
7
|
+
DEFAULT_ACCOUNT_ID,
|
|
8
|
+
listCombinedAccountIds,
|
|
9
|
+
resolveMergedAccountConfig,
|
|
10
|
+
type OpenClawConfig,
|
|
11
|
+
} from "openclaw/plugin-sdk/account-resolution";
|
|
12
|
+
import { resolveDangerousNameMatchingEnabled } from "openclaw/plugin-sdk/dangerous-name-runtime";
|
|
13
|
+
import type {
|
|
14
|
+
SynologyChatChannelConfig,
|
|
15
|
+
ResolvedSynologyChatAccount,
|
|
16
|
+
SynologyWebhookPathSource,
|
|
17
|
+
} from "./types.js";
|
|
7
18
|
|
|
8
19
|
/** Extract the channel config from the full OpenClaw config object. */
|
|
9
|
-
function getChannelConfig(cfg:
|
|
10
|
-
return cfg?.channels?.["synology-chat"];
|
|
20
|
+
function getChannelConfig(cfg: OpenClawConfig): SynologyChatChannelConfig | undefined {
|
|
21
|
+
return cfg?.channels?.["synology-chat"] as SynologyChatChannelConfig | undefined;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function resolveImplicitAccountId(channelCfg: SynologyChatChannelConfig): string | undefined {
|
|
25
|
+
return channelCfg.token || process.env.SYNOLOGY_CHAT_TOKEN ? DEFAULT_ACCOUNT_ID : undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function getRawAccountConfig(
|
|
29
|
+
channelCfg: SynologyChatChannelConfig,
|
|
30
|
+
accountId: string,
|
|
31
|
+
): SynologyChatChannelConfig {
|
|
32
|
+
if (accountId === DEFAULT_ACCOUNT_ID) {
|
|
33
|
+
return channelCfg;
|
|
34
|
+
}
|
|
35
|
+
return channelCfg.accounts?.[accountId] ?? {};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function hasExplicitWebhookPath(rawAccount: SynologyChatChannelConfig | undefined): boolean {
|
|
39
|
+
return typeof rawAccount?.webhookPath === "string" && rawAccount.webhookPath.trim().length > 0;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function resolveWebhookPathSource(params: {
|
|
43
|
+
accountId: string;
|
|
44
|
+
channelCfg: SynologyChatChannelConfig;
|
|
45
|
+
rawAccount: SynologyChatChannelConfig;
|
|
46
|
+
}): SynologyWebhookPathSource {
|
|
47
|
+
if (hasExplicitWebhookPath(params.rawAccount)) {
|
|
48
|
+
return "explicit";
|
|
49
|
+
}
|
|
50
|
+
if (params.accountId !== DEFAULT_ACCOUNT_ID && hasExplicitWebhookPath(params.channelCfg)) {
|
|
51
|
+
return "inherited-base";
|
|
52
|
+
}
|
|
53
|
+
return "default";
|
|
11
54
|
}
|
|
12
55
|
|
|
13
56
|
/** Parse allowedUserIds from string or array to string[]. */
|
|
14
57
|
function parseAllowedUserIds(raw: string | string[] | undefined): string[] {
|
|
15
|
-
if (!raw)
|
|
16
|
-
|
|
58
|
+
if (!raw) {
|
|
59
|
+
return [];
|
|
60
|
+
}
|
|
61
|
+
if (Array.isArray(raw)) {
|
|
62
|
+
return raw.filter(Boolean);
|
|
63
|
+
}
|
|
17
64
|
return raw
|
|
18
65
|
.split(",")
|
|
19
66
|
.map((s) => s.trim())
|
|
20
67
|
.filter(Boolean);
|
|
21
68
|
}
|
|
22
69
|
|
|
70
|
+
function parseRateLimitPerMinute(raw: string | undefined): number {
|
|
71
|
+
if (raw == null) {
|
|
72
|
+
return 30;
|
|
73
|
+
}
|
|
74
|
+
const trimmed = raw.trim();
|
|
75
|
+
if (!/^-?\d+$/.test(trimmed)) {
|
|
76
|
+
return 30;
|
|
77
|
+
}
|
|
78
|
+
return Number.parseInt(trimmed, 10);
|
|
79
|
+
}
|
|
80
|
+
|
|
23
81
|
/**
|
|
24
82
|
* List all configured account IDs for this channel.
|
|
25
83
|
* Returns ["default"] if there's a base config, plus any named accounts.
|
|
26
84
|
*/
|
|
27
|
-
export function listAccountIds(cfg:
|
|
85
|
+
export function listAccountIds(cfg: OpenClawConfig): string[] {
|
|
28
86
|
const channelCfg = getChannelConfig(cfg);
|
|
29
|
-
if (!channelCfg)
|
|
30
|
-
|
|
31
|
-
const ids = new Set<string>();
|
|
32
|
-
|
|
33
|
-
// If base config has a token, there's a "default" account
|
|
34
|
-
const hasBaseToken = channelCfg.token || process.env.SYNOLOGY_CHAT_TOKEN;
|
|
35
|
-
if (hasBaseToken) {
|
|
36
|
-
ids.add("default");
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// Named accounts
|
|
40
|
-
if (channelCfg.accounts) {
|
|
41
|
-
for (const id of Object.keys(channelCfg.accounts)) {
|
|
42
|
-
ids.add(id);
|
|
43
|
-
}
|
|
87
|
+
if (!channelCfg) {
|
|
88
|
+
return [];
|
|
44
89
|
}
|
|
45
90
|
|
|
46
|
-
return
|
|
91
|
+
return listCombinedAccountIds({
|
|
92
|
+
configuredAccountIds: Object.keys(channelCfg.accounts ?? {}),
|
|
93
|
+
implicitAccountId: resolveImplicitAccountId(channelCfg),
|
|
94
|
+
});
|
|
47
95
|
}
|
|
48
96
|
|
|
49
97
|
/**
|
|
50
98
|
* Resolve a specific account by ID with full defaults applied.
|
|
51
99
|
* Falls back to env vars for the "default" account.
|
|
52
100
|
*/
|
|
53
|
-
export function resolveAccount(
|
|
101
|
+
export function resolveAccount(
|
|
102
|
+
cfg: OpenClawConfig,
|
|
103
|
+
accountId?: string | null,
|
|
104
|
+
): ResolvedSynologyChatAccount {
|
|
54
105
|
const channelCfg = getChannelConfig(cfg) ?? {};
|
|
55
|
-
const id = accountId ||
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const
|
|
106
|
+
const id = accountId || DEFAULT_ACCOUNT_ID;
|
|
107
|
+
const accountOverrides =
|
|
108
|
+
id === DEFAULT_ACCOUNT_ID ? undefined : (channelCfg.accounts?.[id] ?? undefined);
|
|
109
|
+
const rawAccount = getRawAccountConfig(channelCfg, id);
|
|
110
|
+
const merged = resolveMergedAccountConfig<Record<string, unknown> & SynologyChatChannelConfig>({
|
|
111
|
+
channelConfig: channelCfg as Record<string, unknown> & SynologyChatChannelConfig,
|
|
112
|
+
accounts: channelCfg.accounts as
|
|
113
|
+
| Record<string, Partial<Record<string, unknown> & SynologyChatChannelConfig>>
|
|
114
|
+
| undefined,
|
|
115
|
+
accountId: id,
|
|
116
|
+
});
|
|
59
117
|
|
|
60
118
|
// Env var fallbacks (primarily for the "default" account)
|
|
61
119
|
const envToken = process.env.SYNOLOGY_CHAT_TOKEN ?? "";
|
|
62
120
|
const envIncomingUrl = process.env.SYNOLOGY_CHAT_INCOMING_URL ?? "";
|
|
63
121
|
const envNasHost = process.env.SYNOLOGY_NAS_HOST ?? "localhost";
|
|
64
122
|
const envAllowedUserIds = process.env.SYNOLOGY_ALLOWED_USER_IDS ?? "";
|
|
65
|
-
const
|
|
123
|
+
const envRateLimitValue = parseRateLimitPerMinute(process.env.SYNOLOGY_RATE_LIMIT);
|
|
66
124
|
const envBotName = process.env.OPENCLAW_BOT_NAME ?? "OpenClaw";
|
|
125
|
+
const webhookPathSource = resolveWebhookPathSource({ accountId: id, channelCfg, rawAccount });
|
|
126
|
+
const dangerouslyAllowInheritedWebhookPath =
|
|
127
|
+
rawAccount.dangerouslyAllowInheritedWebhookPath ??
|
|
128
|
+
channelCfg.dangerouslyAllowInheritedWebhookPath ??
|
|
129
|
+
false;
|
|
67
130
|
|
|
68
131
|
// Merge: account override > base channel config > env var
|
|
69
132
|
return {
|
|
70
133
|
accountId: id,
|
|
71
|
-
enabled:
|
|
72
|
-
token:
|
|
73
|
-
incomingUrl:
|
|
74
|
-
nasHost:
|
|
75
|
-
webhookPath:
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
134
|
+
enabled: merged.enabled ?? true,
|
|
135
|
+
token: merged.token ?? envToken,
|
|
136
|
+
incomingUrl: merged.incomingUrl ?? envIncomingUrl,
|
|
137
|
+
nasHost: merged.nasHost ?? envNasHost,
|
|
138
|
+
webhookPath: merged.webhookPath ?? "/webhook/synology",
|
|
139
|
+
webhookPathSource,
|
|
140
|
+
dangerouslyAllowNameMatching: resolveDangerousNameMatchingEnabled({
|
|
141
|
+
providerConfig: channelCfg,
|
|
142
|
+
accountConfig: accountOverrides,
|
|
143
|
+
}),
|
|
144
|
+
dangerouslyAllowInheritedWebhookPath,
|
|
145
|
+
dmPolicy: merged.dmPolicy ?? "allowlist",
|
|
146
|
+
allowedUserIds: parseAllowedUserIds(merged.allowedUserIds ?? envAllowedUserIds),
|
|
147
|
+
rateLimitPerMinute: merged.rateLimitPerMinute ?? envRateLimitValue,
|
|
148
|
+
botName: merged.botName ?? envBotName,
|
|
149
|
+
allowInsecureSsl: merged.allowInsecureSsl ?? false,
|
|
86
150
|
};
|
|
87
151
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { synologyChatApprovalAuth } from "./approval-auth.js";
|
|
3
|
+
|
|
4
|
+
describe("synologyChatApprovalAuth", () => {
|
|
5
|
+
it("authorizes numeric Synology Chat user ids", () => {
|
|
6
|
+
const cfg = { channels: { "synology-chat": { allowedUserIds: ["123"] } } };
|
|
7
|
+
|
|
8
|
+
expect(
|
|
9
|
+
synologyChatApprovalAuth.authorizeActorAction({
|
|
10
|
+
cfg,
|
|
11
|
+
senderId: "123",
|
|
12
|
+
action: "approve",
|
|
13
|
+
approvalKind: "plugin",
|
|
14
|
+
}),
|
|
15
|
+
).toEqual({ authorized: true });
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createResolvedApproverActionAuthAdapter,
|
|
3
|
+
resolveApprovalApprovers,
|
|
4
|
+
} from "openclaw/plugin-sdk/approval-auth-runtime";
|
|
5
|
+
import { resolveAccount } from "./accounts.js";
|
|
6
|
+
|
|
7
|
+
function normalizeSynologyChatApproverId(value: string | number): string | undefined {
|
|
8
|
+
const trimmed = String(value).trim();
|
|
9
|
+
return /^\d+$/.test(trimmed) ? trimmed : undefined;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const synologyChatApprovalAuth = createResolvedApproverActionAuthAdapter({
|
|
13
|
+
channelLabel: "Synology Chat",
|
|
14
|
+
resolveApprovers: ({ cfg, accountId }) => {
|
|
15
|
+
const account = resolveAccount(cfg ?? {}, accountId);
|
|
16
|
+
return resolveApprovalApprovers({
|
|
17
|
+
allowFrom: account.allowedUserIds,
|
|
18
|
+
normalizeApprover: normalizeSynologyChatApproverId,
|
|
19
|
+
});
|
|
20
|
+
},
|
|
21
|
+
normalizeSenderId: (value) => normalizeSynologyChatApproverId(value),
|
|
22
|
+
});
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
+
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import {
|
|
4
|
+
buildChannelTurnContextMock,
|
|
5
|
+
dispatchReplyWithBufferedBlockDispatcher,
|
|
6
|
+
finalizeInboundContextMock,
|
|
7
|
+
registerPluginHttpRouteMock,
|
|
8
|
+
resolveAgentRouteMock,
|
|
9
|
+
setSynologyRuntimeConfigForTest,
|
|
10
|
+
} from "./channel.test-mocks.js";
|
|
11
|
+
import { makeFormBody, makeReq, makeRes } from "./test-http-utils.js";
|
|
12
|
+
|
|
13
|
+
type _RegisteredRoute = {
|
|
14
|
+
path: string;
|
|
15
|
+
accountId: string;
|
|
16
|
+
handler: (req: IncomingMessage, res: ServerResponse) => Promise<void>;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
let createSynologyChatPlugin: typeof import("./channel.js").createSynologyChatPlugin;
|
|
20
|
+
|
|
21
|
+
function makeStartContext<T>(cfg: T, accountId: string, abortSignal: AbortSignal) {
|
|
22
|
+
setSynologyRuntimeConfigForTest(cfg);
|
|
23
|
+
return {
|
|
24
|
+
cfg,
|
|
25
|
+
accountId,
|
|
26
|
+
log: { info: vi.fn(), warn: vi.fn(), error: vi.fn() },
|
|
27
|
+
abortSignal,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
describe("Synology channel wiring integration", () => {
|
|
32
|
+
beforeAll(async () => {
|
|
33
|
+
({ createSynologyChatPlugin } = await import("./channel.js"));
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
beforeEach(() => {
|
|
37
|
+
registerPluginHttpRouteMock.mockClear();
|
|
38
|
+
dispatchReplyWithBufferedBlockDispatcher.mockClear();
|
|
39
|
+
buildChannelTurnContextMock.mockClear();
|
|
40
|
+
finalizeInboundContextMock.mockClear();
|
|
41
|
+
resolveAgentRouteMock.mockClear();
|
|
42
|
+
setSynologyRuntimeConfigForTest({});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("registers real webhook handler with resolved account config and enforces allowlist", async () => {
|
|
46
|
+
const plugin = createSynologyChatPlugin();
|
|
47
|
+
const abortController = new AbortController();
|
|
48
|
+
const cfg = {
|
|
49
|
+
channels: {
|
|
50
|
+
"synology-chat": {
|
|
51
|
+
enabled: true,
|
|
52
|
+
accounts: {
|
|
53
|
+
alerts: {
|
|
54
|
+
enabled: true,
|
|
55
|
+
token: "valid-token",
|
|
56
|
+
incomingUrl: "https://nas.example.com/incoming",
|
|
57
|
+
webhookPath: "/webhook/synology-alerts",
|
|
58
|
+
dmPolicy: "allowlist",
|
|
59
|
+
allowedUserIds: ["456"],
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const started = plugin.gateway.startAccount(
|
|
67
|
+
makeStartContext(cfg, "alerts", abortController.signal),
|
|
68
|
+
);
|
|
69
|
+
expect(registerPluginHttpRouteMock).toHaveBeenCalledTimes(1);
|
|
70
|
+
|
|
71
|
+
const firstCall = registerPluginHttpRouteMock.mock.calls[0];
|
|
72
|
+
expect(firstCall).toBeTruthy();
|
|
73
|
+
if (!firstCall) {
|
|
74
|
+
throw new Error("Expected registerPluginHttpRoute to be called");
|
|
75
|
+
}
|
|
76
|
+
const registered = firstCall[0];
|
|
77
|
+
expect(registered.path).toBe("/webhook/synology-alerts");
|
|
78
|
+
expect(registered.accountId).toBe("alerts");
|
|
79
|
+
|
|
80
|
+
const req = makeReq(
|
|
81
|
+
"POST",
|
|
82
|
+
makeFormBody({
|
|
83
|
+
token: "valid-token",
|
|
84
|
+
user_id: "123",
|
|
85
|
+
username: "unauthorized-user",
|
|
86
|
+
text: "Hello",
|
|
87
|
+
}),
|
|
88
|
+
);
|
|
89
|
+
const res = makeRes();
|
|
90
|
+
await registered.handler(req, res);
|
|
91
|
+
|
|
92
|
+
expect(res._status).toBe(403);
|
|
93
|
+
expect(res._body).toContain("not authorized");
|
|
94
|
+
expect(dispatchReplyWithBufferedBlockDispatcher).not.toHaveBeenCalled();
|
|
95
|
+
abortController.abort();
|
|
96
|
+
await started;
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("isolates same user_id across different accounts", async () => {
|
|
100
|
+
const plugin = createSynologyChatPlugin();
|
|
101
|
+
const alphaAbortController = new AbortController();
|
|
102
|
+
const betaAbortController = new AbortController();
|
|
103
|
+
const cfg = {
|
|
104
|
+
channels: {
|
|
105
|
+
"synology-chat": {
|
|
106
|
+
enabled: true,
|
|
107
|
+
accounts: {
|
|
108
|
+
alpha: {
|
|
109
|
+
enabled: true,
|
|
110
|
+
token: "token-alpha",
|
|
111
|
+
incomingUrl: "https://nas.example.com/incoming-alpha",
|
|
112
|
+
webhookPath: "/webhook/synology-alpha",
|
|
113
|
+
dmPolicy: "open",
|
|
114
|
+
allowedUserIds: ["*"],
|
|
115
|
+
},
|
|
116
|
+
beta: {
|
|
117
|
+
enabled: true,
|
|
118
|
+
token: "token-beta",
|
|
119
|
+
incomingUrl: "https://nas.example.com/incoming-beta",
|
|
120
|
+
webhookPath: "/webhook/synology-beta",
|
|
121
|
+
dmPolicy: "open",
|
|
122
|
+
allowedUserIds: ["*"],
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
session: {
|
|
128
|
+
dmScope: "main" as const,
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const alphaStarted = plugin.gateway.startAccount(
|
|
133
|
+
makeStartContext(cfg, "alpha", alphaAbortController.signal),
|
|
134
|
+
);
|
|
135
|
+
const betaStarted = plugin.gateway.startAccount(
|
|
136
|
+
makeStartContext(cfg, "beta", betaAbortController.signal),
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
expect(registerPluginHttpRouteMock).toHaveBeenCalledTimes(2);
|
|
140
|
+
const alphaRoute = registerPluginHttpRouteMock.mock.calls[0]?.[0];
|
|
141
|
+
const betaRoute = registerPluginHttpRouteMock.mock.calls[1]?.[0];
|
|
142
|
+
if (!alphaRoute || !betaRoute) {
|
|
143
|
+
throw new Error("Expected both Synology Chat routes to register");
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const alphaReq = makeReq(
|
|
147
|
+
"POST",
|
|
148
|
+
makeFormBody({
|
|
149
|
+
token: "token-alpha",
|
|
150
|
+
user_id: "123",
|
|
151
|
+
username: "alice",
|
|
152
|
+
text: "alpha secret",
|
|
153
|
+
}),
|
|
154
|
+
);
|
|
155
|
+
const alphaRes = makeRes();
|
|
156
|
+
await alphaRoute.handler(alphaReq, alphaRes);
|
|
157
|
+
|
|
158
|
+
const betaReq = makeReq(
|
|
159
|
+
"POST",
|
|
160
|
+
makeFormBody({
|
|
161
|
+
token: "token-beta",
|
|
162
|
+
user_id: "123",
|
|
163
|
+
username: "bob",
|
|
164
|
+
text: "beta secret",
|
|
165
|
+
}),
|
|
166
|
+
);
|
|
167
|
+
const betaRes = makeRes();
|
|
168
|
+
await betaRoute.handler(betaReq, betaRes);
|
|
169
|
+
|
|
170
|
+
expect(alphaRes._status).toBe(204);
|
|
171
|
+
expect(betaRes._status).toBe(204);
|
|
172
|
+
expect(dispatchReplyWithBufferedBlockDispatcher).toHaveBeenCalledTimes(2);
|
|
173
|
+
expect(finalizeInboundContextMock).toHaveBeenCalledTimes(2);
|
|
174
|
+
|
|
175
|
+
const alphaCtx = finalizeInboundContextMock.mock.calls[0]?.[0];
|
|
176
|
+
const betaCtx = finalizeInboundContextMock.mock.calls[1]?.[0];
|
|
177
|
+
expect(alphaCtx).toMatchObject({
|
|
178
|
+
AccountId: "alpha",
|
|
179
|
+
SessionKey: "agent:agent-alpha:synology-chat:alpha:direct:123",
|
|
180
|
+
});
|
|
181
|
+
expect(betaCtx).toMatchObject({
|
|
182
|
+
AccountId: "beta",
|
|
183
|
+
SessionKey: "agent:agent-beta:synology-chat:beta:direct:123",
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
alphaAbortController.abort();
|
|
187
|
+
betaAbortController.abort();
|
|
188
|
+
await alphaStarted;
|
|
189
|
+
await betaStarted;
|
|
190
|
+
});
|
|
191
|
+
});
|