summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMarcus Huewe <suse-tux@gmx.de>2018-03-02 15:30:09 +0100
committerMatěj Cepl <mcepl@cepl.eu>2018-03-04 14:26:22 +0100
commitf749f85db5a61ad4ee0a83d9424cc856ef76fcda (patch)
tree0ad6a7f54d6157d5ccfb18b853e93ff1374d4496 /tests
parentff96d066fa94eb05924c39f028c36ae51aa9d790 (diff)
downloadm2crypto-f749f85db5a61ad4ee0a83d9424cc856ef76fcda.tar.gz
Fix SSL.Connection.__del__
Without this change self.m2_ssl_free(self.ssl) is never called, because m2.bio_noclose is defined as "0". Hence, the if-condition is always false. This got broken in commit e2f707b172 ("SSL package: Port to python3"). Note that these testcases rely on the "fact" (or CPython implementation detail?) that "del s" calls s' __del__ method.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_ssl.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/test_ssl.py b/tests/test_ssl.py
index 34af245..a191c8f 100644
--- a/tests/test_ssl.py
+++ b/tests/test_ssl.py
@@ -877,6 +877,53 @@ class MiscSSLClientTestCase(BaseSSLClientTestCase):
self.stop_server(pid)
self.assertIn('s_server -quiet -www', data)
+ def test_ssl_connection_free(self):
+ pid = self.start_server(self.args)
+ orig_m2_ssl_free = SSL.Connection.m2_ssl_free
+ def _m2_ssl_free(ssl):
+ orig_m2_ssl_free(ssl)
+ _m2_ssl_free.called = True
+
+ try:
+ ctx = SSL.Context()
+ s = SSL.Connection(ctx)
+ s.m2_ssl_free = _m2_ssl_free
+ s.connect(self.srv_addr)
+ data = self.http_get(s)
+ s.close()
+ self.assertFalse(hasattr(_m2_ssl_free, 'called'))
+ # keep fingers crossed that SSL.Connection.__del__ is called
+ # by the python interpreter
+ del s
+ finally:
+ self.stop_server(pid)
+ self.assertIn('s_server -quiet -www', data)
+ self.assertTrue(getattr(_m2_ssl_free, 'called', False))
+
+ def test_ssl_connection_no_free(self):
+ pid = self.start_server(self.args)
+ orig_m2_ssl_free = SSL.Connection.m2_ssl_free
+ def _m2_ssl_free(ssl):
+ _m2_ssl_free.called = True
+ orig_m2_ssl_free(ssl)
+
+ try:
+ ctx = SSL.Context()
+ s = SSL.Connection(ctx)
+ s.m2_ssl_free = _m2_ssl_free
+ s.set_ssl_close_flag(m2.bio_close)
+ s.connect(self.srv_addr)
+ data = self.http_get(s)
+ s.close()
+ self.assertFalse(hasattr(_m2_ssl_free, 'called'))
+ # keep fingers crossed that SSL.Connection.__del__ is called
+ # by the python interpreter
+ del s
+ finally:
+ self.stop_server(pid)
+ self.assertIn('s_server -quiet -www', data)
+ self.assertFalse(hasattr(_m2_ssl_free, 'called'))
+
class UrllibSSLClientTestCase(BaseSSLClientTestCase):