fix: resolve discord owner allowFrom matches
This commit is contained in:
41
src/discord/monitor/allow-list.test.ts
Normal file
41
src/discord/monitor/allow-list.test.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { DiscordChannelConfigResolved } from "./allow-list.js";
|
||||
import { resolveDiscordOwnerAllowFrom } from "./allow-list.js";
|
||||
|
||||
describe("resolveDiscordOwnerAllowFrom", () => {
|
||||
it("returns undefined when no allowlist is configured", () => {
|
||||
const result = resolveDiscordOwnerAllowFrom({
|
||||
channelConfig: { allowed: true } as DiscordChannelConfigResolved,
|
||||
sender: { id: "123" },
|
||||
});
|
||||
|
||||
expect(result).toBeUndefined();
|
||||
});
|
||||
|
||||
it("skips wildcard matches for owner allowFrom", () => {
|
||||
const result = resolveDiscordOwnerAllowFrom({
|
||||
channelConfig: { allowed: true, users: ["*"] } as DiscordChannelConfigResolved,
|
||||
sender: { id: "123" },
|
||||
});
|
||||
|
||||
expect(result).toBeUndefined();
|
||||
});
|
||||
|
||||
it("returns a matching user id entry", () => {
|
||||
const result = resolveDiscordOwnerAllowFrom({
|
||||
channelConfig: { allowed: true, users: ["123"] } as DiscordChannelConfigResolved,
|
||||
sender: { id: "123" },
|
||||
});
|
||||
|
||||
expect(result).toEqual(["123"]);
|
||||
});
|
||||
|
||||
it("returns the normalized name slug for name matches", () => {
|
||||
const result = resolveDiscordOwnerAllowFrom({
|
||||
channelConfig: { allowed: true, users: ["Some User"] } as DiscordChannelConfigResolved,
|
||||
sender: { id: "999", name: "Some User" },
|
||||
});
|
||||
|
||||
expect(result).toEqual(["some-user"]);
|
||||
});
|
||||
});
|
||||
@@ -167,10 +167,13 @@ export function resolveDiscordOwnerAllowFrom(params: {
|
||||
if (!allowList) {
|
||||
return undefined;
|
||||
}
|
||||
const match = allowListMatches(allowList, {
|
||||
id: params.sender.id,
|
||||
name: params.sender.name,
|
||||
tag: params.sender.tag,
|
||||
const match = resolveDiscordAllowListMatch({
|
||||
allowList,
|
||||
candidate: {
|
||||
id: params.sender.id,
|
||||
name: params.sender.name,
|
||||
tag: params.sender.tag,
|
||||
},
|
||||
});
|
||||
if (!match.allowed || !match.matchKey || match.matchKey === "*") {
|
||||
return undefined;
|
||||
|
||||
Reference in New Issue
Block a user