Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replacing protocol lookup with ternary #139

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

fawcilize
Copy link

@fawcilize fawcilize commented Feb 22, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant