-
Notifications
You must be signed in to change notification settings - Fork 32
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
Conversation
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 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. 📒 Files selected for processing (1)
WalkthroughThe changes in this pull request include updates to the Changes
Assessment against linked issues
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this 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
⛔ 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 ofpytest.assume()
tests/test_sso.py (1)
Pattern tests/**
: - test functions shouldn't have a return type hint
- it's ok to use
assert
instead ofpytest.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) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
assert title == "Success", f"Unexpected title: {title}" | |
if title != "Success": | |
raise GarthException(f"Unexpected title: {title}") |
There was a problem hiding this 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
⛔ 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 ofpytest.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.
closes #41
replaces #68
Summary by CodeRabbit
New Features
Bug Fixes
Documentation
Chores