From f2bbc9cc0166a7f0db9a750b38e1a924dadb2108 Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Sun, 2 Feb 2014 10:59:14 -0500 Subject: Change the info callback test to at least assert that the connection argument is a Connection instance. Fix the implementation to make the test pass. --- OpenSSL/SSL.py | 2 +- OpenSSL/test/test_ssl.py | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/OpenSSL/SSL.py b/OpenSSL/SSL.py index 81ec2e2..f21ad9d 100644 --- a/OpenSSL/SSL.py +++ b/OpenSSL/SSL.py @@ -699,7 +699,7 @@ class Context(object): """ @wraps(callback) def wrapper(ssl, where, return_code): - callback(self, where, return_code) + callback(Connection._reverse_mapping[ssl], where, return_code) self._info_callback = _ffi.callback( "void (*)(const SSL *, int, int)", wrapper) _lib.SSL_CTX_set_info_callback(self._context, self._info_callback) diff --git a/OpenSSL/test/test_ssl.py b/OpenSSL/test/test_ssl.py index e3518c5..712009b 100644 --- a/OpenSSL/test/test_ssl.py +++ b/OpenSSL/test/test_ssl.py @@ -700,15 +700,19 @@ class ContextTests(TestCase, _LoopbackMixin): serverSSL = Connection(context, server) serverSSL.set_accept_state() - while not called: - for ssl in clientSSL, serverSSL: - try: - ssl.do_handshake() - except WantReadError: - pass + handshake(clientSSL, serverSSL) - # Kind of lame. Just make sure it got called somehow. - self.assertTrue(called) + # The callback must always be called with the connection it is a + # callback for as the first argument. It would probably be better to + # split this into separate tests for client and server side info + # callbacks. It would also be good to at least assert *something* + # about `where` and `ret`. + notConnections = [ + conn for (conn, where, ret) in called + if not isinstance(conn, Connection)] + self.assertEqual( + [], notConnections, + "Some info callback arguments were not Connection instaces.") def _load_verify_locations_test(self, *args): -- cgit v1.2.1 From 3835e52f89ecaa7c7c9ab18872d19a758e449135 Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Sun, 2 Feb 2014 11:12:30 -0500 Subject: clean up messy comment --- OpenSSL/test/test_ssl.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/OpenSSL/test/test_ssl.py b/OpenSSL/test/test_ssl.py index 712009b..a9b9890 100644 --- a/OpenSSL/test/test_ssl.py +++ b/OpenSSL/test/test_ssl.py @@ -702,11 +702,11 @@ class ContextTests(TestCase, _LoopbackMixin): handshake(clientSSL, serverSSL) - # The callback must always be called with the connection it is a - # callback for as the first argument. It would probably be better to - # split this into separate tests for client and server side info - # callbacks. It would also be good to at least assert *something* - # about `where` and `ret`. + # The callback must always be called with a Connection instance as the + # first argument. It would probably be better to split this into + # separate tests for client and server side info callbacks so we could + # assert it is called with the right Connection instance. It would + # also be good to assert *something* about `where` and `ret`. notConnections = [ conn for (conn, where, ret) in called if not isinstance(conn, Connection)] -- cgit v1.2.1