Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/client/_clientwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,9 @@ def try_to_auto_login(self) -> None:
self.show_login_widget()

def on_login_attempt_failed(self) -> None:
self.disconnect_()
self.state = ClientState.DISCONNECTED
self._auto_relogin = False
self.show_login_widget()
Comment thread
coderabbitai[bot] marked this conversation as resolved.

def get_creds_and_login(self) -> None:
Expand Down
1 change: 1 addition & 0 deletions src/oauth/oauth_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def check_token_scopes(self) -> None:

def on_request_failed(self, error: QOAuth2AuthorizationCodeFlow.Error) -> None:
self._logger.error("Request failed with an error: %s", error)
self.setToken("")
self.stop_checking_expiration()

def setup_credentials(self) -> None:
Expand Down
28 changes: 28 additions & 0 deletions tests/unit_tests/client/test_authentication.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from unittest.mock import call


def test_login_failure_allows_fresh_connection(application, client_instance, mocker):
from src.client.clientstate import ClientState
from src.util.gameurl import GameUrl

disconnect = mocker.patch.object(client_instance, "disconnect_")
show_login_widget = mocker.patch.object(client_instance, "show_login_widget")
mocker.patch.object(client_instance, "_state", ClientState.LOGGED_IN)
mocker.patch.object(client_instance, "_auto_relogin", True)
lifecycle = mocker.Mock()
lifecycle.attach_mock(disconnect, "disconnect")
lifecycle.attach_mock(show_login_widget, "show_login_widget")

client_instance.on_login_attempt_failed()

assert client_instance.state == ClientState.DISCONNECTED
assert not client_instance._auto_relogin
assert lifecycle.mock_calls == [call.disconnect(), call.show_login_widget()]

mocker.patch.object(client_instance.replayServer, "doListen", return_value=True)
mocker.patch.object(client_instance.replayServer, "serverPort", return_value=12345)
connect = mocker.patch.object(client_instance.lobby_connection, "do_connect")
mocker.patch.object(GameUrl, "PORT", -1)

assert client_instance.do_connect()
connect.assert_called_once_with()
11 changes: 11 additions & 0 deletions tests/unit_tests/oauth/test_oauth_flow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def test_request_failure_discards_access_token(application):
from PyQt6.QtNetworkAuth import QAbstractOAuth

from src.oauth.oauth_flow import OAuth2Flow

flow = OAuth2Flow()
flow.setToken("expired-token")

flow.requestFailed.emit(QAbstractOAuth.Error.NetworkError)

assert flow.token() == ""