mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-20 21:51:28 +00:00
fix(regression): preserve external command auth context
This commit is contained in:
@@ -34,11 +34,13 @@ function resolveProviderFromContext(
|
||||
ctx: MsgContext,
|
||||
cfg: OpenClawConfig,
|
||||
): { providerId: ChannelId | undefined; hadResolutionError: boolean } {
|
||||
const explicitMessageChannel =
|
||||
normalizeMessageChannel(ctx.Provider) ??
|
||||
normalizeMessageChannel(ctx.Surface) ??
|
||||
normalizeMessageChannel(ctx.OriginatingChannel);
|
||||
if (explicitMessageChannel === INTERNAL_MESSAGE_CHANNEL) {
|
||||
const explicitMessageChannels = [ctx.Surface, ctx.OriginatingChannel, ctx.Provider]
|
||||
.map((value) => normalizeMessageChannel(value))
|
||||
.filter((value): value is string => Boolean(value));
|
||||
const explicitMessageChannel = explicitMessageChannels.find(
|
||||
(value) => value !== INTERNAL_MESSAGE_CHANNEL,
|
||||
);
|
||||
if (!explicitMessageChannel && explicitMessageChannels.includes(INTERNAL_MESSAGE_CHANNEL)) {
|
||||
return { providerId: undefined, hadResolutionError: false };
|
||||
}
|
||||
const direct =
|
||||
|
||||
@@ -216,6 +216,28 @@ describe("resolveCommandAuthorization", () => {
|
||||
expect(auth.isAuthorizedSender).toBe(true);
|
||||
});
|
||||
|
||||
it("preserves external channel command auth in mixed webchat contexts", () => {
|
||||
const cfg = {
|
||||
commands: { allowFrom: { whatsapp: ["+15551234567"] } },
|
||||
channels: { whatsapp: { allowFrom: ["+15551234567"] } },
|
||||
} as OpenClawConfig;
|
||||
|
||||
const auth = resolveCommandAuthorization({
|
||||
ctx: {
|
||||
Provider: "webchat",
|
||||
Surface: "whatsapp",
|
||||
OriginatingChannel: "whatsapp",
|
||||
From: "whatsapp:+19995551234",
|
||||
SenderE164: "+19995551234",
|
||||
} as MsgContext,
|
||||
cfg,
|
||||
commandAuthorized: true,
|
||||
});
|
||||
|
||||
expect(auth.providerId).toBe("whatsapp");
|
||||
expect(auth.isAuthorizedSender).toBe(false);
|
||||
});
|
||||
|
||||
it("falls back to channel allowFrom when provider allowlist resolution throws", () => {
|
||||
registerAllowFromPlugins(
|
||||
createThrowingAllowFromPlugin("telegram", "channels.telegram.botToken: unresolved SecretRef"),
|
||||
|
||||
Reference in New Issue
Block a user