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

FIX: Request>Auth>Bearer configuration does not override if Collection>Auth>Basic is set. #1409

Conversation

karloluis
Copy link

@karloluis karloluis commented Jan 18, 2024

Description

Fixes #1536 and #960

The way axios handles the auth property on the request configurations makes it such that it will always take precedence over the headers.authorization for the headers object. This was causing issues where the Bruno Collection has Basic Auth and the Request being run has Bearer Auth.

Reproducing

  1. In Collection>Settings>Auth select Basic
  2. In a Request>Auth select Bearer
  3. Spin up an http server; preferably with a debugger and a breakpoint on the endpoint
  4. Inspect the req.headers property the server received

This will result in Basic ========; in this fix it should be Bearer =======

Alternative implementation

Instead of inverting logic and doing conditional validations consider potentially mutating the request object.
By doing delete request.auth on the condition for the request on bearer mode the bug can be avoided. Although I tend to shy away from mutating objects this way as it may have unintended side-effects.

Contribution Checklist:

  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.

Publishing to New Package Managers

Please see here for more information.

@karloluis karloluis changed the title FIX: Overriding request auth over collection FIX: Collection>Auth>Basic configuration does not override when Request>Auth>Bearer is set. Jan 23, 2024
@karloluis karloluis changed the title FIX: Collection>Auth>Basic configuration does not override when Request>Auth>Bearer is set. FIX: Request>Auth>Bearer configuration does not override if Collection>Auth>Basic is set. Jan 23, 2024
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Best read in split diff view.

@karloluis
Copy link
Author

Added tests and hoping for feedback to polish it further.

@karloluis karloluis mentioned this pull request Feb 7, 2024
5 tasks
@karloluis
Copy link
Author

Appears to be fixed by #1667

@karloluis karloluis closed this Mar 7, 2024
@karloluis karloluis deleted the bugfix/collection-basic-auth-collision-request-bearer branch March 8, 2024 09:14
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.

Collection specifying Basic Auth is not overwritten when Request specifies Bearer Token
1 participant