Skip to content

Fixes for return_on_mfa code#92

Merged
felipao-mx merged 12 commits intomatin:mainfrom
cyberjunky:mfa-fixes
Mar 13, 2025
Merged

Fixes for return_on_mfa code#92
felipao-mx merged 12 commits intomatin:mainfrom
cyberjunky:mfa-fixes

Conversation

@cyberjunky
Copy link
Copy Markdown
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.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jan 22, 2025

Walkthrough

The pull request introduces changes to the handling of Multi-Factor Authentication (MFA) in the Garth library's login process. Key modifications are made across several files, including README.md, garth/http.py, and garth/sso.py, updating how login results are returned and processed when MFA is required. The version number is incremented to 0.5.3 to reflect these changes.

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 for token handling
garth/sso.py - Modified MFA return value structure to return a tuple with "needs_mfa" and client state dictionary
garth/version.py - Incremented version from 0.5.2 to 0.5.3
tests/test_http.py - Reformatted assertion in test_configure_pool_connections for clarity
- Added new test test_resume_login for testing resume_login method
tests/test_sso.py - Updated assertions in test_login_return_on_mfa to reflect new MFA return structure

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.

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b633e1d and fd9f521.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (1)
  • tests/test_http.py (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`tests/**`: - test functions shouldn't have a return type hi...

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

  • it's ok to use assert instead of pytest.assume()
  • tests/test_http.py
🔇 Additional comments (2)
tests/test_http.py (2)

116-118: Good improvement on assertion message!

Adding a descriptive error message makes the test more maintainable by clearly indicating what might be wrong when the test fails.


252-278:

Details

✅ Verification successful

Great addition of test for MFA functionality!

The test thoroughly verifies the new MFA login flow, checking both the initial return structure when MFA is needed and the resumed login with an MFA code.

One minor observation: The comment on line 269 mentions "obtain from custom login" but uses a hardcoded value. This is fine for testing purposes, but in a real scenario, this code would come from an actual MFA process.

Also, consider adding a test case for handling invalid MFA codes in the future to ensure robust error handling.


Review Approval: MFA Test Functionality Validated

The MFA login test in tests/test_http.py is well-constructed, accurately verifying both the initial MFA-required state and the resumed login flow. The use of a hardcoded MFA code (as noted on line 269) is acceptable for the purpose of testing. As a future improvement, consider adding a test case to handle invalid MFA codes to bolster error handling.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
  • @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
Copy Markdown
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

@cyberjunky
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

@cyberjunky
Copy link
Copy Markdown
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..

@felipao-mx
Copy link
Copy Markdown
Collaborator

hi @cyberjunky ! thanks for fixing lint errors. I totally understand that VCR sometimes can be tricky. Would you be ok if I commit the fixes directly to your branch? I'd be happy to help.

@cyberjunky
Copy link
Copy Markdown
Contributor Author

hi @cyberjunky ! thanks for fixing lint errors. I totally understand that VCR sometimes can be tricky. Would you be ok if I commit the fixes directly to your branch? I'd be happy to help.

@felipao-mx yes please. I'm still struggling a little bit, in my limited time, how to record them with credentials. Any help is appreciated! I found out I need to call login() again after the first mfa authorisation and oauth keys were created, but that is no big deal and can be fixed later if needed.

@cyberjunky
Copy link
Copy Markdown
Contributor Author

I'm afraid I'm forced to migrate parts of garths code in my library. I'm kind of stuck with this casette/tests stuff.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (922f3c3) to head (fd9f521).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #92   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           34        34           
  Lines         1335      1356   +21     
=========================================
+ Hits          1335      1356   +21     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@felipao-mx felipao-mx merged commit a05eb5b into matin:main Mar 13, 2025
18 checks passed
@felipao-mx
Copy link
Copy Markdown
Collaborator

v0.5.3 released! thanks @cyberjunky for your contribution

@cyberjunky
Copy link
Copy Markdown
Contributor Author

@felipao-mx wow, nice, thank you very much, I can continue with coding and hopefully close several related requests!

@cyberjunky cyberjunky deleted the mfa-fixes branch March 13, 2025 08:53
@coderabbitai coderabbitai bot mentioned this pull request Jun 3, 2025
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