def test_simple_ssl(self): """ Server uses its cert, client uses none. """ server_port = 9001 with TestSSL._ClientServerContextManager(server_port): client = SSLClient("https://localhost:%d/RPC2" % server_port, ca_certs) self.assertEqual(client.test_server(), RESULT_OK)
def test_client_cert(self): """ Server & client use certs. """ server_port = 9002 with TestSSL._ClientServerContextManager(server_port, ssl.CERT_REQUIRED): client = SSLClient("https://localhost:%d/RPC2" % server_port, ca_certs, client_key, client_cert) self.assertEqual(client.test_server(), RESULT_OK)
def test_client_cert_verify_ok(self): """ Server & client use certs. Server succesfully validates client certificate's fields. """ server_port = 9003 verify_fields = {"commonName":"My Client", "countryName":"US", "organizationalUnitName":"My Unit", "organizationName":"My Company", "stateOrProvinceName":"My State"} with TestSSL._ClientServerContextManager(server_port, ssl.CERT_REQUIRED, verify_fields): client = SSLClient("https://localhost:%d/RPC2" % server_port, ca_certs, client_key, client_cert) self.assertEqual(client.test_server(), RESULT_OK)
def test_client_cert_verify_ok(self): """ Server & client use certs. Server succesfully validates client certificate's fields. """ server_port = 9003 verify_fields = { "commonName": "My Client", "countryName": "US", "organizationalUnitName": "My Unit", "organizationName": "My Company", "stateOrProvinceName": "My State" } with TestSSL._ClientServerContextManager(server_port, ssl.CERT_REQUIRED, verify_fields): client = SSLClient("https://localhost:%d/RPC2" % server_port, ca_certs, client_key, client_cert) self.assertEqual(client.test_server(), RESULT_OK)