mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-25 08:52:12 +00:00
* feat(telegram): support custom apiRoot for alternative API endpoints Add `apiRoot` config option to allow users to specify custom Telegram Bot API endpoints (e.g., self-hosted Bot API servers). Threads the configured base URL through all Telegram API call sites: bot creation, send, probe, audit, media download, and api-fetch. Extends SSRF policy to dynamically trust custom apiRoot hostname for media downloads. Closes #28535 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix(telegram): thread apiRoot through allowFrom lookups * fix(telegram): honor lookup transport and local file paths * refactor(telegram): unify username lookup plumbing * fix(telegram): restore doctor lookup imports * fix: document Telegram apiRoot support (#48842) (thanks @Cypherm) --------- Co-authored-by: Cypherm <28184436+Cypherm@users.noreply.github.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Ayaan Zaidi <hi@obviy.us>
47 lines
1.8 KiB
TypeScript
47 lines
1.8 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import { resolveTelegramAllowFromEntries } from "./setup-core.js";
|
|
|
|
describe("resolveTelegramAllowFromEntries", () => {
|
|
it("passes apiRoot through username lookups", async () => {
|
|
const globalFetch = vi.fn(async () => {
|
|
throw new Error("global fetch should not be called");
|
|
});
|
|
const fetchMock = vi.fn(async () => ({
|
|
ok: true,
|
|
json: async () => ({ ok: true, result: { id: 12345 } }),
|
|
}));
|
|
vi.stubGlobal("fetch", globalFetch);
|
|
const proxyFetch = vi.fn();
|
|
const fetchModule = await import("./fetch.js");
|
|
const proxyModule = await import("./proxy.js");
|
|
const resolveTelegramFetch = vi.spyOn(fetchModule, "resolveTelegramFetch");
|
|
const makeProxyFetch = vi.spyOn(proxyModule, "makeProxyFetch");
|
|
makeProxyFetch.mockReturnValue(proxyFetch as unknown as typeof fetch);
|
|
resolveTelegramFetch.mockReturnValue(fetchMock as unknown as typeof fetch);
|
|
|
|
try {
|
|
const resolved = await resolveTelegramAllowFromEntries({
|
|
entries: ["@user"],
|
|
credentialValue: "tok",
|
|
apiRoot: "https://custom.telegram.test/root/",
|
|
proxyUrl: "http://127.0.0.1:8080",
|
|
network: { autoSelectFamily: false, dnsResultOrder: "ipv4first" },
|
|
});
|
|
|
|
expect(resolved).toEqual([{ input: "@user", resolved: true, id: "12345" }]);
|
|
expect(makeProxyFetch).toHaveBeenCalledWith("http://127.0.0.1:8080");
|
|
expect(resolveTelegramFetch).toHaveBeenCalledWith(proxyFetch, {
|
|
network: { autoSelectFamily: false, dnsResultOrder: "ipv4first" },
|
|
});
|
|
expect(fetchMock).toHaveBeenCalledWith(
|
|
"https://custom.telegram.test/root/bottok/getChat?chat_id=%40user",
|
|
undefined,
|
|
);
|
|
} finally {
|
|
makeProxyFetch.mockRestore();
|
|
resolveTelegramFetch.mockRestore();
|
|
vi.unstubAllGlobals();
|
|
}
|
|
});
|
|
});
|