





















@@ -4,7 +4,7 @@ import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "no
44import { readFile } from "node:fs/promises";
55import { tmpdir } from "node:os";
66import path, { win32 } from "node:path";
7-import { afterEach, describe, expect, it } from "vitest";
7+import { afterEach, describe, expect, it, vi } from "vitest";
88import { fetchJsonWithTimeout, runCommand } from "../../scripts/e2e/telegram-user-credential-io.ts";
99import {
1010expandHome,
@@ -75,6 +75,8 @@ async function waitForExit(
7575}
76767777afterEach(() => {
78+vi.restoreAllMocks();
79+vi.unstubAllGlobals();
7880for (const dir of tempDirs.splice(0)) {
7981rmSync(dir, { force: true, recursive: true });
8082}
@@ -178,6 +180,64 @@ describe("telegram user credential IO", () => {
178180).toThrow("Chunked payload marker exceeds 67108864 bytes.");
179181});
180182183+it("hydrates chunked lease payloads using utf8 byte lengths", async () => {
184+const credentialModule = (await import(
185+`${new URL("../../scripts/e2e/telegram-user-credential.ts", import.meta.url).href}?case=utf8-chunk-${Date.now()}`
186+)) as {
187+hydratePayloadFromLease(params: {
188+acquired: Record<string, unknown>;
189+ownerId: string;
190+siteUrl: string;
191+token: string;
192+}): Promise<Record<string, unknown>>;
193+};
194+const sha256 = "a".repeat(64);
195+const serialized = JSON.stringify({
196+groupId: "-100123",
197+sutToken: "sut-token",
198+testerUserId: "8709353529",
199+testerUsername: "OpenClawTestUser",
200+telegramApiId: "123456",
201+telegramApiHash: "api-hash-\u00e9",
202+tdlibDatabaseEncryptionKey: "db-key",
203+tdlibArchiveBase64: "tdlib-archive",
204+tdlibArchiveSha256: sha256,
205+desktopTdataArchiveBase64: "desktop-archive",
206+desktopTdataArchiveSha256: sha256,
207+});
208+const fetchMock = vi.fn<typeof fetch>(
209+async () =>
210+new Response(JSON.stringify({ status: "ok", data: serialized }), {
211+status: 200,
212+headers: { "content-type": "application/json" },
213+}),
214+);
215+vi.stubGlobal("fetch", fetchMock);
216+217+const payload = await credentialModule.hydratePayloadFromLease({
218+acquired: {
219+credentialId: "cred-utf8",
220+leaseToken: "lease-utf8",
221+payload: {
222+[CHUNKED_PAYLOAD_MARKER]: true,
223+byteLength: Buffer.byteLength(serialized, "utf8"),
224+chunkCount: 1,
225+},
226+},
227+ownerId: "owner-utf8",
228+siteUrl: "https://qa.example.invalid",
229+token: "ci-secret",
230+});
231+232+expect(payload.telegramApiHash).toBe("api-hash-\u00e9");
233+expect(fetchMock).toHaveBeenCalledWith(
234+"https://qa.example.invalid/qa-credentials/v1/payload-chunk",
235+expect.objectContaining({
236+body: expect.stringContaining('"credentialId":"cred-utf8"'),
237+}),
238+);
239+});
240+181241it("rejects loose numeric credential limits instead of parsing prefixes", async () => {
182242const credentialModule = (await import(
183243`${new URL("../../scripts/e2e/telegram-user-credential.ts", import.meta.url).href}?case=limits-${Date.now()}`
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。