node-oauth2-jwt-bearer
node-oauth2-jwt-bearer copied to clipboard
refactor: replacing protocol lookup with ternary
Description
Changed the protocol to be a ternary instead of a lookup. The lookup creates a cached copy of http.get and https.get, which means libraries like nock can't override them unless nock is explicitly imported before any application code. This is why it's not failing for the current tests in the repository.
Testing
import yourTestingApplication from '@app';
import 'nock';
nock(issuerUri)
.persist()
.get(/jwks.json/)
.reply(200, { keys: [{ kid: 'kid', ...publicJwk }] })
.get(/openid-configuration/)
.reply(200, {
....
❌ Fails with Failed to fetch authorization server metadata because it tries to make a real Api call
// Import order matters
import 'nock';
import yourTestingApplication from '@app';
nock(issuerUri)
.persist()
.get(/jwks.json/)
.reply(200, { keys: [{ kid: 'kid', ...publicJwk }] })
.get(/openid-configuration/)
.reply(200, {
....
Passes ✅
This will fail with: Failed to fetch authorization server metadata because it tries to make a real Api call
- [N] This change adds test coverage for new/changed/fixed functionality
Checklist
- [N/A] I have added documentation for new/changed functionality in this PR or in auth0.com/docs
- [Y] All active GitHub checks for tests, formatting, and security are passing
- [Y] The correct base branch is being used, if not the default branch