diff options
author | Alex Gaynor <alex.gaynor@gmail.com> | 2016-07-03 23:38:48 -0400 |
---|---|---|
committer | Hynek Schlawack <hs@ox.cx> | 2016-07-04 05:38:48 +0200 |
commit | 7778e796de33dc6b582723698410de0047e97bb0 (patch) | |
tree | 69935280289cccab669de7e9319f53fe87889523 | |
parent | 5bb2bd19dcb015bf7f2bfb8817da86fd0dc94672 (diff) | |
download | pyopenssl-7778e796de33dc6b582723698410de0047e97bb0.tar.gz |
Write a few more tests for coverage (#501)
-rw-r--r-- | src/OpenSSL/crypto.py | 3 | ||||
-rw-r--r-- | tests/test_crypto.py | 19 |
2 files changed, 19 insertions, 3 deletions
diff --git a/src/OpenSSL/crypto.py b/src/OpenSSL/crypto.py index 869bbb4..91cc8c8 100644 --- a/src/OpenSSL/crypto.py +++ b/src/OpenSSL/crypto.py @@ -997,8 +997,7 @@ class X509(object): raise TypeError("pkey must be a PKey instance") set_result = _lib.X509_set_pubkey(self._x509, pkey._pkey) - if not set_result: - _raise_current_error() + _openssl_assert(set_result == 1) def sign(self, pkey, digest): """ diff --git a/tests/test_crypto.py b/tests/test_crypto.py index 5b2c48a..10d2427 100644 --- a/tests/test_crypto.py +++ b/tests/test_crypto.py @@ -971,6 +971,9 @@ class X509NameTests(TestCase): self.assertEqual(name.commonName, "quux") self.assertEqual(name.CN, "quux") + with pytest.raises(AttributeError): + name.foobar + def test_copy(self): """ :py:class:`X509Name` creates a new :py:class:`X509NameType` instance @@ -1048,6 +1051,8 @@ class X509NameTests(TestCase): assertNotEqual(self._x509name(CN="foo"), self._x509name(OU="foo")) + assertNotEqual(self._x509name(), object()) + def _inequality(a, b, assertTrue, assertFalse): assertTrue(a < b) assertTrue(a <= b) @@ -1848,6 +1853,15 @@ WpOdIpB8KksUTCzV591Nr1wd cert = X509() self.assertRaises(Error, cert.get_pubkey) + def test_set_pubkey_wrong_type(self): + """ + :obj:`X509.set_pubkey` raises :obj:`TypeError` when given an object of + the wrong type. + """ + cert = X509() + with pytest.raises(TypeError): + cert.set_pubkey(object()) + def test_subject_name_hash_wrong_args(self): """ :py:obj:`X509.subject_name_hash` raises :py:obj:`TypeError` if called @@ -2850,7 +2864,10 @@ class LoadCertificateTests(TestCase): neither :py:obj:`FILETYPE_PEM` nor :py:obj:`FILETYPE_ASN1` then :py:class:`ValueError` is raised. """ - self.assertRaises(ValueError, load_certificate_request, object(), b"") + with pytest.raises(ValueError): + load_certificate_request(object(), b"") + with pytest.raises(ValueError): + load_certificate(object(), b"") class PKCS7Tests(TestCase): |