def test_aws_with_region(self): with mock.patch('botocore.service.Service.get_endpoint') as endpoint: http_response = models.Response() http_response.status_code = 200 endpoint.return_value.make_request.return_value = (http_response, {}) self.assert_params_for_cmd( 'ec2 describe-instances --region us-east-1', expected_rc=0) endpoint.assert_called_with(region_name='us-east-1', endpoint_url=None)
def test_default_to_verifying_ssl(self): with mock.patch('botocore.endpoint.Endpoint') as endpoint: http_response = models.Response() http_response.status_code = 200 endpoint.return_value.host = '' endpoint.return_value.make_request.return_value = (http_response, {}) self.assert_params_for_cmd2( 'ec2 describe-instances --region us-east-1', expected_rc=0) call_args = endpoint.call_args self.assertEqual(call_args[1]['verify'], True)
def test_s3_with_no_verify_ssl(self): with mock.patch('botocore.service.Service.get_endpoint') as endpoint: http_response = models.Response() http_response.status_code = 200 endpoint.return_value.make_request.return_value = ( http_response, {'CommonPrefixes': [], 'Contents': []}) self.assert_params_for_cmd( 's3 ls s3://test --no-verify-ssl', expected_rc=0) endpoint.assert_called_with(region_name=None, endpoint_url=None, verify=False)
def test_s3_with_region_and_endpoint_url(self): with mock.patch('botocore.service.Service.get_endpoint') as endpoint: http_response = models.Response() http_response.status_code = 200 endpoint.return_value.make_request.return_value = ( http_response, {'CommonPrefixes': [], 'Contents': []}) self.assert_params_for_cmd( 's3 ls s3://test --region us-east-1 --endpoint-url https://foobar.com/', expected_rc=0) endpoint.assert_called_with(region_name='us-east-1', endpoint_url='https://foobar.com/', verify=None)
def test_aws_with_endpoint_url(self): with mock.patch('botocore.service.Service.get_endpoint') as endpoint: http_response = models.Response() http_response.status_code = 200 endpoint.return_value.make_request.return_value = ( http_response, {}) self.assert_params_for_cmd( 'ec2 describe-instances --endpoint-url https://foobar.com/', expected_rc=0) endpoint.assert_called_with(region_name=None, verify=None, endpoint_url='https://foobar.com/')
def test_aws_with_cacert_env_var(self): with mock.patch('botocore.endpoint.Endpoint') as endpoint: http_response = models.Response() http_response.status_code = 200 endpoint.return_value.host = '' endpoint.return_value.make_request.return_value = (http_response, {}) self.environ['AWS_CA_BUNDLE'] = '/path/cacert.pem' self.assert_params_for_cmd2( 'ec2 describe-instances --region us-east-1', expected_rc=0) call_args = endpoint.call_args self.assertEqual(call_args[1]['verify'], '/path/cacert.pem')
def setUp(self): super(TestHowClientIsCreated, self).setUp() self.endpoint_creator_patch = mock.patch( 'botocore.client.EndpointCreator') self.endpoint_creator = self.endpoint_creator_patch.start() self.create_endpoint = \ self.endpoint_creator.return_value.create_endpoint self.endpoint = self.create_endpoint.return_value # Have the endpoint give a dummy empty response. http_response = models.Response() http_response.status_code = 200 self.endpoint.make_request.return_value = ( http_response, {})
def test_aws_with_verify_false(self): with mock.patch('botocore.service.Service.get_endpoint') as endpoint: http_response = models.Response() http_response.status_code = 200 endpoint.return_value.make_request.return_value = ( http_response, {}) self.assert_params_for_cmd( 'ec2 describe-instances --region us-east-1 --no-verify-ssl', expected_rc=0) # Because we used --no-verify-ssl, get_endpoint should be # called with verify=False endpoint.assert_called_with(region_name='us-east-1', verify=False, endpoint_url=None)