Skip to content

Commit 728788c

Browse files
committed
fix(msteams): add oversized response test for graph-upload
1 parent 5c9a3ba commit 728788c

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,37 @@ describe("resolveGraphChatId", () => {
247247

248248
expect(result).toBeNull();
249249
});
250+
251+
it("rejects oversized OneDrive upload responses and cancels the stream", async () => {
252+
const cancel = vi.fn();
253+
const stream = new ReadableStream<Uint8Array>({
254+
cancel,
255+
start(controller) {
256+
const ONE_MIB = 1024 * 1024;
257+
for (let i = 0; i < 18; i++) {
258+
controller.enqueue(new Uint8Array(ONE_MIB));
259+
}
260+
controller.close();
261+
},
262+
});
263+
const fetchFn = vi.fn(
264+
async () =>
265+
new Response(stream, {
266+
status: 200,
267+
headers: { "content-type": "application/json" },
268+
}),
269+
);
270+
271+
await expect(
272+
uploadToOneDrive({
273+
buffer: Buffer.from("x"),
274+
filename: "a.txt",
275+
tokenProvider,
276+
fetchFn,
277+
}),
278+
).rejects.toThrow("msteams.graph.oneDriveUpload: JSON response exceeds");
279+
expect(cancel).toHaveBeenCalledOnce();
280+
});
250281
});
251282

252283
describe("buildTeamsFileInfoCard", () => {
@@ -285,4 +316,5 @@ describe("buildTeamsFileInfoCard", () => {
285316
},
286317
});
287318
});
319+
288320
});

0 commit comments

Comments
 (0)