Skip to content

Commit cea2c0c

Browse files
committed
test(msteams): prove graph upload oversized JSON rejection
1 parent 59df748 commit cea2c0c

1 file changed

Lines changed: 47 additions & 2 deletions

File tree

extensions/msteams/src/graph-upload.test.ts

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Msteams tests cover graph upload plugin behavior.
22
import { createServer, type Server } from "node:http";
3-
import type { AddressInfo } from "node:net";
43
import { withFetchPreconnect } from "openclaw/plugin-sdk/test-env";
54
import { afterEach, describe, expect, it, vi } from "vitest";
65
import { buildTeamsFileInfoCard } from "./graph-chat.js";
@@ -265,7 +264,7 @@ async function listenLoopbackServer(server: Server): Promise<number> {
265264
reject(new Error("expected loopback TCP address"));
266265
return;
267266
}
268-
resolve((address as AddressInfo).port);
267+
resolve(address.port);
269268
});
270269
});
271270
}
@@ -415,6 +414,52 @@ describe("graph-upload readProviderJsonResponse loopback proof", () => {
415414
await closeServer(server);
416415
}
417416
});
417+
418+
it("uploadToOneDrive rejects an oversized success JSON body from a real loopback HTTP server", async () => {
419+
const server = createServer((_req, res) => {
420+
res.writeHead(200, { "content-type": "application/json" });
421+
const chunk = Buffer.alloc(64 * 1024, 0x20);
422+
let remaining = 257; // >16 MiB when combined with the JSON prefix.
423+
res.write('{"id":"item-big","webUrl":"https://example.com/big","name":"big.txt","padding":"');
424+
const writeNext = () => {
425+
if (remaining <= 0) {
426+
res.end('"}');
427+
return;
428+
}
429+
remaining -= 1;
430+
if (res.write(chunk)) {
431+
setImmediate(writeNext);
432+
} else {
433+
res.once("drain", writeNext);
434+
}
435+
};
436+
writeNext();
437+
});
438+
const port = await listenLoopbackServer(server);
439+
440+
try {
441+
const realFetch = globalThis.fetch.bind(globalThis);
442+
vi.stubGlobal(
443+
"fetch",
444+
withFetchPreconnect(async (input: RequestInfo | URL, init?: RequestInit) => {
445+
const url = new URL(input instanceof Request ? input.url : String(input));
446+
const loopback = new URL(`${url.pathname}${url.search}`, `http://127.0.0.1:${port}`);
447+
return realFetch(loopback, init);
448+
}),
449+
);
450+
451+
await expect(
452+
uploadToOneDrive({ buffer: Buffer.from("x"), filename: "big.txt", tokenProvider }),
453+
).rejects.toThrow(
454+
"msteams.graph-upload.uploadOneDriveFile: JSON response exceeds 16777216 bytes",
455+
);
456+
console.log(
457+
"[msteams graph-upload loopback proof] oversized JSON rejected by bounded reader",
458+
);
459+
} finally {
460+
await closeServer(server);
461+
}
462+
});
418463
});
419464

420465
describe("buildTeamsFileInfoCard", () => {

0 commit comments

Comments
 (0)