def test_ensure_passphrase_raises_wrong_passphrase(mocker, mock_db, mock_cryptor): mock_cryptor.check.side_effect = ValueError mock_db._storage.path = 'path' with pytest.raises(click.ClickException) as excinfo: cli.ensure_passphrase(mock_db, 'passphrase') assert 'Wrong passphrase' in excinfo.value.message
def test_ensure_passphrase_logs_error_when_decrypt_result_not_ok(mocker): mock_logging = mocker.patch('passpie.cli.logging') mock_encrypt = mocker.patch('passpie.cli.encrypt') mock_decrypt = mocker.patch('passpie.cli.decrypt', return_value='NOT OK') config = {'recipient': 'recipient', 'homedir': 'homedir'} message_full = "Wrong passphrase for recipient: {} in homedir: {}".format( config['recipient'], config['homedir'], ) with pytest.raises(click.ClickException): cli.ensure_passphrase('passphrase', config=config) assert mock_logging.debug.called mock_logging.debug.assert_called_once_with(message_full)
def test_ensure_passphrase_calls_decrypt_with_encrypted_data(mocker): mock_logging = mocker.patch('passpie.cli.logging') mock_encrypt = mocker.patch('passpie.cli.encrypt') mock_decrypt = mocker.patch('passpie.cli.decrypt', return_value='OK') config = {'recipient': 'recipient', 'homedir': 'homedir'} cli.ensure_passphrase('passphrase', config=config) assert mock_encrypt.called assert mock_decrypt.called mock_encrypt.assert_called_once_with('OK', recipient=config['recipient'], homedir=config['homedir']) mock_decrypt.assert_called_once_with(mock_encrypt.return_value, recipient=config['recipient'], passphrase='passphrase', homedir=config['homedir'])
def test_ensure_passphrase_returns_passphrase(mocker, mock_db, mock_cryptor): mock_db._storage.path = 'path' mock_cryptor.check.return_value = True passphrase = 'passphrase' result = cli.ensure_passphrase(mock_db, 'passphrase') assert result == passphrase