def test_timeout(self): def fake_connection(_address): """Fail immediately with a socket timeout.""" raise socket.timeout('fake error') socket.create_connection = fake_connection connection = AwsElasticsearchConnection('mockservice.cc-zone-1.amazonaws.com', aws_access_key_id='access_key', aws_secret_access_key='secret', region='region_123') connection.num_retries = 0 with self.assertRaises(socket.error): connection.make_request('GET', 'https://example.com')
def test_signing(self): connection = AwsElasticsearchConnection('mockservice.cc-zone-1.amazonaws.com', aws_access_key_id='my_access_key', aws_secret_access_key='secret', region='region_123') # create a request and sign it request = connection.build_base_http_request('GET', '/', None) request.authorize(connection) # confirm the header contains signing method and key id auth_header = request.headers['Authorization'] self.assertTrue('AWS4-HMAC-SHA256' in auth_header) self.assertTrue('my_access_key' in auth_header)
def test_signing(self): connection = AwsElasticsearchConnection( 'mockservice.cc-zone-1.amazonaws.com', aws_access_key_id='my_access_key', aws_secret_access_key='secret', region='region_123') # create a request and sign it request = connection.build_base_http_request('GET', '/', None) request.authorize(connection) # confirm the header contains signing method and key id auth_header = request.headers['Authorization'] self.assertTrue('AWS4-HMAC-SHA256' in auth_header) self.assertTrue('my_access_key' in auth_header)
def test_timeout(self): def fake_connection(_address): """Fail immediately with a socket timeout.""" raise socket.timeout('fake error') socket.create_connection = fake_connection connection = AwsElasticsearchConnection( 'mockservice.cc-zone-1.amazonaws.com', aws_access_key_id='access_key', aws_secret_access_key='secret', region='region_123') connection.num_retries = 0 with self.assertRaises(socket.error): connection.make_request('GET', 'https://example.com')
def test_constructor_params(self): connection = AwsElasticsearchConnection( 'mockservice.cc-zone-1.amazonaws.com', aws_access_key_id='access_key', aws_secret_access_key='secret', region='region_123') self.assertEqual(connection.auth_region_name, 'region_123') self.assertEqual(connection.aws_access_key_id, 'access_key') self.assertEqual(connection.aws_secret_access_key, 'secret')