-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
012717a
commit 9cab1f0
Showing
3 changed files
with
27 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,10 @@ | ||
import { http, HttpResponse } from 'msw'; | ||
import sinon from 'sinon'; | ||
import { afterEach, beforeEach, describe, expect, test } from 'vitest'; | ||
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'; | ||
|
||
import { TokenVerificationErrorReason } from '../../errors'; | ||
import { | ||
mockExpiredJwt, | ||
mockInvalidSignatureJwt, | ||
mockJwks, | ||
mockJwt, | ||
mockJwtPayload, | ||
mockMalformedJwt, | ||
} from '../../fixtures'; | ||
import runtime from '../../runtime'; | ||
import { jsonOk } from '../../util/testUtils'; | ||
import { mockExpiredJwt, mockInvalidSignatureJwt, mockJwt, mockJwtPayload, mockMalformedJwt } from '../../fixtures'; | ||
import { server } from '../../mock-server'; | ||
import { AuthErrorReason, AuthStatus } from '../authStatus'; | ||
import { | ||
authenticateRequest, | ||
|
@@ -386,31 +379,31 @@ describe('tokens.getOrganizationSyncTarget(url,options)', _ => { | |
}); | ||
|
||
describe('tokens.authenticateRequest(options)', () => { | ||
let fakeClock; | ||
let fakeFetch; | ||
|
||
beforeEach(() => { | ||
fakeClock = sinon.useFakeTimers(new Date(mockJwtPayload.iat * 1000).getTime()); | ||
fakeFetch = sinon.stub(runtime, 'fetch'); | ||
fakeFetch.onCall(0).returns(jsonOk(mockJwks)); | ||
// the refresh token flow calls verify twice, so we need to support two calls | ||
fakeFetch.onCall(1).returns(jsonOk(mockJwks)); | ||
vi.useFakeTimers(); | ||
vi.setSystemTime(new Date(mockJwtPayload.iat * 1000).getTime()); | ||
}); | ||
|
||
afterEach(() => { | ||
fakeClock.restore(); | ||
fakeFetch.restore(); | ||
sinon.restore(); | ||
}); | ||
afterEach(() => {}); | ||
|
||
// | ||
// HTTP Authorization exists | ||
// | ||
|
||
test('returns signed out state if jwk fails to load from remote', async () => { | ||
fakeFetch.onCall(0).returns(jsonOk({})); | ||
test.only('returns signed out state if jwk fails to load from remote', async () => { | ||
server.use( | ||
http.get('https://api.clerk.test/v1/jwks', () => { | ||
return new HttpResponse('{}', { status: 200 }); | ||
}), | ||
); | ||
|
||
try { | ||
const requestState = await authenticateRequest(mockRequestWithHeaderAuth(), mockOptions()); | ||
|
||
const requestState = await authenticateRequest(mockRequestWithHeaderAuth(), mockOptions()); | ||
console.log('requestState', requestState); | ||
} catch (e) { | ||
console.log('e', e); | ||
} | ||
|
||
const errMessage = | ||
'The JWKS endpoint did not contain any signing keys. Contact [email protected]. Contact [email protected] (reason=jwk-remote-failed-to-load, token-carrier=header)'; | ||
|
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