Skip to content

Commit

Permalink
fix bug where api logout call is made when token expired
Browse files Browse the repository at this point in the history
  • Loading branch information
Allie Crevier committed Jan 30, 2020
1 parent 47c04fc commit 58b7ba2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
8 changes: 4 additions & 4 deletions securedrop_client/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,10 +492,10 @@ def logout(self):
Call logout function in the API, reset the API object, and force the UI
to update into a logged out state.
"""
self.call_api(self.api.logout,
self.on_logout_success,
self.on_logout_failure)
self.api = None
if self.api is not None:
self.call_api(self.api.logout, self.on_logout_success, self.on_logout_failure)
self.api = None

self.api_job_queue.logout()
storage.mark_all_pending_drafts_as_failed(self.session)
self.gui.logout()
Expand Down
23 changes: 23 additions & 0 deletions tests/test_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,29 @@ def test_Controller_on_update_star_failed(homedir, config, mocker, session_maker
mock_gui.update_error_status.assert_called_once_with('Failed to update star.')


def test_Controller_logout_with_no_api(homedir, config, mocker, session_maker):
'''
Ensure we don't attempt to make an api call to logout when the api has been set to None
because token is invalid.
'''
mock_gui = mocker.MagicMock()
co = Controller('http://localhost', mock_gui, session_maker, homedir)
co.api = None
co.api_job_queue = mocker.MagicMock()
co.api_job_queue.logout = mocker.MagicMock()
co.call_api = mocker.MagicMock()
fail_draft_replies = mocker.patch(
'securedrop_client.storage.mark_all_pending_drafts_as_failed')

co.logout()

co.call_api.assert_not_called()
co.api_job_queue.logout.assert_called_once_with()
co.gui.logout.assert_called_once_with()
msg = 'Client logout successful'
fail_draft_replies.called_once_with(co.session)


def test_Controller_logout_success(homedir, config, mocker, session_maker):
"""
Ensure the API is called on logout and if the API call succeeds,
Expand Down

0 comments on commit 58b7ba2

Please sign in to comment.