Synology Chat: ignore non-registerable path collisions

This commit is contained in:
Vincent Koc 2026-03-14 23:19:20 -07:00
parent 9f6b531839
commit 2bc62c67e7
2 changed files with 46 additions and 2 deletions

View File

@ -98,7 +98,7 @@ export function resolveAccount(cfg: any, accountId?: string | null): ResolvedSyn
export function findConflictingWebhookPathAccountIds(cfg: any, accountId: string): string[] {
const current = resolveAccount(cfg, accountId);
const currentPath = current.webhookPath.trim();
if (!current.enabled || !current.token.trim() || !currentPath) {
if (!current.enabled || !current.token.trim() || !current.incomingUrl.trim() || !currentPath) {
return [];
}
@ -107,7 +107,10 @@ export function findConflictingWebhookPathAccountIds(cfg: any, accountId: string
.map((candidateId) => resolveAccount(cfg, candidateId))
.filter(
(candidate) =>
candidate.enabled && candidate.token.trim() && candidate.webhookPath.trim() === currentPath,
candidate.enabled &&
candidate.token.trim() &&
candidate.incomingUrl.trim() &&
candidate.webhookPath.trim() === currentPath,
)
.map((candidate) => candidate.accountId);
}

View File

@ -375,5 +375,46 @@ describe("createSynologyChatPlugin", () => {
expect.stringContaining("Each enabled account must use a unique webhookPath."),
);
});
it("ignores accounts with a shared path when they are missing incomingUrl", async () => {
const registerMock = registerPluginHttpRouteMock;
registerMock.mockClear();
const plugin = createSynologyChatPlugin();
const abortController = new AbortController();
const log = { info: vi.fn(), warn: vi.fn(), error: vi.fn() };
const result = plugin.gateway.startAccount({
cfg: {
channels: {
"synology-chat": {
enabled: true,
token: "base-token",
incomingUrl: "https://nas/incoming",
webhookPath: "/webhook/synology/shared",
dmPolicy: "allowlist",
allowedUserIds: ["owner-a"],
accounts: {
alerts: {
enabled: true,
token: "alerts-token",
incomingUrl: "",
webhookPath: "/webhook/synology/shared",
dmPolicy: "open",
},
},
},
},
},
accountId: "default",
log,
abortSignal: abortController.signal,
});
await expectPendingStartAccountPromise(result, abortController);
expect(registerMock).toHaveBeenCalledTimes(1);
expect(log.error).not.toHaveBeenCalledWith(
expect.stringContaining("Each enabled account must use a unique webhookPath."),
);
});
});
});