mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 11:31:23 +00:00
fix(discord): normalize command allowFrom prefixes
This commit is contained in:
@@ -253,6 +253,15 @@ describe("resolveCommandAuthorization", () => {
|
||||
} as MsgContext;
|
||||
}
|
||||
|
||||
function makeDiscordContext(senderId: string, fromOverride?: string): MsgContext {
|
||||
return {
|
||||
Provider: "discord",
|
||||
Surface: "discord",
|
||||
From: fromOverride ?? `discord:${senderId}`,
|
||||
SenderId: senderId,
|
||||
} as MsgContext;
|
||||
}
|
||||
|
||||
function resolveWithCommandsAllowFrom(senderId: string, commandAuthorized: boolean) {
|
||||
return resolveCommandAuthorization({
|
||||
ctx: makeWhatsAppContext(senderId),
|
||||
@@ -372,6 +381,48 @@ describe("resolveCommandAuthorization", () => {
|
||||
|
||||
expect(auth.isAuthorizedSender).toBe(true);
|
||||
});
|
||||
|
||||
it("normalizes Discord commands.allowFrom prefixes and mentions", () => {
|
||||
const cfg = {
|
||||
commands: {
|
||||
allowFrom: {
|
||||
discord: ["user:123", "<@!456>", "pk:member-1"],
|
||||
},
|
||||
},
|
||||
} as OpenClawConfig;
|
||||
|
||||
const userAuth = resolveCommandAuthorization({
|
||||
ctx: makeDiscordContext("123"),
|
||||
cfg,
|
||||
commandAuthorized: false,
|
||||
});
|
||||
|
||||
expect(userAuth.isAuthorizedSender).toBe(true);
|
||||
|
||||
const mentionAuth = resolveCommandAuthorization({
|
||||
ctx: makeDiscordContext("456"),
|
||||
cfg,
|
||||
commandAuthorized: false,
|
||||
});
|
||||
|
||||
expect(mentionAuth.isAuthorizedSender).toBe(true);
|
||||
|
||||
const pkAuth = resolveCommandAuthorization({
|
||||
ctx: makeDiscordContext("member-1", "discord:999"),
|
||||
cfg,
|
||||
commandAuthorized: false,
|
||||
});
|
||||
|
||||
expect(pkAuth.isAuthorizedSender).toBe(true);
|
||||
|
||||
const deniedAuth = resolveCommandAuthorization({
|
||||
ctx: makeDiscordContext("other"),
|
||||
cfg,
|
||||
commandAuthorized: false,
|
||||
});
|
||||
|
||||
expect(deniedAuth.isAuthorizedSender).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user