예제 #1
0
def test_Controller_on_file_downloaded_api_failure(homedir, config, mocker):
    '''
    Using the `config` fixture to ensure the config is written to disk.
    '''
    mock_gui = mocker.MagicMock()
    mock_session = mocker.MagicMock()
    co = Controller('http://localhost', mock_gui, mock_session, homedir)
    co.file_ready = mocker.MagicMock()  # signal when file is downloaded
    co.update_sources = mocker.MagicMock()
    co.api_runner = mocker.MagicMock()

    test_filename = "1-my-file-location-msg.gpg"
    co.api_runner.result = ("", test_filename)
    co.call_reset = mocker.MagicMock()
    co.set_status = mocker.MagicMock()
    result_data = Exception('error message')
    submission_db_object = mocker.MagicMock()
    submission_db_object.uuid = 'myuuid'
    submission_db_object.filename = 'filename'

    co.on_file_download_failure(result_data,
                                current_object=submission_db_object)

    co.set_status.assert_called_once_with(
        "The file download failed. Please try again.")
    co.file_ready.emit.assert_not_called()
예제 #2
0
def test_Controller_on_file_downloaded_success(homedir, config, mocker):
    '''
    Using the `config` fixture to ensure the config is written to disk.
    '''
    mock_gui = mocker.MagicMock()
    mock_session = mocker.MagicMock()
    co = Controller('http://localhost', mock_gui, mock_session, homedir)
    co.update_sources = mocker.MagicMock()
    co.api_runner = mocker.MagicMock()
    co.file_ready = mocker.MagicMock()  # signal when file is downloaded

    test_filename = "1-my-file-location-msg.gpg"
    test_object_uuid = 'uuid-of-downloaded-object'
    co.call_reset = mocker.MagicMock()
    result_data = ('this-is-a-sha256-sum', test_filename)
    submission_db_object = mocker.MagicMock()
    submission_db_object.uuid = test_object_uuid
    submission_db_object.filename = test_filename
    mock_storage = mocker.patch('securedrop_client.logic.storage')
    mock_gpg = mocker.patch.object(co.gpg,
                                   'decrypt_submission_or_reply',
                                   return_value='filepath')
    mocker.patch('shutil.move')

    co.on_file_download_success(result_data,
                                current_object=submission_db_object)

    mock_gpg.call_count == 1
    mock_storage.mark_file_as_downloaded.assert_called_once_with(
        test_object_uuid, mock_session)
    mock_storage.set_object_decryption_status_with_content.assert_called_once_with(
        submission_db_object, mock_session, True)

    # Signal should be emitted with UUID of the successfully downloaded object
    co.file_ready.emit.assert_called_once_with(test_object_uuid)
예제 #3
0
def test_Controller_on_sync_success_with_key_import_fail(
        homedir, config, mocker):
    """
    If there's a result to syncing, then update local storage.
    This is it to check that we can gracefully handle an import failure.
    Using the `config` fixture to ensure the config is written to disk.
    """
    mock_gui = mocker.MagicMock()
    mock_session = mocker.MagicMock()
    co = Controller('http://localhost', mock_gui, mock_session, homedir)
    co.update_sources = mocker.MagicMock()
    co.api_runner = mocker.MagicMock()

    mock_source = mocker.MagicMock()
    mock_source.key = {
        'type': 'PGP',
        'public': PUB_KEY,
    }

    mock_sources = [mock_source]
    result_data = (mock_sources, 'submissions', 'replies')

    co.call_reset = mocker.MagicMock()
    mock_storage = mocker.patch('securedrop_client.logic.storage')
    mocker.patch.object(co.gpg, 'import_key', side_effect=CryptoError)
    co.on_sync_success(result_data)
    mock_storage.update_local_storage. \
        assert_called_once_with(mock_session, mock_sources, "submissions",
                                "replies",
                                os.path.join(homedir, 'data'))
    co.update_sources.assert_called_once_with()
예제 #4
0
def test_Controller_on_update_star_success(homedir, config, mocker):
    """
    If the starring occurs successfully, then a sync should occur to update
    locally.
    Using the `config` fixture to ensure the config is written to disk.
    """
    mock_gui = mocker.MagicMock()
    mock_session = mocker.MagicMock()
    co = Controller('http://localhost', mock_gui, mock_session, homedir)
    result = True
    co.call_reset = mocker.MagicMock()
    co.sync_api = mocker.MagicMock()
    co.on_update_star_success(result)
    co.sync_api.assert_called_once_with()
    mock_gui.clear_error_status.assert_called_once_with()
예제 #5
0
def test_Controller_on_update_star_failed(homedir, config, mocker):
    """
    If the starring does not occur properly, then an error should appear
    on the error status sidebar, and a sync will not occur.
    Using the `config` fixture to ensure the config is written to disk.
    """
    mock_gui = mocker.MagicMock()
    mock_session = mocker.MagicMock()
    co = Controller('http://localhost', mock_gui, mock_session, homedir)
    result = Exception('boom')
    co.call_reset = mocker.MagicMock()
    co.sync_api = mocker.MagicMock()
    co.on_update_star_failure(result)
    co.sync_api.assert_not_called()
    mock_gui.update_error_status.assert_called_once_with(
        'Failed to update star.')
예제 #6
0
def test_Controller_on_sync_success(homedir, config, mocker):
    """
    If there's a result to syncing, then update local storage.
    Using the `config` fixture to ensure the config is written to disk.
    """
    mock_gui = mocker.MagicMock()
    mock_session = mocker.MagicMock()
    co = Controller('http://localhost', mock_gui, mock_session, homedir)
    co.update_sources = mocker.MagicMock()
    co.api_runner = mocker.MagicMock()
    co.gpg = mocker.MagicMock()

    result_data = ('sources', 'submissions', 'replies')

    co.update_sources = mocker.MagicMock()
    co.api_runner = mocker.MagicMock()

    mock_source = mocker.MagicMock()
    mock_source.key = {
        'type': 'PGP',
        'public': PUB_KEY,
    }

    mock_sources = [mock_source]

    result_data = (mock_sources, 'submissions', 'replies')

    co.call_reset = mocker.MagicMock()
    mock_storage = mocker.patch('securedrop_client.logic.storage')
    co.on_sync_success(result_data)
    mock_storage.update_local_storage. \
        assert_called_once_with(mock_session, mock_sources, "submissions",
                                "replies",
                                os.path.join(homedir, 'data'))

    co.update_sources.assert_called_once_with()