-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle customer proxy re-auth response by retrying, not prompting use…
…r for different token Fixes https://linear.app/sourcegraph/issue/CODY-4695/handle-customer-proxy-re-auth-response-by-retrying-not-prompting-user
- Loading branch information
Showing
20 changed files
with
396 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { describe, expect, it, vi } from 'vitest' | ||
import { SourcegraphGraphQLAPIClient } from '../..' | ||
import * as fetchModule from '../../fetch' | ||
import { NeedsAuthChallengeError } from '../errors' | ||
|
||
vi.mocked(fetchModule) | ||
|
||
describe('SourcegraphGraphQLClient', () => { | ||
const client = SourcegraphGraphQLAPIClient.withStaticConfig({ | ||
auth: { | ||
credentials: { token: 'test-token' }, | ||
serverEndpoint: 'https://test.sourcegraph.com', | ||
}, | ||
clientState: { anonymousUserID: 'a' }, | ||
configuration: { | ||
telemetryLevel: 'off', | ||
}, | ||
}) | ||
|
||
describe('fetchHTTP', () => { | ||
it('sets Accept header', async () => { | ||
const fetchMock = vi | ||
.spyOn(fetchModule, 'fetch') | ||
.mockImplementation(async () => | ||
Promise.resolve(new Response(JSON.stringify({ data: {} }), { status: 200 })) | ||
) | ||
await client.fetchHTTP('TestQuery', 'POST', '/graphql', '{}') | ||
|
||
expect(fetchMock).toHaveBeenCalled() | ||
const headers = fetchMock.mock.calls[0][1]?.headers as Headers | ||
expect(headers.get('Accept')).toBe('application/json') | ||
|
||
fetchMock.mockRestore() | ||
}) | ||
}) | ||
|
||
describe('getCurrentUserInfo', () => { | ||
it('returns NeedsAuthChallengeError when response requires auth challenge', async () => { | ||
const fetchMock = vi.spyOn(fetchModule, 'fetch').mockImplementation(async () => | ||
Promise.resolve( | ||
new Response(null, { | ||
status: 401, | ||
headers: new Headers({ | ||
'X-CustomerName-U2f-Challenge': 'true', | ||
}), | ||
}) | ||
) | ||
) | ||
const result = await client.getCurrentUserInfo() | ||
expect(fetchMock).toHaveBeenCalled() | ||
console.log('XX', result) | ||
expect(result).toBeInstanceOf(NeedsAuthChallengeError) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.