fix(slack): match channel-prefixed allowlist keys

This commit is contained in:
Peter Steinberger
2026-05-02 06:22:33 +01:00
parent d4d4a591e5
commit b867ed4ff2
3 changed files with 35 additions and 0 deletions

View File

@@ -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,

View File

@@ -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",