mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-25 04:24:51 -07:00
test(core): mock fetch in OAuth transport fallback tests (#17059)
Co-authored-by: Bryan Morgan <bryanmorgan@google.com>
This commit is contained in:
@@ -1998,6 +1998,19 @@ describe('connectToMcpServer - OAuth with transport fallback', () => {
|
||||
vi.spyOn(console, 'warn').mockImplementation(() => {});
|
||||
vi.spyOn(console, 'error').mockImplementation(() => {});
|
||||
|
||||
// Mock fetch to prevent real network calls during OAuth discovery fallback.
|
||||
// When a 401 error lacks a www-authenticate header, the code attempts to
|
||||
// fetch the header directly from the server, which would hang without this mock.
|
||||
vi.stubGlobal(
|
||||
'fetch',
|
||||
vi.fn().mockResolvedValue({
|
||||
status: 401,
|
||||
headers: new Headers({
|
||||
'www-authenticate': `Bearer realm="test", resource_metadata="http://test-server/.well-known/oauth-protected-resource"`,
|
||||
}),
|
||||
}),
|
||||
);
|
||||
|
||||
mockTokenStorage = {
|
||||
getCredentials: vi.fn().mockResolvedValue({ clientId: 'test-client' }),
|
||||
} as unknown as MCPOAuthTokenStorage;
|
||||
@@ -2019,6 +2032,7 @@ describe('connectToMcpServer - OAuth with transport fallback', () => {
|
||||
|
||||
afterEach(() => {
|
||||
vi.clearAllMocks();
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
it('should handle HTTP 404 → SSE 401 → OAuth → SSE+OAuth succeeds', async () => {
|
||||
|
||||
Reference in New Issue
Block a user