def test_no_ssl(self): params = connection.URLParameters('http://') self.assertIsNone(params.ssl_options) self.assertEqual(params.port, params.DEFAULT_PORT) self.assert_default_parameter_values(params) params = connection.URLParameters('amqp://') self.assertIsNone(params.ssl_options) self.assertEqual(params.port, params.DEFAULT_PORT) self.assert_default_parameter_values(params)
def test_ssl(self): params = connection.URLParameters('https://') self.assertIsNotNone(params.ssl_options) self.assertEqual(params.port, params.DEFAULT_SSL_PORT) params = connection.URLParameters('amqps://') self.assertIsNotNone(params.ssl_options) self.assertEqual(params.port, params.DEFAULT_SSL_PORT) # Make sure the other parameters unrelated to SSL have default values params = connection.URLParameters('amqps://') params.ssl_options = None params.port = params.DEFAULT_PORT self.assert_default_parameter_values(params)
def test_process_url(self): """test for the different query stings checked by process url""" url_params = { 'backpressure_detection': None, 'channel_max': 1, 'connection_attempts': 2, 'frame_max': 30000, 'heartbeat': 4, 'locale': 'en', 'retry_delay': 5, 'socket_timeout': 6, 'ssl_options': {'ssl': 'dict'} } for backpressure in ('t', 'f'): test_params = copy.deepcopy(url_params) test_params['backpressure_detection'] = backpressure query_string = urlencode(test_params) test_url = 'https://www.test.com?%s' % query_string params = connection.URLParameters(test_url) #check each value for t_param in ('channel_max', 'connection_attempts', 'frame_max', 'locale', 'retry_delay', 'socket_timeout', 'ssl_options'): self.assertEqual(test_params[t_param], getattr(params, t_param), t_param) self.assertEqual(params.backpressure_detection, backpressure == 't') self.assertEqual(test_params['heartbeat'], params.heartbeat)
def test_good_parameters(self): """test for the different query stings checked by process url""" query_args = { 'blocked_connection_timeout': 10.5, 'channel_max': 3, 'connection_attempts': 2, 'frame_max': 40000, 'heartbeat': 7, 'locale': 'en_UK', 'retry_delay': 3, 'socket_timeout': 100.5, 'ssl_options': { 'ssl': 'options' }, 'tcp_options': { 'TCP_USER_TIMEOUT': 1000, 'TCP_KEEPIDLE': 60 } } for backpressure in ('t', 'f'): test_params = copy.deepcopy(query_args) test_params['backpressure_detection'] = backpressure virtual_host = '/' query_string = urlencode(test_params) test_url = ('https://*****:*****@www.test.com:5678/%s?%s' % ( url_quote(virtual_host, safe=''), query_string, )) params = connection.URLParameters(test_url) # check all value from query string for t_param in query_args: expected_value = query_args[t_param] actual_value = getattr(params, t_param) self.assertEqual(actual_value, expected_value, msg='Expected %s=%r, but got %r' % (t_param, expected_value, actual_value)) self.assertEqual(params.backpressure_detection, backpressure == 't') # check all values from base URL self.assertEqual(params.ssl, True) self.assertEqual(params.credentials.username, 'myuser') self.assertEqual(params.credentials.password, 'mypass') self.assertEqual(params.host, 'www.test.com') self.assertEqual(params.port, 5678) self.assertEqual(params.virtual_host, virtual_host)
def test_no_url_scheme_defaults_to_plaintext(self): params = connection.URLParameters('//') self.assertIsNone(params.ssl_options) self.assertEqual(params.port, params.DEFAULT_PORT)
def test_default_property_values(self): params = connection.URLParameters('') self.assert_default_parameter_values(params) self.assertIsNone(params.ssl_options) self.assertEqual(params.port, params.DEFAULT_PORT)
def test_good_parameters(self): """test for the different query stings checked by process url""" query_args = { 'blocked_connection_timeout': 10.5, 'channel_max': 3, 'connection_attempts': 2, 'frame_max': 40000, 'heartbeat': 7, 'locale': 'en_UK', 'retry_delay': 3, 'socket_timeout': 100.5, # NOTE: just straight ssl.CERT_OPTIONAL breaks on python 3.6 and 3.7 # during ast.literal_eval() of the urlencoded dict as invalid syntax # on <VerifyMode.CERT_NONE: 1>: # {'cert_reqs': <VerifyMode.CERT_NONE: 1>, 'server_hostname': 'blah.blah.com'} 'ssl_options': { 'keyfile': None, 'certfile': None, 'ssl_version': int(ssl.PROTOCOL_SSLv23), 'ca_certs': None, 'cert_reqs': int(ssl.CERT_NONE), 'npn_protocols': None, 'ciphers': None, 'server_hostname': 'blah.blah.com' }, 'tcp_options': { 'TCP_USER_TIMEOUT': 1000, 'TCP_KEEPIDLE': 60 } } for backpressure in ('t', 'f'): test_params = dict(query_args) test_params['backpressure_detection'] = backpressure virtual_host = '/' query_string = urlencode(test_params) test_url = ('https://*****:*****@www.test.com:5678/%s?%s' % ( url_quote(virtual_host, safe=''), query_string, )) params = connection.URLParameters(test_url) # check all value from query string for t_param in query_args: expected_value = query_args[t_param] actual_value = getattr(params, t_param) if t_param == 'ssl_options': self.assertEqual(actual_value.context.verify_mode, expected_value['cert_reqs']) self.assertEqual(actual_value.server_hostname, expected_value['server_hostname']) else: self.assertEqual(actual_value, expected_value, msg='Expected %s=%r, but got %r' % (t_param, expected_value, actual_value)) self.assertEqual(params.backpressure_detection, backpressure == 't') # check all values from base URL self.assertIsNotNone(params.ssl_options) self.assertEqual(params.credentials.username, 'myuser') self.assertEqual(params.credentials.password, 'mypass') self.assertEqual(params.host, 'www.test.com') self.assertEqual(params.port, 5678) self.assertEqual(params.virtual_host, virtual_host)