Commit 8b6a940c authored by dieter's avatar dieter

fix tests checking the SSL context

parent 6d85718b
...@@ -133,14 +133,17 @@ class SSLConfigTestMockiavellian(ZEOConfigTestBase): ...@@ -133,14 +133,17 @@ class SSLConfigTestMockiavellian(ZEOConfigTestBase):
server.close() server.close()
def assert_context( def assert_context(
self, factory, context, self,
server,
factory, context,
cert=(server_cert, server_key, None), cert=(server_cert, server_key, None),
verify_mode=ssl.CERT_REQUIRED, verify_mode=ssl.CERT_REQUIRED,
check_hostname=False, check_hostname=False,
cafile=None, capath=None, cafile=None, capath=None,
): ):
factory.assert_called_with( factory.assert_called_with(
ssl.Purpose.SERVER_AUTH, cafile=cafile, capath=capath) ssl.Purpose.CLIENT_AUTH if server else ssl.Purpose.SERVER_AUTH,
cafile=cafile, capath=capath)
context.load_cert_chain.assert_called_with(*cert) context.load_cert_chain.assert_called_with(*cert)
self.assertEqual(context, factory.return_value) self.assertEqual(context, factory.return_value)
self.assertEqual(context.verify_mode, verify_mode) self.assertEqual(context.verify_mode, verify_mode)
...@@ -157,7 +160,7 @@ class SSLConfigTestMockiavellian(ZEOConfigTestBase): ...@@ -157,7 +160,7 @@ class SSLConfigTestMockiavellian(ZEOConfigTestBase):
server = create_server( server = create_server(
certificate=server_cert, key=server_key, authenticate=__file__) certificate=server_cert, key=server_key, authenticate=__file__)
context = server.acceptor.ssl_context context = server.acceptor.ssl_context
self.assert_context(factory, context, cafile=__file__) self.assert_context(True, factory, context, cafile=__file__)
server.close() server.close()
@mock.patch('ssl.create_default_context') @mock.patch('ssl.create_default_context')
...@@ -165,7 +168,7 @@ class SSLConfigTestMockiavellian(ZEOConfigTestBase): ...@@ -165,7 +168,7 @@ class SSLConfigTestMockiavellian(ZEOConfigTestBase):
server = create_server( server = create_server(
certificate=server_cert, key=server_key, authenticate=here) certificate=server_cert, key=server_key, authenticate=here)
context = server.acceptor.ssl_context context = server.acceptor.ssl_context
self.assert_context(factory, context, capath=here) self.assert_context(True, factory, context, capath=here)
server.close() server.close()
@mock.patch('ssl.create_default_context') @mock.patch('ssl.create_default_context')
...@@ -177,7 +180,7 @@ class SSLConfigTestMockiavellian(ZEOConfigTestBase): ...@@ -177,7 +180,7 @@ class SSLConfigTestMockiavellian(ZEOConfigTestBase):
authenticate=here, authenticate=here,
) )
context = server.acceptor.ssl_context context = server.acceptor.ssl_context
self.assert_context( self.assert_context(True,
factory, context, (server_cert, server_key, pwfunc), capath=here) factory, context, (server_cert, server_key, pwfunc), capath=here)
server.close() server.close()
...@@ -197,7 +200,7 @@ class SSLConfigTestMockiavellian(ZEOConfigTestBase): ...@@ -197,7 +200,7 @@ class SSLConfigTestMockiavellian(ZEOConfigTestBase):
context = ClientStorage.call_args[1]['ssl'] context = ClientStorage.call_args[1]['ssl']
self.assertEqual(ClientStorage.call_args[1]['ssl_server_hostname'], self.assertEqual(ClientStorage.call_args[1]['ssl_server_hostname'],
None) None)
self.assert_context( self.assert_context(False,
factory, context, (client_cert, client_key, None), factory, context, (client_cert, client_key, None),
check_hostname=True) check_hostname=True)
...@@ -213,7 +216,7 @@ class SSLConfigTestMockiavellian(ZEOConfigTestBase): ...@@ -213,7 +216,7 @@ class SSLConfigTestMockiavellian(ZEOConfigTestBase):
context = ClientStorage.call_args[1]['ssl'] context = ClientStorage.call_args[1]['ssl']
self.assertEqual(ClientStorage.call_args[1]['ssl_server_hostname'], self.assertEqual(ClientStorage.call_args[1]['ssl_server_hostname'],
None) None)
self.assert_context( self.assert_context(False,
factory, context, (client_cert, client_key, None), factory, context, (client_cert, client_key, None),
capath=here, capath=here,
check_hostname=True, check_hostname=True,
...@@ -230,7 +233,7 @@ class SSLConfigTestMockiavellian(ZEOConfigTestBase): ...@@ -230,7 +233,7 @@ class SSLConfigTestMockiavellian(ZEOConfigTestBase):
context = ClientStorage.call_args[1]['ssl'] context = ClientStorage.call_args[1]['ssl']
self.assertEqual(ClientStorage.call_args[1]['ssl_server_hostname'], self.assertEqual(ClientStorage.call_args[1]['ssl_server_hostname'],
None) None)
self.assert_context( self.assert_context(False,
factory, context, (client_cert, client_key, None), factory, context, (client_cert, client_key, None),
cafile=server_cert, cafile=server_cert,
check_hostname=True, check_hostname=True,
...@@ -249,7 +252,7 @@ class SSLConfigTestMockiavellian(ZEOConfigTestBase): ...@@ -249,7 +252,7 @@ class SSLConfigTestMockiavellian(ZEOConfigTestBase):
context = ClientStorage.call_args[1]['ssl'] context = ClientStorage.call_args[1]['ssl']
self.assertEqual(ClientStorage.call_args[1]['ssl_server_hostname'], self.assertEqual(ClientStorage.call_args[1]['ssl_server_hostname'],
None) None)
self.assert_context( self.assert_context(False,
factory, context, (client_cert, client_key, pwfunc), factory, context, (client_cert, client_key, pwfunc),
cafile=server_cert, cafile=server_cert,
check_hostname=True, check_hostname=True,
...@@ -266,7 +269,7 @@ class SSLConfigTestMockiavellian(ZEOConfigTestBase): ...@@ -266,7 +269,7 @@ class SSLConfigTestMockiavellian(ZEOConfigTestBase):
context = ClientStorage.call_args[1]['ssl'] context = ClientStorage.call_args[1]['ssl']
self.assertEqual(ClientStorage.call_args[1]['ssl_server_hostname'], self.assertEqual(ClientStorage.call_args[1]['ssl_server_hostname'],
'example.com') 'example.com')
self.assert_context( self.assert_context(False,
factory, context, (client_cert, client_key, None), factory, context, (client_cert, client_key, None),
cafile=server_cert, cafile=server_cert,
check_hostname=True, check_hostname=True,
...@@ -283,7 +286,7 @@ class SSLConfigTestMockiavellian(ZEOConfigTestBase): ...@@ -283,7 +286,7 @@ class SSLConfigTestMockiavellian(ZEOConfigTestBase):
context = ClientStorage.call_args[1]['ssl'] context = ClientStorage.call_args[1]['ssl']
self.assertEqual(ClientStorage.call_args[1]['ssl_server_hostname'], self.assertEqual(ClientStorage.call_args[1]['ssl_server_hostname'],
None) None)
self.assert_context( self.assert_context(False,
factory, context, (client_cert, client_key, None), factory, context, (client_cert, client_key, None),
cafile=server_cert, cafile=server_cert,
check_hostname=False, check_hostname=False,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment