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

Fixes for return_on_mfa code #92

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Conversation

cyberjunky
Copy link
Contributor

@cyberjunky cyberjunky commented Jan 22, 2025

With these changes I got it working, some returns where missing, I could not get it working with returning one result variable.

Summary by CodeRabbit

  • New Features

    • Enhanced Multi-Factor Authentication (MFA) login handling with clearer result separation.
    • Improved token management during the login process.
  • Bug Fixes

    • Refined MFA login flow to provide clearer result handling.
  • Documentation

    • Updated README with new login method usage and MFA handling instructions.
  • Tests

    • Added new tests for the resume_login functionality.
  • Chores

    • Version bumped to 0.5.3.

Copy link
Contributor

coderabbitai bot commented Jan 22, 2025

Warning

Rate limit exceeded

@cyberjunky has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 14 minutes and 21 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between ea4621a and 41c5834.

📒 Files selected for processing (1)
  • tests/test_http.py (2 hunks)

Walkthrough

The pull request introduces changes to the Multi-Factor Authentication (MFA) handling process in the Garth library. The modifications primarily affect the login mechanism across multiple files, including README.md, garth/http.py, and garth/sso.py. The changes update how login results are returned and processed, specifically when MFA is required. The version number has been incremented to 0.5.3 to reflect these modifications.

Changes

File Change Summary
README.md - Updated MFA login example to use two-result unpacking
- Modified garth.login() and garth.resume_login() method calls
garth/http.py - Updated login() method to return OAuth1 and OAuth2 tokens
- Added new resume_login() method with similar token handling
garth/sso.py - Modified MFA return value structure
- Now returns a tuple with "needs_mfa" string and client state dictionary
garth/version.py - Incremented version from 0.5.2 to 0.5.3
tests/test_http.py - Reformatted assertion statement in test_configure_pool_connections for clarity
- Added new test test_resume_login for testing resume_login method

Sequence Diagram

sequenceDiagram
    participant User
    participant Garth
    participant SSO
    
    User->>Garth: login(email, password)
    Garth->>SSO: Attempt login
    alt MFA Required
        SSO-->>Garth: Return ("needs_mfa", client_state)
        Garth-->>User: Prompt for MFA code
        User->>Garth: Provide MFA code
        Garth->>SSO: Resume login with MFA
        SSO-->>Garth: Return OAuth1 and OAuth2 tokens
    else Login Successful
        SSO-->>Garth: Return OAuth1 and OAuth2 tokens
    end
    Garth-->>User: Complete login
Loading

Possibly related PRs

  • support return_on_mfa #84: The changes in the main PR are related to the modifications in the login function's return structure and the introduction of the resume_login method, which are also addressed in the retrieved PR that enhances MFA handling in the sso.py file.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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
Contributor

@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: 2

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 922f3c3 and 7de1671.

📒 Files selected for processing (4)
  • README.md (1 hunks)
  • garth/http.py (1 hunks)
  • garth/sso.py (1 hunks)
  • garth/version.py (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: CI
garth/http.py

[warning] Code formatting issues detected. File needs to be reformatted using Ruff formatter.


[warning] Trailing whitespace detected and needs to be removed.

🔇 Additional comments (3)
garth/http.py (1)

164-169: LGTM! The login method correctly handles the new return structure.

The changes properly unpack and store the OAuth tokens from the SSO login response.

🧰 Tools
🪛 GitHub Actions: CI

[warning] Code formatting issues detected. File needs to be reformatted using Ruff formatter.


[warning] Trailing whitespace detected and needs to be removed.

garth/version.py (1)

1-1: LGTM! Version bump is appropriate.

The increment to 0.5.3 aligns with semantic versioning for a backward-compatible bug fix.

README.md (1)

143-144: LGTM! Documentation accurately reflects the implementation changes.

The example code has been updated to demonstrate the new MFA handling flow, making it clearer and more explicit.

Also applies to: 146-146

garth/sso.py Show resolved Hide resolved
garth/http.py Outdated Show resolved Hide resolved
@cyberjunky
Copy link
Contributor Author

@matin Hi there, can you please have a quick look and merge if you have the time?
Otherwise I'm thinking it's maybe better to integrate parts of the code in Garmin Connect package.

@matin
Copy link
Owner

matin commented Jan 28, 2025

@cyberjunky I apologize I haven't had a change to review. I'm adding @felipao-mx as a maintainer to review and merge

Copy link
Collaborator

@felipao-mx felipao-mx left a comment

Choose a reason for hiding this comment

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

hi @cyberjunky, thanks for your contribution! I have notice that some tests are not currently passing. Could you please take a look? I think these failing tests are related to the return type for "needs_mfa" case and lint checks.

Copy link
Contributor

@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: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f4e10d5 and ea4621a.

📒 Files selected for processing (1)
  • tests/test_http.py (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
tests/test_http.py (1)

Pattern tests/**: - test functions shouldn't have a return type hint

  • it's ok to use assert instead of pytest.assume()
🪛 GitHub Actions: CI
tests/test_http.py

[error] 254-254: CannotOverwriteExistingCassetteException: Can't overwrite existing cassette ('/home/runner/work/garth/garth/tests/cassettes/test_resume_login.yaml') in your current record mode ('none').

🔇 Additional comments (1)
tests/test_http.py (1)

116-118: LGTM! Clear and descriptive assertion message.

The reformatted assertion message improves readability while maintaining clear error reporting.

Comment on lines 252 to 264
@pytest.mark.vcr
def test_resume_login(client: Client):
client.oauth1_token, client.oauth2_token = client.login(
"[email protected]", "correct_password"
)
assert client.oauth1_token
assert client.oauth2_token
client.oauth1_token, client.oauth2_token = None, None
assert client.oauth1_token is None
assert client.oauth2_token is None
client.resume_login("[email protected]", "correct_password")
assert client.oauth1_token
assert client.oauth2_token
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Record VCR cassette for the new test.

The test logic is well-structured, but the pipeline is failing because the VCR cassette for test_resume_login is missing. You'll need to record the cassette first.

Run the test with VCR in record mode to generate the cassette:

#!/bin/bash
# Description: Record VCR cassette for test_resume_login
python -m pytest tests/test_http.py::test_resume_login --vcr-record=once
🧰 Tools
🪛 GitHub Actions: CI

[error] 254-254: CannotOverwriteExistingCassetteException: Can't overwrite existing cassette ('/home/runner/work/garth/garth/tests/cassettes/test_resume_login.yaml') in your current record mode ('none').

@cyberjunky
Copy link
Contributor Author

@felipao-mx I fixed the lint errors, not sure if I can fix the two tests. I frankly hate them, do not master them.
Will try again tomorrow, maybe..

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.

3 participants