Skip to content

Commit 9bb76ee

Browse files
committed
test: add regression test for empty customHeaders OAuth flow (modelcontextprotocol#982)
Adds test to ensure that an empty customHeaders array doesn't prevent OAuth token injection for direct connections. This test would have caught the bug where a default disabled Authorization header blocked the OAuth flow.
1 parent 42c9575 commit 9bb76ee

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

‎client/src/lib/hooks/__tests__/useConnection.test.tsx‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,24 @@ describe("useConnection", () => {
10441044
expect(headers).toHaveProperty("Authorization", "Bearer mock-token");
10451045
});
10461046

1047+
test("uses OAuth token when customHeaders is empty array (regression test for #982)", async () => {
1048+
// This test ensures that an empty customHeaders array doesn't prevent OAuth token injection
1049+
// Previously, a default disabled Authorization header blocked OAuth flow for direct connections
1050+
const propsWithEmptyHeaders = {
1051+
...defaultProps,
1052+
customHeaders: [],
1053+
};
1054+
1055+
const { result } = renderHook(() => useConnection(propsWithEmptyHeaders));
1056+
1057+
await act(async () => {
1058+
await result.current.connect();
1059+
});
1060+
1061+
const headers = mockSSETransport.options?.requestInit?.headers;
1062+
expect(headers).toHaveProperty("Authorization", "Bearer mock-token");
1063+
});
1064+
10471065
test("warns of enabled empty Bearer token", async () => {
10481066
// This test prevents regression of the bug where default "Bearer " header
10491067
// prevented OAuth token injection, causing infinite auth loops

0 commit comments

Comments
 (0)