From a268f6c74806d5996d469dd84ab365b0cf830f96 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Tue, 12 Aug 2014 09:26:18 -0700 Subject: [PATCH 1/6] Handle when an OpenSSL error doesn't contain a reason (Or any other field) You can reproduce the error by running: ``` treq.get('https://nile.ghdonline.org') ``` from within a twisted program (and doing the approrpiate deferred stuff). I'm unsure how to craft a unit test for this --- OpenSSL/_util.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/OpenSSL/_util.py b/OpenSSL/_util.py index baeecc632..8e304879b 100644 --- a/OpenSSL/_util.py +++ b/OpenSSL/_util.py @@ -7,6 +7,8 @@ def exception_from_error_queue(exceptionType): def text(charp): + if not charp: + return "" return native(ffi.string(charp)) errors = [] From de1906a59337325b4eeb2a947e608be70071a76b Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Tue, 12 Aug 2014 16:12:54 -0700 Subject: [PATCH 2/6] Added a test case --- OpenSSL/test/test_util.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 OpenSSL/test/test_util.py diff --git a/OpenSSL/test/test_util.py b/OpenSSL/test/test_util.py new file mode 100644 index 000000000..7da386ed1 --- /dev/null +++ b/OpenSSL/test/test_util.py @@ -0,0 +1,10 @@ +from OpenSSL._util import exception_from_error_queue, lib +from OpenSSL.test.util import TestCase + + + +class TestErrors(TestCase): + def test_exception_from_error_queue_nonexistant_reason(self): + lib.ERR_put_error(lib.ERR_LIB_EVP, 0, 1112, "", 10) + exc = self.assertRaises(ValueError, exception_from_error_queue, ValueError) + self.assertEqual(exc.args[0][0][2], "") From bae2dc36f3a4ceccca6634f2989927d004b76d37 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Thu, 14 Aug 2014 13:44:54 -0700 Subject: [PATCH 3/6] Fix for py3k --- OpenSSL/test/test_util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenSSL/test/test_util.py b/OpenSSL/test/test_util.py index 7da386ed1..d5e567ad4 100644 --- a/OpenSSL/test/test_util.py +++ b/OpenSSL/test/test_util.py @@ -5,6 +5,6 @@ class TestErrors(TestCase): def test_exception_from_error_queue_nonexistant_reason(self): - lib.ERR_put_error(lib.ERR_LIB_EVP, 0, 1112, "", 10) + lib.ERR_put_error(lib.ERR_LIB_EVP, 0, 1112, b"", 10) exc = self.assertRaises(ValueError, exception_from_error_queue, ValueError) self.assertEqual(exc.args[0][0][2], "") From 9823239397c17e6dda1e2813ecc8cc4b48f4cbf8 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Fri, 15 Aug 2014 11:23:00 -0700 Subject: [PATCH 4/6] A docstring for the test --- OpenSSL/test/test_util.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/OpenSSL/test/test_util.py b/OpenSSL/test/test_util.py index d5e567ad4..6bc9a06b7 100644 --- a/OpenSSL/test/test_util.py +++ b/OpenSSL/test/test_util.py @@ -5,6 +5,11 @@ class TestErrors(TestCase): def test_exception_from_error_queue_nonexistant_reason(self): + """ + :py:func:`exception_from_error_queue` does not raise a ``TypeError`` + when it encounters an OpenSSL error code which does not have a reason + string. + """ lib.ERR_put_error(lib.ERR_LIB_EVP, 0, 1112, b"", 10) exc = self.assertRaises(ValueError, exception_from_error_queue, ValueError) self.assertEqual(exc.args[0][0][2], "") From 27f55edddb96c63e21027571475b2fb63bc91126 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Fri, 15 Aug 2014 11:24:26 -0700 Subject: [PATCH 5/6] Fixed a typo in the test method name --- OpenSSL/test/test_util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenSSL/test/test_util.py b/OpenSSL/test/test_util.py index 6bc9a06b7..f58535478 100644 --- a/OpenSSL/test/test_util.py +++ b/OpenSSL/test/test_util.py @@ -4,7 +4,7 @@ class TestErrors(TestCase): - def test_exception_from_error_queue_nonexistant_reason(self): + def test_exception_from_error_queue_nonexistent_reason(self): """ :py:func:`exception_from_error_queue` does not raise a ``TypeError`` when it encounters an OpenSSL error code which does not have a reason From 174c692604ee8dcd332b2ddab76d7e44da471994 Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Sat, 11 Apr 2015 07:26:15 -0400 Subject: [PATCH 6/6] minor docstring fixes --- OpenSSL/test/test_util.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/OpenSSL/test/test_util.py b/OpenSSL/test/test_util.py index f58535478..8d92a3c75 100644 --- a/OpenSSL/test/test_util.py +++ b/OpenSSL/test/test_util.py @@ -3,12 +3,14 @@ -class TestErrors(TestCase): +class ErrorTests(TestCase): + """ + Tests for handling of certain OpenSSL error cases. + """ def test_exception_from_error_queue_nonexistent_reason(self): """ - :py:func:`exception_from_error_queue` does not raise a ``TypeError`` - when it encounters an OpenSSL error code which does not have a reason - string. + :py:func:`exception_from_error_queue` raises ``ValueError`` when it + encounters an OpenSSL error code which does not have a reason string. """ lib.ERR_put_error(lib.ERR_LIB_EVP, 0, 1112, b"", 10) exc = self.assertRaises(ValueError, exception_from_error_queue, ValueError)