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

add Baearear token for jwt #407

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

add Baearear token for jwt #407

wants to merge 1 commit into from

Conversation

pachCode
Copy link
Member

@pachCode pachCode commented Jul 29, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced authentication logic prioritizing JWT over basic authentication.
    • Updated request handling to include JWT in the Authorization header.
  • Bug Fixes

    • Adjusted tests to reflect the new behavior of the authentication mechanism with JWT, ensuring accurate assertions.

@pachCode pachCode requested a review from felipao-mx July 29, 2024 19:51
@pachCode pachCode self-assigned this Jul 29, 2024
Copy link

coderabbitai bot commented Jul 29, 2024

Walkthrough

The recent changes enhance the authentication mechanism in the client class by prioritizing JWT over basic authentication. The logic updates ensure that when a JWT token is available, the auth property reflects this by returning None. Additionally, requests now include the JWT in the Authorization header, streamlining API authentication. Correspondingly, tests have been updated to align with the new expectations around JWT and authentication behavior.

Changes

Files Change Summary
cuenca/http/client.py Enhanced authentication logic to prioritize JWT over basic auth; updated request method to set Authorization header.
tests/http/test_client.py Updated test_configures_jwt to assert that session.auth is falsy when using JWT, reflecting the new auth behavior.

Poem

🐇 In fields of code, we dance with glee,
JWT now leads, as it should be!
Basic auth waits, a soft goodbye,
While headers bloom like flowers in the sky.
With tests aligned and logic bright,
Our rabbit hole's a joyous sight! 🌼


Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between b602497 and 8e3ea60.

Files selected for processing (2)
  • cuenca/http/client.py (2 hunks)
  • tests/http/test_client.py (1 hunks)
Additional comments not posted (3)
tests/http/test_client.py (1)

39-39: LGTM! But verify the function usage in the codebase.

The change in the assertion aligns with the updated authentication mechanism where JWT takes precedence over basic authentication.

However, ensure that all test cases and functions that rely on session.auth are updated accordingly.

cuenca/http/client.py (2)

44-48: LGTM! But verify the function usage in the codebase.

The change ensures that JWT authentication takes precedence over basic authentication when both are available.

However, ensure that all function calls to auth are updated accordingly.

Verification successful

LGTM! But verify the function usage in the codebase.

The change ensures that JWT authentication takes precedence over basic authentication when both are available.

  • The auth property is defined and used in cuenca/http/client.py.
  • The behavior of the auth property is tested in tests/http/test_client.py.

The tests ensure that the auth property behaves correctly when both basic authentication and JWT tokens are present.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `auth`.

# Test: Search for the usage of `auth`. Expect: Only occurrences that align with the updated authentication mechanism.
rg --type python -A 5 $'auth'

Length of output: 59


Script:

#!/bin/bash
# Description: Verify all function calls to `auth`.

# Test: Search for the usage of `auth`. Expect: Only occurrences that align with the updated authentication mechanism.
rg -t py -A 5 'auth'

Length of output: 5423


116-118: LGTM! But verify the function usage in the codebase.

The change ensures that JWT tokens are included in the request headers, aligning with standard practices for API authentication.

However, ensure that all function calls to request are updated accordingly.

Copy link

codecov bot commented Jul 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (b602497) to head (8e3ea60).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #407   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           49        49           
  Lines         1111      1112    +1     
=========================================
+ Hits          1111      1112    +1     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
cuenca/http/client.py 100.00% <100.00%> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b602497...8e3ea60. Read the comment docs.

return self.basic_auth if all(self.basic_auth) else None
return (
self.basic_auth
if all(self.basic_auth) and not self.jwt_token
Copy link
Member

Choose a reason for hiding this comment

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

me da la impresión que este método su objetivo era regresar las credenciales

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.

2 participants