fix: resolve discord owner allowFrom matches

This commit is contained in:
Peter Steinberger
2026-02-05 00:51:39 -08:00
parent 5031b283a5
commit a4d1af1b11
2 changed files with 48 additions and 4 deletions

View 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"]);
});
});

View File

@@ -167,10 +167,13 @@ export function resolveDiscordOwnerAllowFrom(params: {
if (!allowList) { if (!allowList) {
return undefined; return undefined;
} }
const match = allowListMatches(allowList, { const match = resolveDiscordAllowListMatch({
id: params.sender.id, allowList,
name: params.sender.name, candidate: {
tag: params.sender.tag, id: params.sender.id,
name: params.sender.name,
tag: params.sender.tag,
},
}); });
if (!match.allowed || !match.matchKey || match.matchKey === "*") { if (!match.allowed || !match.matchKey || match.matchKey === "*") {
return undefined; return undefined;