Better tests for X509Store.add_cert and a fix
diff --git a/OpenSSL/crypto.py b/OpenSSL/crypto.py
index ad448b8..736227b 100644
--- a/OpenSSL/crypto.py
+++ b/OpenSSL/crypto.py
@@ -1034,8 +1034,8 @@
result = _api.X509_STORE_add_cert(self._store, cert._x509)
if not result:
- 1/0
- _raise_current_error()
+ _raise_current_error(Error)
+
X509StoreType = X509Store
diff --git a/OpenSSL/test/test_crypto.py b/OpenSSL/test/test_crypto.py
index a3fc79d..2ba06a6 100644
--- a/OpenSSL/test/test_crypto.py
+++ b/OpenSSL/test/test_crypto.py
@@ -1609,8 +1609,24 @@
def test_add_cert(self):
+ """
+ :py:obj:`X509Store.add_cert` adds a :py:obj:`X509` instance to the
+ certificate store.
+ """
+ cert = load_certificate(FILETYPE_PEM, cleartextCertificatePEM)
store = X509Store()
- store.add_cert(X509())
+ store.add_cert(cert)
+
+
+ def test_add_cert_rejects_duplicate(self):
+ """
+ :py:obj:`X509Store.add_cert` raises :py:obj:`OpenSSL.crypto.Error` if an
+ attempt is made to add the same certificate to the store more than once.
+ """
+ cert = load_certificate(FILETYPE_PEM, cleartextCertificatePEM)
+ store = X509Store()
+ store.add_cert(cert)
+ self.assertRaises(Error, store.add_cert, cert)