diff options
author | Jean-Paul Calderone <exarkun@twistedmatrix.com> | 2013-12-29 16:54:58 -0500 |
---|---|---|
committer | Jean-Paul Calderone <exarkun@twistedmatrix.com> | 2013-12-29 16:54:58 -0500 |
commit | 4a68b4080d1ecb80842b790a28812a35606a1941 (patch) | |
tree | 33b717cb867e2689c2e25133c8b77854c8f024c5 | |
parent | 5300d6abd9e530eab8a27de0e55fc28aa42de325 (diff) | |
download | pyopenssl-4a68b4080d1ecb80842b790a28812a35606a1941.tar.gz |
Add a test for bad type value passed to load_certificate_request and fix the behavior. Also incidental additional error handling fix for untested code.
-rw-r--r-- | OpenSSL/crypto.py | 5 | ||||
-rw-r--r-- | OpenSSL/test/test_crypto.py | 14 |
2 files changed, 17 insertions, 2 deletions
diff --git a/OpenSSL/crypto.py b/OpenSSL/crypto.py index 65bc8e8..437d111 100644 --- a/OpenSSL/crypto.py +++ b/OpenSSL/crypto.py @@ -1944,10 +1944,11 @@ def load_certificate_request(type, buffer): elif type == FILETYPE_ASN1: req = _lib.d2i_X509_REQ_bio(bio, _ffi.NULL) else: - 1/0 + raise ValueError("type argument must be FILETYPE_PEM or FILETYPE_ASN1") if req == _ffi.NULL: - 1/0 + # TODO: This is untested. + _raise_current_error() x509req = X509Req.__new__(X509Req) x509req._req = _ffi.gc(req, _lib.X509_REQ_free) diff --git a/OpenSSL/test/test_crypto.py b/OpenSSL/test/test_crypto.py index d451c9c..a87a5e8 100644 --- a/OpenSSL/test/test_crypto.py +++ b/OpenSSL/test/test_crypto.py @@ -2468,6 +2468,20 @@ class FunctionTests(TestCase): +class LoadCertificateTests(TestCase): + """ + Tests for :py:obj:`load_certificate_request`. + """ + def test_badFileType(self): + """ + If the file type passed to :py:obj:`load_certificate_request` is + neither :py:obj:`FILETYPE_PEM` nor :py:obj:`FILETYPE_ASN1` then + :py:class:`ValueError` is raised. + """ + self.assertRaises(ValueError, load_certificate_request, object(), b"") + + + class PKCS7Tests(TestCase): """ Tests for :py:obj:`PKCS7Type`. |