2016-10-11 02:22:54 +02:00
|
|
|
#!/usr/bin/env
|
|
|
|
# Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"). You
|
|
|
|
# may not use this file except in compliance with the License. A copy of
|
|
|
|
# the License is located at
|
|
|
|
#
|
|
|
|
# http://aws.amazon.com/apache2.0/
|
|
|
|
#
|
|
|
|
# or in the "license" file accompanying this file. This file is
|
|
|
|
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
|
|
|
# ANY KIND, either express or implied. See the License for the specific
|
|
|
|
# language governing permissions and limitations under the License.
|
2018-11-28 09:58:03 +01:00
|
|
|
import socket
|
|
|
|
|
2016-10-11 02:22:54 +02:00
|
|
|
import botocore.config
|
2022-05-26 00:10:07 +02:00
|
|
|
from botocore import args, exceptions
|
2018-10-04 08:50:52 +02:00
|
|
|
from botocore.client import ClientEndpointBridge
|
2016-10-11 02:22:54 +02:00
|
|
|
from botocore.config import Config
|
2019-11-18 09:46:14 +01:00
|
|
|
from botocore.configprovider import ConfigValueStore
|
2018-10-04 08:50:52 +02:00
|
|
|
from botocore.hooks import HierarchicalEmitter
|
|
|
|
from botocore.model import ServiceModel
|
2022-05-26 00:10:07 +02:00
|
|
|
from tests import mock, unittest
|
2016-10-11 02:22:54 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TestCreateClientArgs(unittest.TestCase):
|
|
|
|
def setUp(self):
|
2018-10-04 08:50:52 +02:00
|
|
|
self.event_emitter = mock.Mock(HierarchicalEmitter)
|
2019-11-18 09:46:14 +01:00
|
|
|
self.config_store = ConfigValueStore()
|
2018-10-04 08:50:52 +02:00
|
|
|
self.args_create = args.ClientArgsCreator(
|
2022-05-26 00:10:07 +02:00
|
|
|
self.event_emitter, None, None, None, None, self.config_store
|
|
|
|
)
|
2019-11-18 09:46:14 +01:00
|
|
|
self.service_name = 'ec2'
|
2018-10-04 08:50:52 +02:00
|
|
|
self.region = 'us-west-2'
|
|
|
|
self.endpoint_url = 'https://ec2/'
|
2019-11-18 09:46:14 +01:00
|
|
|
self.service_model = self._get_service_model()
|
2018-10-04 08:50:52 +02:00
|
|
|
self.bridge = mock.Mock(ClientEndpointBridge)
|
2019-11-18 09:46:14 +01:00
|
|
|
self._set_endpoint_bridge_resolve()
|
2018-11-28 09:58:03 +01:00
|
|
|
self.default_socket_options = [
|
|
|
|
(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
|
|
|
|
]
|
2018-10-04 08:50:52 +02:00
|
|
|
|
2019-11-18 09:46:14 +01:00
|
|
|
def _get_service_model(self, service_name=None):
|
|
|
|
if service_name is None:
|
|
|
|
service_name = self.service_name
|
|
|
|
service_model = mock.Mock(ServiceModel)
|
|
|
|
service_model.service_name = service_name
|
|
|
|
service_model.endpoint_prefix = service_name
|
|
|
|
service_model.metadata = {
|
|
|
|
'serviceFullName': 'MyService',
|
2022-05-26 00:10:07 +02:00
|
|
|
'protocol': 'query',
|
2019-11-18 09:46:14 +01:00
|
|
|
}
|
|
|
|
service_model.operation_names = []
|
|
|
|
return service_model
|
|
|
|
|
|
|
|
def _set_endpoint_bridge_resolve(self, **override_kwargs):
|
|
|
|
ret_val = {
|
|
|
|
'region_name': self.region,
|
|
|
|
'signature_version': 'v4',
|
|
|
|
'endpoint_url': self.endpoint_url,
|
|
|
|
'signing_name': self.service_name,
|
|
|
|
'signing_region': self.region,
|
2022-05-26 00:10:07 +02:00
|
|
|
'metadata': {},
|
2019-11-18 09:46:14 +01:00
|
|
|
}
|
|
|
|
ret_val.update(**override_kwargs)
|
|
|
|
self.bridge.resolve.return_value = ret_val
|
|
|
|
|
2018-10-04 08:50:52 +02:00
|
|
|
def call_get_client_args(self, **override_kwargs):
|
|
|
|
call_kwargs = {
|
|
|
|
'service_model': self.service_model,
|
|
|
|
'region_name': self.region,
|
|
|
|
'is_secure': True,
|
|
|
|
'endpoint_url': self.endpoint_url,
|
|
|
|
'verify': True,
|
|
|
|
'credentials': None,
|
|
|
|
'scoped_config': {},
|
|
|
|
'client_config': None,
|
2022-05-26 00:10:07 +02:00
|
|
|
'endpoint_bridge': self.bridge,
|
2018-10-04 08:50:52 +02:00
|
|
|
}
|
|
|
|
call_kwargs.update(**override_kwargs)
|
|
|
|
return self.args_create.get_client_args(**call_kwargs)
|
|
|
|
|
|
|
|
def assert_create_endpoint_call(self, mock_endpoint, **override_kwargs):
|
|
|
|
call_kwargs = {
|
|
|
|
'endpoint_url': self.endpoint_url,
|
|
|
|
'region_name': self.region,
|
|
|
|
'response_parser_factory': None,
|
|
|
|
'timeout': (60, 60),
|
|
|
|
'verify': True,
|
|
|
|
'max_pool_connections': 10,
|
|
|
|
'proxies': None,
|
2021-01-26 16:12:20 +01:00
|
|
|
'proxies_config': None,
|
2018-11-28 09:58:03 +01:00
|
|
|
'socket_options': self.default_socket_options,
|
|
|
|
'client_cert': None,
|
2018-10-04 08:50:52 +02:00
|
|
|
}
|
|
|
|
call_kwargs.update(**override_kwargs)
|
|
|
|
mock_endpoint.return_value.create_endpoint.assert_called_with(
|
|
|
|
self.service_model, **call_kwargs
|
|
|
|
)
|
2016-10-11 02:22:54 +02:00
|
|
|
|
|
|
|
def test_compute_s3_configuration(self):
|
2019-12-12 10:04:05 +01:00
|
|
|
self.assertIsNone(self.args_create.compute_s3_config(None))
|
2016-10-11 02:22:54 +02:00
|
|
|
|
2019-12-12 10:04:05 +01:00
|
|
|
def test_compute_s3_config_only_config_store(self):
|
|
|
|
self.config_store.set_config_variable(
|
2022-05-26 00:10:07 +02:00
|
|
|
's3', {'use_accelerate_endpoint': True}
|
|
|
|
)
|
2016-10-11 02:22:54 +02:00
|
|
|
self.assertEqual(
|
2019-12-12 10:04:05 +01:00
|
|
|
self.args_create.compute_s3_config(None),
|
2022-05-26 00:10:07 +02:00
|
|
|
{'use_accelerate_endpoint': True},
|
2016-10-11 02:22:54 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_client_s3_accelerate_from_client_config(self):
|
|
|
|
self.assertEqual(
|
|
|
|
self.args_create.compute_s3_config(
|
|
|
|
client_config=Config(s3={'use_accelerate_endpoint': True})
|
|
|
|
),
|
2022-05-26 00:10:07 +02:00
|
|
|
{'use_accelerate_endpoint': True},
|
2016-10-11 02:22:54 +02:00
|
|
|
)
|
|
|
|
|
2019-12-12 10:04:05 +01:00
|
|
|
def test_client_s3_accelerate_client_config_overrides_config_store(self):
|
|
|
|
self.config_store.set_config_variable(
|
2022-05-26 00:10:07 +02:00
|
|
|
's3', {'use_accelerate_endpoint': False}
|
|
|
|
)
|
2016-10-11 02:22:54 +02:00
|
|
|
self.assertEqual(
|
|
|
|
self.args_create.compute_s3_config(
|
|
|
|
client_config=Config(s3={'use_accelerate_endpoint': True})
|
|
|
|
),
|
|
|
|
# client_config beats scoped_config
|
2022-05-26 00:10:07 +02:00
|
|
|
{'use_accelerate_endpoint': True},
|
2016-10-11 02:22:54 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_max_pool_from_client_config_forwarded_to_endpoint_creator(self):
|
|
|
|
config = botocore.config.Config(max_pool_connections=20)
|
|
|
|
with mock.patch('botocore.args.EndpointCreator') as m:
|
2018-10-04 08:50:52 +02:00
|
|
|
self.call_get_client_args(client_config=config)
|
|
|
|
self.assert_create_endpoint_call(m, max_pool_connections=20)
|
2017-07-10 09:39:11 +02:00
|
|
|
|
|
|
|
def test_proxies_from_client_config_forwarded_to_endpoint_creator(self):
|
2022-05-26 00:10:07 +02:00
|
|
|
proxies = {
|
|
|
|
'http': 'http://foo.bar:1234',
|
|
|
|
'https': 'https://foo.bar:4321',
|
|
|
|
}
|
2017-07-10 09:39:11 +02:00
|
|
|
config = botocore.config.Config(proxies=proxies)
|
|
|
|
with mock.patch('botocore.args.EndpointCreator') as m:
|
2018-10-04 08:50:52 +02:00
|
|
|
self.call_get_client_args(client_config=config)
|
|
|
|
self.assert_create_endpoint_call(m, proxies=proxies)
|
2017-06-27 11:52:19 +02:00
|
|
|
|
|
|
|
def test_s3_with_endpoint_url_still_resolves_region(self):
|
2018-10-04 08:50:52 +02:00
|
|
|
self.service_model.endpoint_prefix = 's3'
|
|
|
|
self.service_model.metadata = {'protocol': 'rest-xml'}
|
|
|
|
self.bridge.resolve.side_effect = [
|
2017-06-27 11:52:19 +02:00
|
|
|
{
|
2022-05-26 00:10:07 +02:00
|
|
|
'region_name': None,
|
|
|
|
'signature_version': 's3v4',
|
|
|
|
'endpoint_url': 'http://other.com/',
|
|
|
|
'signing_name': 's3',
|
|
|
|
'signing_region': None,
|
|
|
|
'metadata': {},
|
2017-06-27 11:52:19 +02:00
|
|
|
},
|
|
|
|
{
|
2022-05-26 00:10:07 +02:00
|
|
|
'region_name': 'us-west-2',
|
|
|
|
'signature_version': 's3v4',
|
2017-06-27 11:52:19 +02:00
|
|
|
'enpoint_url': 'https://s3-us-west-2.amazonaws.com',
|
2022-05-26 00:10:07 +02:00
|
|
|
'signing_name': 's3',
|
|
|
|
'signing_region': 'us-west-2',
|
|
|
|
'metadata': {},
|
|
|
|
},
|
2017-06-27 11:52:19 +02:00
|
|
|
]
|
2018-10-04 08:50:52 +02:00
|
|
|
client_args = self.call_get_client_args(
|
2022-05-26 00:10:07 +02:00
|
|
|
endpoint_url='http://other.com/'
|
|
|
|
)
|
|
|
|
self.assertEqual(client_args['client_config'].region_name, 'us-west-2')
|
2017-06-27 11:52:19 +02:00
|
|
|
|
|
|
|
def test_region_does_not_resolve_if_not_s3_and_endpoint_url_provided(self):
|
2018-10-04 08:50:52 +02:00
|
|
|
self.service_model.endpoint_prefix = 'ec2'
|
|
|
|
self.service_model.metadata = {'protocol': 'query'}
|
2022-05-26 00:10:07 +02:00
|
|
|
self.bridge.resolve.side_effect = [
|
|
|
|
{
|
|
|
|
'region_name': None,
|
|
|
|
'signature_version': 'v4',
|
|
|
|
'endpoint_url': 'http://other.com/',
|
|
|
|
'signing_name': 'ec2',
|
|
|
|
'signing_region': None,
|
|
|
|
'metadata': {},
|
|
|
|
}
|
|
|
|
]
|
2018-10-04 08:50:52 +02:00
|
|
|
client_args = self.call_get_client_args(
|
2022-05-26 00:10:07 +02:00
|
|
|
endpoint_url='http://other.com/'
|
|
|
|
)
|
2017-06-27 11:52:19 +02:00
|
|
|
self.assertEqual(client_args['client_config'].region_name, None)
|
2017-08-24 04:33:12 +02:00
|
|
|
|
2018-11-28 09:58:03 +01:00
|
|
|
def test_tcp_keepalive_enabled(self):
|
|
|
|
scoped_config = {'tcp_keepalive': 'true'}
|
|
|
|
with mock.patch('botocore.args.EndpointCreator') as m:
|
|
|
|
self.call_get_client_args(scoped_config=scoped_config)
|
|
|
|
self.assert_create_endpoint_call(
|
2022-05-26 00:10:07 +02:00
|
|
|
m,
|
|
|
|
socket_options=self.default_socket_options
|
|
|
|
+ [(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)],
|
2018-11-28 09:58:03 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_tcp_keepalive_not_specified(self):
|
|
|
|
scoped_config = {}
|
|
|
|
with mock.patch('botocore.args.EndpointCreator') as m:
|
|
|
|
self.call_get_client_args(scoped_config=scoped_config)
|
|
|
|
self.assert_create_endpoint_call(
|
2022-05-26 00:10:07 +02:00
|
|
|
m, socket_options=self.default_socket_options
|
|
|
|
)
|
2018-11-28 09:58:03 +01:00
|
|
|
|
|
|
|
def test_tcp_keepalive_explicitly_disabled(self):
|
|
|
|
scoped_config = {'tcp_keepalive': 'false'}
|
|
|
|
with mock.patch('botocore.args.EndpointCreator') as m:
|
|
|
|
self.call_get_client_args(scoped_config=scoped_config)
|
|
|
|
self.assert_create_endpoint_call(
|
2022-05-26 00:10:07 +02:00
|
|
|
m, socket_options=self.default_socket_options
|
|
|
|
)
|
2018-11-28 09:58:03 +01:00
|
|
|
|
|
|
|
def test_tcp_keepalive_enabled_case_insensitive(self):
|
|
|
|
scoped_config = {'tcp_keepalive': 'True'}
|
|
|
|
with mock.patch('botocore.args.EndpointCreator') as m:
|
|
|
|
self.call_get_client_args(scoped_config=scoped_config)
|
|
|
|
self.assert_create_endpoint_call(
|
2022-05-26 00:10:07 +02:00
|
|
|
m,
|
|
|
|
socket_options=self.default_socket_options
|
|
|
|
+ [(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)],
|
2018-11-28 09:58:03 +01:00
|
|
|
)
|
2019-11-18 09:46:14 +01:00
|
|
|
|
2022-01-12 23:38:07 +01:00
|
|
|
def test_client_config_has_use_dualstack_endpoint_flag(self):
|
2022-05-26 00:10:07 +02:00
|
|
|
self._set_endpoint_bridge_resolve(metadata={'tags': ['dualstack']})
|
2022-01-12 23:38:07 +01:00
|
|
|
client_args = self.call_get_client_args(
|
|
|
|
service_model=self._get_service_model('ec2'),
|
|
|
|
)
|
|
|
|
self.assertTrue(client_args['client_config'].use_dualstack_endpoint)
|
|
|
|
|
|
|
|
def test_client_config_has_use_fips_endpoint_flag(self):
|
2022-05-26 00:10:07 +02:00
|
|
|
self._set_endpoint_bridge_resolve(metadata={'tags': ['fips']})
|
2022-01-12 23:38:07 +01:00
|
|
|
client_args = self.call_get_client_args(
|
|
|
|
service_model=self._get_service_model('ec2'),
|
|
|
|
)
|
|
|
|
self.assertTrue(client_args['client_config'].use_fips_endpoint)
|
|
|
|
|
2022-05-26 00:10:07 +02:00
|
|
|
def test_client_config_has_both_use_fips_and_use_dualstack__endpoint_flags(
|
|
|
|
self,
|
|
|
|
):
|
2022-01-12 23:38:07 +01:00
|
|
|
self._set_endpoint_bridge_resolve(
|
2022-05-26 00:10:07 +02:00
|
|
|
metadata={'tags': ['fips', 'dualstack']}
|
2022-01-12 23:38:07 +01:00
|
|
|
)
|
|
|
|
client_args = self.call_get_client_args(
|
|
|
|
service_model=self._get_service_model('ec2'),
|
|
|
|
)
|
|
|
|
self.assertTrue(client_args['client_config'].use_fips_endpoint)
|
|
|
|
self.assertTrue(client_args['client_config'].use_dualstack_endpoint)
|
|
|
|
|
|
|
|
def test_s3_override_use_dualstack_endpoint_flag(self):
|
2022-05-26 00:10:07 +02:00
|
|
|
self._set_endpoint_bridge_resolve(metadata={'tags': ['dualstack']})
|
2022-01-12 23:38:07 +01:00
|
|
|
client_args = self.call_get_client_args(
|
|
|
|
service_model=self._get_service_model('s3'),
|
|
|
|
)
|
2022-05-26 00:10:07 +02:00
|
|
|
self.assertTrue(
|
|
|
|
client_args['client_config'].s3['use_dualstack_endpoint']
|
|
|
|
)
|
2022-01-12 23:38:07 +01:00
|
|
|
|
2019-11-18 09:46:14 +01:00
|
|
|
def test_sts_override_resolved_endpoint_for_legacy_region(self):
|
|
|
|
self.config_store.set_config_variable(
|
2022-05-26 00:10:07 +02:00
|
|
|
'sts_regional_endpoints', 'legacy'
|
|
|
|
)
|
2019-11-18 09:46:14 +01:00
|
|
|
client_args = self.call_get_client_args(
|
|
|
|
service_model=self._get_service_model('sts'),
|
2022-05-26 00:10:07 +02:00
|
|
|
region_name='us-west-2',
|
|
|
|
endpoint_url=None,
|
2019-11-18 09:46:14 +01:00
|
|
|
)
|
|
|
|
self.assertEqual(
|
2022-05-26 00:10:07 +02:00
|
|
|
client_args['endpoint'].host, 'https://sts.amazonaws.com'
|
|
|
|
)
|
2019-11-18 09:46:14 +01:00
|
|
|
self.assertEqual(
|
2022-05-26 00:10:07 +02:00
|
|
|
client_args['request_signer'].region_name, 'us-east-1'
|
|
|
|
)
|
2019-11-18 09:46:14 +01:00
|
|
|
|
|
|
|
def test_sts_use_resolved_endpoint_for_nonlegacy_region(self):
|
|
|
|
resolved_endpoint = 'https://resolved-endpoint'
|
|
|
|
resolved_region = 'resolved-region'
|
|
|
|
self._set_endpoint_bridge_resolve(
|
2022-05-26 00:10:07 +02:00
|
|
|
endpoint_url=resolved_endpoint, signing_region=resolved_region
|
2019-11-18 09:46:14 +01:00
|
|
|
)
|
|
|
|
self.config_store.set_config_variable(
|
2022-05-26 00:10:07 +02:00
|
|
|
'sts_regional_endpoints', 'legacy'
|
|
|
|
)
|
2019-11-18 09:46:14 +01:00
|
|
|
client_args = self.call_get_client_args(
|
|
|
|
service_model=self._get_service_model('sts'),
|
2022-05-26 00:10:07 +02:00
|
|
|
region_name='ap-east-1',
|
|
|
|
endpoint_url=None,
|
2019-11-18 09:46:14 +01:00
|
|
|
)
|
|
|
|
self.assertEqual(client_args['endpoint'].host, resolved_endpoint)
|
|
|
|
self.assertEqual(
|
2022-05-26 00:10:07 +02:00
|
|
|
client_args['request_signer'].region_name, resolved_region
|
|
|
|
)
|
2019-11-18 09:46:14 +01:00
|
|
|
|
|
|
|
def test_sts_use_resolved_endpoint_for_regional_configuration(self):
|
|
|
|
resolved_endpoint = 'https://resolved-endpoint'
|
|
|
|
resolved_region = 'resolved-region'
|
|
|
|
self._set_endpoint_bridge_resolve(
|
2022-05-26 00:10:07 +02:00
|
|
|
endpoint_url=resolved_endpoint, signing_region=resolved_region
|
2019-11-18 09:46:14 +01:00
|
|
|
)
|
|
|
|
self.config_store.set_config_variable(
|
2022-05-26 00:10:07 +02:00
|
|
|
'sts_regional_endpoints', 'regional'
|
|
|
|
)
|
2019-11-18 09:46:14 +01:00
|
|
|
client_args = self.call_get_client_args(
|
|
|
|
service_model=self._get_service_model('sts'),
|
2022-05-26 00:10:07 +02:00
|
|
|
region_name='us-west-2',
|
|
|
|
endpoint_url=None,
|
2019-11-18 09:46:14 +01:00
|
|
|
)
|
|
|
|
self.assertEqual(client_args['endpoint'].host, resolved_endpoint)
|
|
|
|
self.assertEqual(
|
2022-05-26 00:10:07 +02:00
|
|
|
client_args['request_signer'].region_name, resolved_region
|
|
|
|
)
|
2019-11-18 09:46:14 +01:00
|
|
|
|
|
|
|
def test_sts_with_endpoint_override_and_legacy_configured(self):
|
|
|
|
override_endpoint = 'https://override-endpoint'
|
|
|
|
self._set_endpoint_bridge_resolve(endpoint_url=override_endpoint)
|
|
|
|
self.config_store.set_config_variable(
|
2022-05-26 00:10:07 +02:00
|
|
|
'sts_regional_endpoints', 'legacy'
|
|
|
|
)
|
2019-11-18 09:46:14 +01:00
|
|
|
client_args = self.call_get_client_args(
|
|
|
|
service_model=self._get_service_model('sts'),
|
2022-05-26 00:10:07 +02:00
|
|
|
region_name='us-west-2',
|
|
|
|
endpoint_url=override_endpoint,
|
2019-11-18 09:46:14 +01:00
|
|
|
)
|
|
|
|
self.assertEqual(client_args['endpoint'].host, override_endpoint)
|
|
|
|
|
|
|
|
def test_sts_http_scheme_for_override_endpoint(self):
|
|
|
|
self.config_store.set_config_variable(
|
2022-05-26 00:10:07 +02:00
|
|
|
'sts_regional_endpoints', 'legacy'
|
|
|
|
)
|
2019-11-18 09:46:14 +01:00
|
|
|
client_args = self.call_get_client_args(
|
|
|
|
service_model=self._get_service_model('sts'),
|
2022-05-26 00:10:07 +02:00
|
|
|
region_name='us-west-2',
|
|
|
|
endpoint_url=None,
|
|
|
|
is_secure=False,
|
2019-11-18 09:46:14 +01:00
|
|
|
)
|
|
|
|
self.assertEqual(
|
2022-05-26 00:10:07 +02:00
|
|
|
client_args['endpoint'].host, 'http://sts.amazonaws.com'
|
|
|
|
)
|
2019-11-18 09:46:14 +01:00
|
|
|
|
|
|
|
def test_sts_regional_endpoints_defaults_to_legacy_if_not_set(self):
|
2022-05-26 00:10:07 +02:00
|
|
|
self.config_store.set_config_variable('sts_regional_endpoints', None)
|
2019-11-18 09:46:14 +01:00
|
|
|
client_args = self.call_get_client_args(
|
|
|
|
service_model=self._get_service_model('sts'),
|
2022-05-26 00:10:07 +02:00
|
|
|
region_name='us-west-2',
|
|
|
|
endpoint_url=None,
|
2019-11-18 09:46:14 +01:00
|
|
|
)
|
|
|
|
self.assertEqual(
|
2022-05-26 00:10:07 +02:00
|
|
|
client_args['endpoint'].host, 'https://sts.amazonaws.com'
|
|
|
|
)
|
2019-11-18 09:46:14 +01:00
|
|
|
self.assertEqual(
|
2022-05-26 00:10:07 +02:00
|
|
|
client_args['request_signer'].region_name, 'us-east-1'
|
|
|
|
)
|
2019-11-18 09:46:14 +01:00
|
|
|
|
|
|
|
def test_invalid_sts_regional_endpoints(self):
|
|
|
|
self.config_store.set_config_variable(
|
2022-05-26 00:10:07 +02:00
|
|
|
'sts_regional_endpoints', 'invalid'
|
|
|
|
)
|
2019-11-18 09:46:14 +01:00
|
|
|
with self.assertRaises(
|
2022-05-26 00:10:07 +02:00
|
|
|
exceptions.InvalidSTSRegionalEndpointsConfigError
|
|
|
|
):
|
2019-11-18 09:46:14 +01:00
|
|
|
self.call_get_client_args(
|
|
|
|
service_model=self._get_service_model('sts'),
|
2022-05-26 00:10:07 +02:00
|
|
|
region_name='us-west-2',
|
|
|
|
endpoint_url=None,
|
2019-11-18 09:46:14 +01:00
|
|
|
)
|
2020-03-22 13:12:42 +01:00
|
|
|
|
|
|
|
def test_provides_total_max_attempts(self):
|
|
|
|
config = botocore.config.Config(retries={'total_max_attempts': 10})
|
|
|
|
client_args = self.call_get_client_args(client_config=config)
|
|
|
|
self.assertEqual(
|
2022-05-26 00:10:07 +02:00
|
|
|
client_args['client_config'].retries['total_max_attempts'], 10
|
|
|
|
)
|
2020-03-22 13:12:42 +01:00
|
|
|
|
|
|
|
def test_provides_total_max_attempts_has_precedence(self):
|
2022-05-26 00:10:07 +02:00
|
|
|
config = botocore.config.Config(
|
|
|
|
retries={'total_max_attempts': 10, 'max_attempts': 5}
|
|
|
|
)
|
2020-03-22 13:12:42 +01:00
|
|
|
client_args = self.call_get_client_args(client_config=config)
|
|
|
|
self.assertEqual(
|
2022-05-26 00:10:07 +02:00
|
|
|
client_args['client_config'].retries['total_max_attempts'], 10
|
|
|
|
)
|
2020-03-22 13:12:42 +01:00
|
|
|
self.assertNotIn('max_attempts', client_args['client_config'].retries)
|
|
|
|
|
|
|
|
def test_provide_retry_config_maps_total_max_attempts(self):
|
|
|
|
config = botocore.config.Config(retries={'max_attempts': 10})
|
|
|
|
client_args = self.call_get_client_args(client_config=config)
|
|
|
|
self.assertEqual(
|
2022-05-26 00:10:07 +02:00
|
|
|
client_args['client_config'].retries['total_max_attempts'], 11
|
|
|
|
)
|
2020-03-22 13:12:42 +01:00
|
|
|
self.assertNotIn('max_attempts', client_args['client_config'].retries)
|
|
|
|
|
|
|
|
def test_can_merge_max_attempts(self):
|
|
|
|
self.config_store.set_config_variable('max_attempts', 4)
|
|
|
|
config = self.call_get_client_args()['client_config']
|
|
|
|
self.assertEqual(config.retries['total_max_attempts'], 4)
|
|
|
|
|
|
|
|
def test_uses_config_value_if_present_for_max_attempts(self):
|
|
|
|
config = self.call_get_client_args(
|
2021-11-03 18:14:15 +01:00
|
|
|
client_config=Config(retries={'max_attempts': 2})
|
2020-03-22 13:12:42 +01:00
|
|
|
)['client_config']
|
|
|
|
self.assertEqual(config.retries['total_max_attempts'], 3)
|
|
|
|
|
|
|
|
def test_uses_client_config_over_config_store_max_attempts(self):
|
|
|
|
self.config_store.set_config_variable('max_attempts', 4)
|
|
|
|
config = self.call_get_client_args(
|
2021-11-03 18:14:15 +01:00
|
|
|
client_config=Config(retries={'max_attempts': 2})
|
2020-03-22 13:12:42 +01:00
|
|
|
)['client_config']
|
|
|
|
self.assertEqual(config.retries['total_max_attempts'], 3)
|
|
|
|
|
|
|
|
def test_uses_client_config_total_over_config_store_max_attempts(self):
|
|
|
|
self.config_store.set_config_variable('max_attempts', 4)
|
|
|
|
config = self.call_get_client_args(
|
2021-11-03 18:14:15 +01:00
|
|
|
client_config=Config(retries={'total_max_attempts': 2})
|
2020-03-22 13:12:42 +01:00
|
|
|
)['client_config']
|
|
|
|
self.assertEqual(config.retries['total_max_attempts'], 2)
|
|
|
|
|
|
|
|
def test_max_attempts_unset_if_retries_is_none(self):
|
2022-05-26 00:10:07 +02:00
|
|
|
config = self.call_get_client_args(client_config=Config(retries=None))[
|
|
|
|
'client_config'
|
|
|
|
]
|
2020-03-22 13:12:42 +01:00
|
|
|
self.assertEqual(config.retries, {'mode': 'legacy'})
|
|
|
|
|
|
|
|
def test_retry_mode_set_on_config_store(self):
|
|
|
|
self.config_store.set_config_variable('retry_mode', 'standard')
|
|
|
|
config = self.call_get_client_args()['client_config']
|
|
|
|
self.assertEqual(config.retries['mode'], 'standard')
|
|
|
|
|
|
|
|
def test_retry_mode_set_on_client_config(self):
|
|
|
|
config = self.call_get_client_args(
|
2021-11-03 18:14:15 +01:00
|
|
|
client_config=Config(retries={'mode': 'standard'})
|
2020-03-22 13:12:42 +01:00
|
|
|
)['client_config']
|
|
|
|
self.assertEqual(config.retries['mode'], 'standard')
|
|
|
|
|
2022-05-26 00:10:07 +02:00
|
|
|
def test_connect_timeout_set_on_config_store(self):
|
|
|
|
self.config_store.set_config_variable('connect_timeout', 10)
|
|
|
|
config = self.call_get_client_args(
|
|
|
|
client_config=Config(defaults_mode='standard')
|
|
|
|
)['client_config']
|
|
|
|
self.assertEqual(config.connect_timeout, 10)
|
|
|
|
|
|
|
|
def test_connnect_timeout_set_on_client_config(self):
|
|
|
|
config = self.call_get_client_args(
|
|
|
|
client_config=Config(connect_timeout=10)
|
|
|
|
)['client_config']
|
|
|
|
self.assertEqual(config.connect_timeout, 10)
|
|
|
|
|
|
|
|
def test_connnect_timeout_set_to_client_config_default(self):
|
|
|
|
config = self.call_get_client_args()['client_config']
|
|
|
|
self.assertEqual(config.connect_timeout, 60)
|
|
|
|
|
2020-03-22 13:12:42 +01:00
|
|
|
def test_client_config_beats_config_store(self):
|
|
|
|
self.config_store.set_config_variable('retry_mode', 'adaptive')
|
|
|
|
config = self.call_get_client_args(
|
2021-11-03 18:14:15 +01:00
|
|
|
client_config=Config(retries={'mode': 'standard'})
|
2020-03-22 13:12:42 +01:00
|
|
|
)['client_config']
|
|
|
|
self.assertEqual(config.retries['mode'], 'standard')
|