def test_ping_client_cert_required_has_client_cert(self): with NamedTemporaryFile(prefix='zato-tls', delete=False) as ca_cert_tf: ca_cert_tf.write(ca_cert) ca_cert_tf.flush() with NamedTemporaryFile(prefix='zato-tls', delete=False) as client_cert_tf: client_cert_tf.write(client1_key) client_cert_tf.write('\n') client_cert_tf.write(client1_cert) client_cert_tf.flush() server = TLSServer(cert_reqs=ssl.CERT_REQUIRED) server.start() sleep(0.3) port = server.get_port() config = self._get_config() config['address_host'] = 'https://localhost:{}/'.format(port) config['address_url_path'] = '' config['ping_method'] = 'GET' config['tls_verify'] = ca_cert_tf.name config['tls_key_cert_full_path'] = client_cert_tf.name config['sec_type'] = SEC_DEF_TYPE.TLS_KEY_CERT wrapper = HTTPSOAPWrapper(config, requests) wrapper.ping(rand_string())
def test_ping_unknown_ca_verify_invalid_ca_cert(self): with NamedTemporaryFile(prefix='zato-tls', delete=False) as ca_cert_tf: ca_cert_tf.write(ca_cert_invalid) ca_cert_tf.flush() server = TLSServer() server.start() sleep(1) port = server.get_port() config = self._get_config() config['address_host'] = 'https://localhost:{}/'.format(port) config['address_url_path'] = '' config['ping_method'] = 'GET' config['tls_verify'] = ca_cert_tf.name wrapper = HTTPSOAPWrapper(config, requests) try: wrapper.ping(rand_string()) except Exception, e: details = e.message[0][1][0][0] self.assertEquals(details, ('SSL routines', 'SSL3_GET_SERVER_CERTIFICATE', 'certificate verify failed')) else:
def test_ping_client_cert_required_no_client_cert(self): with NamedTemporaryFile(prefix='zato-tls', delete=False) as ca_cert_tf: ca_cert_tf.write(ca_cert) ca_cert_tf.flush() server = TLSServer(cert_reqs=ssl.CERT_REQUIRED) server.start() sleep(0.3) port = server.get_port() config = self._get_config() config['address_host'] = 'https://localhost:{}/'.format(port) config['address_url_path'] = '' config['ping_method'] = 'GET' config['tls_verify'] = ca_cert_tf.name wrapper = HTTPSOAPWrapper(config, requests) try: wrapper.ping(rand_string()) except Exception, e: details = e.message[0][1][0][0] self.assertEquals(details, ('SSL routines', 'SSL3_READ_BYTES', 'sslv3 alert handshake failure')) else:
def test_ping_unknown_ca_verify_invalid_ca_cert(self): with NamedTemporaryFile(prefix='zato-tls', delete=False) as ca_cert_tf: ca_cert_tf.write(ca_cert_invalid) ca_cert_tf.flush() server = TLSServer() server.start() sleep(1) port = server.get_port() config = self._get_config() config['address_host'] = 'https://localhost:{}/'.format(port) config['address_url_path'] = '' config['ping_method'] = 'GET' config['tls_verify'] = ca_cert_tf.name wrapper = HTTPSOAPWrapper(config, requests) try: wrapper.ping(rand_string()) except Exception, e: details = e.message[0][1][0][0] self.assertEquals( details, ('SSL routines', 'SSL3_GET_SERVER_CERTIFICATE', 'certificate verify failed')) else:
def test_pool_size(self): """ https://github.com/zatosource/zato/issues/77 (outconn HTTP/SOAP pool size) """ config = self._get_config() expected_pool_size = rand_int() config['pool_size'] = expected_pool_size requests_module = _FakeRequestsModule() wrapper = HTTPSOAPWrapper(config, requests_module) wrapper.ping(rand_string()) eq_(expected_pool_size, requests_module.session_obj.pool_size)
def test_ping_method(self): """ https://github.com/zatosource/zato/issues/44 (outconn HTTP/SOAP ping method) """ config = self._get_config() expected_ping_method = 'ping-{}'.format(rand_string()) config['ping_method'] = expected_ping_method requests_module = _FakeRequestsModule() wrapper = HTTPSOAPWrapper(config, requests_module) wrapper.ping(rand_string()) ping_method = requests_module.session_obj.request_args[0] eq_(expected_ping_method, ping_method)
def test_pool_size(self): """ https://github.com/zatosource/zato/issues/77 (outconn HTTP/SOAP pool size) """ expected_pool_size = rand_int() requests_module = _FakeRequestsModule() config = {'sec_type':rand_string(), 'address':rand_string(), 'ping_method':rand_string(), 'pool_size':expected_pool_size} wrapper = HTTPSOAPWrapper(config, requests_module) wrapper.ping(rand_string()) eq_(expected_pool_size, requests_module.session_obj.pool_size)
def test_ping_method(self): """ https://github.com/zatosource/zato/issues/44 (outconn HTTP/SOAP ping method) """ expected_ping_method = 'ping-{}'.format(rand_string()) requests_module = _FakeRequestsModule() config = {'sec_type':rand_string(), 'address':rand_string(), 'ping_method':expected_ping_method, 'pool_size':rand_int()} wrapper = HTTPSOAPWrapper(config, requests_module) wrapper.ping(rand_string()) ping_method = requests_module.session_obj.request_args[0] eq_(expected_ping_method, ping_method)
def test_pool_size(self): """ https://github.com/zatosource/zato/issues/77 (outconn HTTP/SOAP pool size) """ expected_pool_size = rand_int() requests_module = _FakeRequestsModule() config = { 'sec_type': rand_string(), 'address': rand_string(), 'ping_method': rand_string(), 'pool_size': expected_pool_size } wrapper = HTTPSOAPWrapper(config, requests_module) wrapper.ping(rand_string()) eq_(expected_pool_size, requests_module.session_obj.pool_size)
def test_ping_method(self): """ https://github.com/zatosource/zato/issues/44 (outconn HTTP/SOAP ping method) """ expected_ping_method = 'ping-{}'.format(rand_string()) requests_module = _FakeRequestsModule() config = { 'sec_type': rand_string(), 'address': rand_string(), 'ping_method': expected_ping_method, 'pool_size': rand_int() } wrapper = HTTPSOAPWrapper(config, requests_module) wrapper.ping(rand_string()) ping_method = requests_module.session_obj.request_args[0] eq_(expected_ping_method, ping_method)
def test_ping_unknown_ca_verify_false(self): server = TLSServer() server.start() sleep(0.3) port = server.get_port() config = self._get_config() config['address_host'] = 'https://localhost:{}/'.format(port) config['address_url_path'] = '' config['ping_method'] = 'GET' config['tls_verify'] = ZATO_NONE wrapper = HTTPSOAPWrapper(config, requests) self.assertIn('Code: 200', wrapper.ping(rand_string()))