-
Notifications
You must be signed in to change notification settings - Fork 7
π§βπ» Handle already logged in state #103
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4ab8cc7
Handle already logged in state
alejsdev 09b24da
Update
alejsdev 45fc73b
Update
alejsdev d908e3b
Add test
alejsdev 946fc05
Update test
alejsdev 6f24161
Add verify token tests
alejsdev 96cfe83
Format
alejsdev 84f9509
Merge branch 'main' into ref/update-login
alejsdev 0ac6ee7
Update login.py
alejsdev d05a0da
Update test_notify_already_logged_in_user
alejsdev 5b8a2e9
Update login message for exp session and add test for token expiration
alejsdev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -162,3 +162,48 @@ def test_fetch_access_token_handles_500_error(respx_mock: respx.MockRouter) -> N | |
| with APIClient() as client: | ||
| with pytest.raises(httpx.HTTPStatusError): | ||
| _fetch_access_token(client, "test_device_code", 5) | ||
|
|
||
|
|
||
| @pytest.mark.respx(base_url=settings.base_api_url) | ||
| def test_notify_already_logged_in_user( | ||
| respx_mock: respx.MockRouter, logged_in_cli: None | ||
| ) -> None: | ||
| respx_mock.get("/users/me").mock( | ||
| return_value=Response(200, json={"email": "[email protected]"}) | ||
| ) | ||
|
|
||
| result = runner.invoke(app, ["login"]) | ||
|
|
||
| assert result.exit_code == 0 | ||
| assert "Already logged in as [email protected]" in result.output | ||
| assert "Run fastapi logout first if you want to switch accounts." in result.output | ||
|
|
||
|
|
||
| @pytest.mark.respx(base_url=settings.base_api_url) | ||
| def test_verify_token_returns_false_on_unauthorized( | ||
| respx_mock: respx.MockRouter, | ||
| ) -> None: | ||
| from fastapi_cloud_cli.commands.login import _verify_token | ||
| from fastapi_cloud_cli.utils.api import APIClient | ||
|
|
||
| respx_mock.get("/users/me").mock(return_value=Response(401)) | ||
|
|
||
| with APIClient() as client: | ||
| is_valid, email = _verify_token(client) | ||
|
|
||
| assert is_valid is False | ||
| assert email is None | ||
|
|
||
|
|
||
| @pytest.mark.respx(base_url=settings.base_api_url) | ||
| def test_verify_token_returns_false_on_forbidden(respx_mock: respx.MockRouter) -> None: | ||
| from fastapi_cloud_cli.commands.login import _verify_token | ||
| from fastapi_cloud_cli.utils.api import APIClient | ||
|
|
||
| respx_mock.get("/users/me").mock(return_value=Response(403)) | ||
|
|
||
| with APIClient() as client: | ||
| is_valid, email = _verify_token(client) | ||
|
|
||
| assert is_valid is False | ||
| assert email is None | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I made a PR to avoid doing any HTTP call, we will validate that the token is still valid
#105
(it could be invalid for other reasons, but I think I prefer avoiding doing an HTTP call)
what do you think?