Skip to content

Commit

Permalink
no longer mark replies as failed if they time out
Browse files Browse the repository at this point in the history
  • Loading branch information
Allie Crevier committed Feb 25, 2020
1 parent 8adf1f2 commit ef0a5bf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
7 changes: 0 additions & 7 deletions securedrop_client/api_jobs/uploads.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,6 @@ def call_api(self, api_client: API, session: Session) -> str:
message = "Failed to send reply for source {id} due to Exception: {error}".format(
id=self.source_uuid, error=e)

# Update draft reply send status to FAILED
reply_status = session.query(ReplySendStatus).filter_by(
name=ReplySendStatusCodes.FAILED.value).one()
draft_reply_db_object.send_status_id = reply_status.id
session.add(draft_reply_db_object)
session.commit()

raise SendReplyJobTimeoutError(message, self.reply_uuid)
except Exception as e:
message = "Failed to send reply for source {id} due to Exception: {error}".format(
Expand Down
5 changes: 4 additions & 1 deletion securedrop_client/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,10 @@ def on_reply_failure(
exception: Union[SendReplyJobError, SendReplyJobTimeoutError]
) -> None:
logger.debug('{} failed to send'.format(exception.reply_uuid))
self.reply_failed.emit(exception.reply_uuid)

# only emit failure signal for non-timeout errors
if isinstance(exception, SendReplyJobError):
self.reply_failed.emit(exception.reply_uuid)

def get_file(self, file_uuid: str) -> db.File:
file = storage.get_file(self.session, file_uuid)
Expand Down
19 changes: 18 additions & 1 deletion tests/test_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from securedrop_client.api_jobs.downloads import (
DownloadChecksumMismatchException, DownloadDecryptionException, DownloadException
)
from securedrop_client.api_jobs.uploads import SendReplyJobError
from securedrop_client.api_jobs.uploads import SendReplyJobError, SendReplyJobTimeoutError

with open(os.path.join(os.path.dirname(__file__), 'files', 'test-key.gpg.pub.asc')) as f:
PUB_KEY = f.read()
Expand Down Expand Up @@ -1394,6 +1394,23 @@ def test_Controller_on_reply_failure(homedir, mocker, session_maker):
reply_succeeded.emit.assert_not_called()


def test_Controller_on_reply_failure_for_timeout(homedir, mocker, session_maker):
'''
Check that when the method is called, the client emits the correct signal.
'''
co = Controller('http://localhost', mocker.MagicMock(), session_maker, homedir)
reply_succeeded = mocker.patch.object(co, 'reply_succeeded')
reply_failed = mocker.patch.object(co, 'reply_failed')
debug_logger = mocker.patch('securedrop_client.logic.logger.debug')

exception = SendReplyJobTimeoutError('mock_error_message', 'mock_reply_uuid')
co.on_reply_failure(exception)

debug_logger.assert_called_once_with('{} failed to send'.format('mock_reply_uuid'))
reply_failed.emit.assert_not_called()
reply_succeeded.emit.assert_not_called()


def test_Controller_is_authenticated_property(homedir, mocker, session_maker):
'''
Check that the @property `is_authenticated`:
Expand Down

0 comments on commit ef0a5bf

Please sign in to comment.