Skip to content

Commit

Permalink
Merge pull request #150 from freedomofpress/fix-crash-in-offline-mode
Browse files Browse the repository at this point in the history
Fix crash in offline mode
  • Loading branch information
heartsucker authored Nov 11, 2018
2 parents 7347c84 + 4c4dd11 commit 17f055b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions securedrop_client/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,10 @@ def on_file_download(self, source_db_object, message):
Download the file associated with the associated message (which may
be a Submission or Reply).
"""
if not self.api: # Then we should tell the user they need to login.
self.on_action_requiring_login()
return

if isinstance(message, models.Submission):
# Handle submissions.
func = self.api.download_submission
Expand Down
3 changes: 3 additions & 0 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Tests for the app module, which sets things up and runs the application.
"""
import os
import platform
import pytest
import sys
from PyQt5.QtWidgets import QApplication
Expand Down Expand Up @@ -46,6 +47,8 @@ def test_configure_logging(safe_tmpdir):
assert sys.excepthook == excepthook


@pytest.mark.skipif(platform.system() != 'Linux',
reason="concurrent app prevention skipped on non Linux")
@mock.patch('securedrop_client.app.sys.exit')
@mock.patch('securedrop_client.app.QMessageBox')
class TestSecondInstancePrevention(object):
Expand Down
21 changes: 21 additions & 0 deletions tests/test_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,27 @@ def test_Client_on_file_downloaded_decrypt_failure(safe_tmpdir):
"Failed to download and decrypt file, please try again.")


def test_Client_on_file_download_user_not_signed_in(safe_tmpdir):
"""
If a user clicks the download button but is not logged in,
an error should appear.
"""
mock_gui = mock.MagicMock()
mock_session = mock.MagicMock()
cl = Client('http://localhost', mock_gui, mock_session, str(safe_tmpdir))
source = models.Source('source-uuid', 'testy-mctestface', False,
'mah pub key', 1, False, datetime.now())
submission = models.Submission(source, 'submission-uuid', 1234,
'myfile.doc.gpg', 'http://myserver/myfile')
cl.on_action_requiring_login = mock.MagicMock()
cl.api = None
submission_sdk_object = mock.MagicMock()
with mock.patch('sdclientapi.Submission') as mock_submission:
mock_submission.return_value = submission_sdk_object
cl.on_file_download(source, submission)
cl.on_action_requiring_login.assert_called_once_with()


def test_Client_on_download_timeout(safe_tmpdir):
mock_gui = mock.MagicMock()
mock_session = mock.MagicMock()
Expand Down

0 comments on commit 17f055b

Please sign in to comment.