summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Paul Calderone <exarkun@twistedmatrix.com>2013-12-29 16:36:50 -0500
committerJean-Paul Calderone <exarkun@twistedmatrix.com>2013-12-29 16:36:50 -0500
commit5300d6abd9e530eab8a27de0e55fc28aa42de325 (patch)
tree3c5d4668b433cc8a5f61a05bc3818c4f2d4cacb8
parente728e87c21c7f0060b49fb93994d669b6c324fd4 (diff)
downloadpyopenssl-5300d6abd9e530eab8a27de0e55fc28aa42de325.tar.gz
Add a test for the error case of setattr
-rw-r--r--OpenSSL/crypto.py3
-rw-r--r--OpenSSL/test/test_crypto.py12
2 files changed, 13 insertions, 2 deletions
diff --git a/OpenSSL/crypto.py b/OpenSSL/crypto.py
index a3f30d9..65bc8e8 100644
--- a/OpenSSL/crypto.py
+++ b/OpenSSL/crypto.py
@@ -245,8 +245,7 @@ class X509Name(object):
add_result = _lib.X509_NAME_add_entry_by_NID(
self._name, nid, _lib.MBSTRING_UTF8, value, -1, -1, 0)
if not add_result:
- # TODO Untested
- 1/0
+ _raise_current_error()
def __getattr__(self, name):
diff --git a/OpenSSL/test/test_crypto.py b/OpenSSL/test/test_crypto.py
index 2acf339..d451c9c 100644
--- a/OpenSSL/test/test_crypto.py
+++ b/OpenSSL/test/test_crypto.py
@@ -737,6 +737,7 @@ class X509NameTests(TestCase):
self.assertRaises(TypeError, setattr, name, None, "hello")
self.assertRaises(TypeError, setattr, name, 30, "hello")
+
def test_setInvalidAttribute(self):
"""
Attempting to set any attribute name on an :py:class:`X509NameType` instance for
@@ -926,6 +927,16 @@ class X509NameTests(TestCase):
"null.python.org\x00example.org", subject.commonName)
+ def test_setAttributeFailure(self):
+ """
+ If the value of an attribute cannot be set for some reason then
+ :py:class:`OpenSSL.crypto.Error` is raised.
+ """
+ name = self._x509name()
+ # This value is too long
+ self.assertRaises(Error, setattr, name, "O", b"x" * 512)
+
+
class _PKeyInteractionTestsMixin:
"""
@@ -2938,6 +2949,7 @@ class CRLTests(TestCase):
self.assertRaises(Error, load_crl, FILETYPE_PEM, "hello, world")
+
class SignVerifyTests(TestCase):
"""
Tests for :py:obj:`OpenSSL.crypto.sign` and :py:obj:`OpenSSL.crypto.verify`.