Skip to content

Commit 8787129

Browse files
committed
test(copilot): add device-code and non-JSON error body redaction cases
Add regression tests covering the device code flow and non-JSON error bodies alongside the existing token refresh coverage. Also include live proof output showing real Response object redaction via extractProviderErrorDetail. Ref: #102953
1 parent 5bfd460 commit 8787129

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

src/llm/utils/oauth/github-copilot.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,4 +309,43 @@ describe("GitHub Copilot OAuth error body redaction", () => {
309309
// Structured code is preserved but raw JSON keys are not leaked
310310
await expect(refreshGitHubCopilotToken("refresh-token")).rejects.toThrow(/code=rate_limited/);
311311
});
312+
313+
it("redacts error body via the device code flow", async () => {
314+
vi.stubGlobal(
315+
"fetch",
316+
vi.fn(
317+
async () =>
318+
new Response(
319+
JSON.stringify({ error: "invalid_request", error_description: "missing client_id" }),
320+
{ status: 400, headers: { "Content-Type": "application/json" } },
321+
),
322+
),
323+
);
324+
325+
await expect(testing.startDeviceFlow("github.com")).rejects.toThrow(
326+
"GitHub Copilot device code request failed with status 400",
327+
);
328+
await expect(testing.startDeviceFlow("github.com")).rejects.not.toThrow(/error_description/);
329+
});
330+
331+
it("handles non-JSON error bodies with bounded detail", async () => {
332+
vi.stubGlobal(
333+
"fetch",
334+
vi.fn(
335+
async () =>
336+
new Response("Internal Server Error", {
337+
status: 500,
338+
headers: { "Content-Type": "text/plain" },
339+
}),
340+
),
341+
);
342+
343+
// For non-JSON bodies the detail is the body text itself (bounded by readResponseTextLimited).
344+
// The error message should include the status code and the bounded body as detail.
345+
await expect(refreshGitHubCopilotToken("refresh-token")).rejects.toThrow(
346+
/GitHub Copilot token refresh request failed with status 500/,
347+
);
348+
// Raw JSON syntax like {"error": must never appear for non-JSON responses
349+
await expect(refreshGitHubCopilotToken("refresh-token")).rejects.not.toThrow(/\{"error"/);
350+
});
312351
});

0 commit comments

Comments
 (0)