Exemple #1
0
 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")
Exemple #2
0
    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)
Exemple #3
0
    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
Exemple #4
0
    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()
Exemple #5
0
    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)
Exemple #6
0
    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)
Exemple #7
0
    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
Exemple #8
0
    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()
Exemple #9
0
 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
Exemple #10
0
    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)
Exemple #11
0
 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
Exemple #12
0
    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)
Exemple #13
0
    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")