mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 16:01:01 +00:00
fix(slack): match channel-prefixed allowlist keys
This commit is contained in:
@@ -74,10 +74,16 @@ export function resolveSlackChannelConfig(params: {
|
||||
// entry-scan. buildChannelKeyCandidates deduplicates identical keys.
|
||||
const channelIdLower = normalizeLowercaseStringOrEmpty(channelId);
|
||||
const channelIdUpper = channelId.toUpperCase();
|
||||
const channelTarget = `channel:${channelId}`;
|
||||
const channelTargetLower = `channel:${channelIdLower}`;
|
||||
const channelTargetUpper = `channel:${channelIdUpper}`;
|
||||
const candidates = buildChannelKeyCandidates(
|
||||
channelId,
|
||||
channelIdLower !== channelId ? channelIdLower : undefined,
|
||||
channelIdUpper !== channelId ? channelIdUpper : undefined,
|
||||
channelTarget,
|
||||
channelTargetLower !== channelTarget ? channelTargetLower : undefined,
|
||||
channelTargetUpper !== channelTarget ? channelTargetUpper : undefined,
|
||||
allowNameMatching ? (channelName ? `#${directName}` : undefined) : undefined,
|
||||
allowNameMatching ? directName : undefined,
|
||||
allowNameMatching ? normalizedName : undefined,
|
||||
|
||||
@@ -79,6 +79,34 @@ describe("resolveSlackChannelConfig", () => {
|
||||
expect(res).toMatchObject({ allowed: true, requireMention: false });
|
||||
});
|
||||
|
||||
it("matches channel-prefixed config keys when Slack delivers a bare channel ID", () => {
|
||||
const res = resolveSlackChannelConfig({
|
||||
channelId: "C0AJYR3BVTJ",
|
||||
channels: { "channel:C0AJYR3BVTJ": { enabled: true, requireMention: false } },
|
||||
defaultRequireMention: true,
|
||||
});
|
||||
expect(res).toMatchObject({
|
||||
allowed: true,
|
||||
requireMention: false,
|
||||
matchKey: "channel:C0AJYR3BVTJ",
|
||||
matchSource: "direct",
|
||||
});
|
||||
});
|
||||
|
||||
it("matches lowercase channel-prefixed config keys when Slack delivers uppercase channel IDs", () => {
|
||||
const res = resolveSlackChannelConfig({
|
||||
channelId: "C0AJYR3BVTJ",
|
||||
channels: { "channel:c0ajyr3bvtj": { enabled: true, requireMention: false } },
|
||||
defaultRequireMention: true,
|
||||
});
|
||||
expect(res).toMatchObject({
|
||||
allowed: true,
|
||||
requireMention: false,
|
||||
matchKey: "channel:c0ajyr3bvtj",
|
||||
matchSource: "direct",
|
||||
});
|
||||
});
|
||||
|
||||
it("blocks channel-name route matches by default", () => {
|
||||
const res = resolveSlackChannelConfig({
|
||||
channelId: "C1",
|
||||
|
||||
Reference in New Issue
Block a user