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

support return_on_mfa #84

Merged
merged 4 commits into from
Dec 11, 2024
Merged

support return_on_mfa #84

merged 4 commits into from
Dec 11, 2024

Conversation

matin
Copy link
Owner

@matin matin commented Dec 11, 2024

closes #41
replaces #68

Summary by CodeRabbit

  • New Features

    • Enhanced login functionality with improved multi-factor authentication (MFA) handling.
    • Added a method to resume the login process after MFA code entry.
  • Bug Fixes

    • Improved error handling for gzip response processing.
  • Documentation

    • Updated README for better clarity on MFA handling and improved formatting for badge links.
  • Chores

    • Version number updated from "0.5.0" to "0.5.1".

@matin matin self-assigned this Dec 11, 2024
Copy link
Contributor

coderabbitai bot commented Dec 11, 2024

Warning

Rate limit exceeded

@matin has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 18 minutes and 33 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 08d620d and 89e2b9a.

📒 Files selected for processing (1)
  • garth/sso.py (4 hunks)

Walkthrough

The changes in this pull request include updates to the .markdownlint.json file, where a new rule "MD046" is added and set to false. The README.md file has been reformatted for better readability, with minor content updates. The garth/sso.py file introduces significant enhancements to the login functionality, particularly for multi-factor authentication (MFA), including new methods for handling MFA. The tests/test_sso.py file adds a test for the new MFA handling behavior, while tests/conftest.py improves error handling in the sanitize_response function.

Changes

File Change Summary
.markdownlint.json Added rule "MD046" set to false.
README.md Reformatted badge links and image links; updated MFA handler section for clarity.
garth/sso.py Added _complete_login and resume_login methods; modified login to include return_on_mfa parameter.
tests/conftest.py Enhanced error handling in sanitize_response function for gzip responses.
tests/test_sso.py Added test_login_return_on_mfa to test MFA login process and resuming login.

Assessment against linked issues

Objective Addressed Explanation
Implement MFA handling in login process (#41)
Allow login method to return state if MFA is required (#41)
Introduce method to handle MFA separately (#41)

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. (Experiment)
  • @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

codecov bot commented Dec 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (b557b88) to head (89e2b9a).
Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #84   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           34        34           
  Lines         1292      1326   +34     
=========================================
+ Hits          1292      1326   +34     
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.

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: 4

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between b557b88 and 3dee595.

⛔ Files ignored due to path filters (1)
  • tests/cassettes/test_login_return_on_mfa.yaml is excluded by !tests/**/cassettes/**
📒 Files selected for processing (5)
  • .markdownlint.json (1 hunks)
  • README.md (5 hunks)
  • garth/sso.py (4 hunks)
  • tests/conftest.py (1 hunks)
  • tests/test_sso.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
tests/conftest.py (1)

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

  • it's ok to use assert instead of pytest.assume()
tests/test_sso.py (1)

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

  • it's ok to use assert instead of pytest.assume()
🪛 GitHub Check: codecov/patch
tests/conftest.py

[warning] 118-119: tests/conftest.py#L118-L119
Added lines #L118 - L119 were not covered by tests

🔇 Additional comments (4)
.markdownlint.json (1)

5-5: Disabling MD046 rule is acceptable

The addition of "MD046": false to the markdownlint configuration is acceptable if it aligns with the project's documentation style preferences.

tests/test_sso.py (1)

68-92: New test test_login_return_on_mfa is well-implemented

The test correctly verifies the MFA login flow using the return_on_mfa parameter and adheres to the coding guidelines. No issues found.

README.md (2)

133-147: Well-documented MFA handling options!

The documentation clearly explains both the default behavior and advanced MFA handling options, which aligns perfectly with the PR objectives for Home-Assistant integration. The examples are clear and demonstrate both the simple custom prompt handler and the more flexible separate MFA handling approach.


3-9: LGTM: Improved readability of URLs

The reformatting of badge links and image URLs across multiple lines enhances the readability of the markdown source without affecting the rendered output.

Also applies to: 23-24, 35-36, 42-43

"client": client,
},
}

handle_mfa(client, SIGNIN_PARAMS, prompt_mfa)
title = get_title(client.last_resp.text)

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

Replace assert with exception handling for login success check

Using assert statements to check the success of the login is not recommended in production code. Replace the assertion with exception handling to properly manage unexpected titles.

Apply this diff to fix the issue:

-    assert title == "Success", f"Unexpected title: {title}"
+    if title != "Success":
+        raise GarthException(f"Unexpected title: {title}")

Committable suggestion skipped: line range outside the PR's diff.

garth/sso.py Outdated
)

title = get_title(client.last_resp.text)
assert title == "Success", f"Unexpected title: {title}"
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

Replace assert with exception handling in resume_login

Similarly, replace the assert statement in the resume_login function with appropriate exception handling to ensure robustness.

Apply this diff to fix the issue:

-    assert title == "Success", f"Unexpected title: {title}"
+    if title != "Success":
+        raise GarthException(f"Unexpected title: {title}")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
assert title == "Success", f"Unexpected title: {title}"
if title != "Success":
raise GarthException(f"Unexpected title: {title}")

garth/sso.py Outdated Show resolved Hide resolved
tests/conftest.py Outdated Show resolved Hide resolved
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

📥 Commits

Reviewing files that changed from the base of the PR and between 3dee595 and 08d620d.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • garth/version.py (1 hunks)
  • tests/conftest.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
tests/conftest.py (1)

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

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

118-119: Add tests to cover exception handling in sanitize_response

The added exception handling for gzip.BadGzipFile enhances robustness. However, these lines are not covered by tests. Consider adding a test case where the response body is not valid gzip data to ensure this code path is executed and verified.


116-121: 🧹 Nitpick (assertive)

Consider logging the exception for debugging purposes.

The empty except block silently ignores gzip decompression failures. While this might be acceptable for sanitizing test responses, adding a debug log would help troubleshoot issues during test development.

Apply this diff to add logging:

             try:
                 body = gzip.GzipFile(fileobj=buffer).read()
             except gzip.BadGzipFile:  # pragma: no cover
-                ...
+                import logging
+                logging.debug("Failed to decompress gzip response body")
             else:
                 response["body"]["string"] = body

Likely invalid or redundant comment.

garth/version.py Show resolved Hide resolved
@matin matin merged commit 3004df3 into main Dec 11, 2024
20 checks passed
@matin matin deleted the return_on_mfa branch December 11, 2024 08:25
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.

Requirements and suggestions related to MFA handling
1 participant