fix: resolve discord owner allowFrom matches
parent
5031b283a5
commit
a4d1af1b11
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue