def test_sign_message_with_default_key(self, gpg_mock, mocker, monkeypatch): gpg_mock._gpg.sign.return_value = self.mock_response(mocker) monkeypatch.setattr(gpg_mock.keys.secret, "current", "CURRENT_KEY") GPG.sign(gpg_mock, self.message, event=False) gpg_mock._gpg.sign.assert_called_once_with(self.message, keyid="CURRENT_KEY")
def test_event(self, gpg_mock, mocker): gpg_mock._gpg.verify.return_value = self.mock_response(mocker) subscription = util.subscribe_event(self.event_class) GPG.verify(gpg_mock, self.signed) event = subscription() assert isinstance(event.gpg, GPG) assert isinstance(event.result, self.response_class)
def test_event(self, gpg_mock, mocker): gpg_mock._gpg.sign.return_value = self.mock_response(mocker) subscription = util.subscribe_event(self.event_class) GPG.sign(gpg_mock, self.message) event = subscription() assert isinstance(event.gpg, GPG) assert event.result.data == self.signed
def test_event(self, gpg_mock, mocker): gpg_mock._gpg.encrypt.return_value = self.mock_response(mocker) subscription = util.subscribe_event(self.event_class) GPG.encrypt(gpg_mock, self.message, key="fingerprint") event = subscription() assert isinstance(event.gpg, GPG) assert event.result.data == self.ciphertext.decode()
def test_failure_raises_exception(self, gpg_mock, mocker): gpg_mock._gpg.verify.return_value = self.mock_response( mocker, status="signature invalid", valid=False, stderr="error output", pubkey_fingerprint=None, ) with pytest.raises(exceptions.MessageVerifyError): GPG.verify(gpg_mock, self.signed)
def test_encrypt_message_with_default_key(self, gpg_mock, mocker, monkeypatch): gpg_mock._gpg.encrypt.return_value = self.mock_response(mocker) monkeypatch.setattr(gpg_mock.keys.secret, "current", "CURRENT_KEY") GPG.encrypt(gpg_mock, self.message, event=False) gpg_mock._gpg.encrypt.assert_called_once_with(self.message, "CURRENT_KEY", symmetric=False, sign=True)
def test_decrypt_ciphertext(self, gpg_mock, mocker): gpg_mock._gpg.decrypt.return_value = self.mock_response(mocker) result = GPG.decrypt(gpg_mock, self.ciphertext, event=False) gpg_mock._gpg.decrypt.assert_called_once_with(self.ciphertext) assert result == self.message
def test_encrypt_message(self, gpg_mock, fingerprint, symmetric, sign, mocker): gpg_mock._gpg.encrypt.return_value = self.mock_response(mocker) result = GPG.encrypt( gpg_mock, self.message, key=fingerprint, symmetric=symmetric, sign=sign, event=False, ) gpg_mock._gpg.encrypt.assert_called_once_with(self.message, fingerprint, symmetric=symmetric, sign=sign) assert result == self.ciphertext.decode()
def test_verify_signed_message(self, gpg_mock, mocker): gpg_mock._gpg.verify.return_value = self.mock_response(mocker) result = GPG.verify(gpg_mock, self.signed, event=False) assert result is True
def test_failure_raises_exception(self, gpg_mock, mocker): gpg_mock._gpg.sign.return_value = self.mock_response( mocker, status="signature failed", stderr="error output") with pytest.raises(exceptions.MessageSignError): GPG.sign(gpg_mock, self.message)
def test_sign_message(self, gpg_mock, keyid, mocker): gpg_mock._gpg.sign.return_value = self.mock_response(mocker) result = GPG.sign(gpg_mock, self.message, key=keyid, event=False) gpg_mock._gpg.sign.assert_called_once_with(self.message, keyid=keyid) assert result == self.signed
def test_failure_raises_exception(self, gpg_mock, mocker): gpg_mock._gpg.decrypt.return_value = self.mock_response( mocker, status="decryption failed", stderr="error output") with pytest.raises(exceptions.MessageDecryptError): GPG.decrypt(gpg_mock, self.ciphertext)
def test_failure_raises_exception(self, gpg_mock, mocker): gpg_mock._gpg.encrypt.return_value = self.mock_response( mocker, status="encryption failed", stderr="error output") with pytest.raises(exceptions.MessageEncryptError): GPG.encrypt(gpg_mock, self.message, "fingerprint")