From 6be674f00fe1b7939e75450f6b4bca2b023be548 Mon Sep 17 00:00:00 2001 From: redshiftzero Date: Sat, 10 Nov 2018 13:51:57 -0800 Subject: [PATCH 1/3] tests: skip concurrent app start tess on Non-Linux platforms --- tests/test_app.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_app.py b/tests/test_app.py index 95ea1d1b2..67a92292d 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -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 @@ -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): From 5078e5d031b9d30d41b3f7af3b21f417cf368f76 Mon Sep 17 00:00:00 2001 From: redshiftzero Date: Sat, 10 Nov 2018 13:52:59 -0800 Subject: [PATCH 2/3] test: regression test for #146 --- tests/test_logic.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/test_logic.py b/tests/test_logic.py index 649e6e6b1..d0dbb8b3b 100644 --- a/tests/test_logic.py +++ b/tests/test_logic.py @@ -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() From 4c4dd115dd5f67c39db8907297123caa0db76c3f Mon Sep 17 00:00:00 2001 From: redshiftzero Date: Sat, 10 Nov 2018 13:53:30 -0800 Subject: [PATCH 3/3] bugfix: show error when user tries to download doc in offline mode --- securedrop_client/logic.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/securedrop_client/logic.py b/securedrop_client/logic.py index f409a155e..79b17cfb8 100644 --- a/securedrop_client/logic.py +++ b/securedrop_client/logic.py @@ -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