Skip to content

Commit

Permalink
unit tests for account_id_endpoint_mode
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlm committed Oct 4, 2023
1 parent ea189ee commit 39cb368
Show file tree
Hide file tree
Showing 4 changed files with 346 additions and 4 deletions.
3 changes: 2 additions & 1 deletion tests/functional/test_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,8 @@ def assert_session_credentials(self, expected_params, **kwargs):
expected_creds = self.create_random_credentials()
response = self.create_assume_role_response(expected_creds)
session = StubbedSession(**kwargs)
stubber = session.stub('sts')
config = Config(signature_version=UNSIGNED)
stubber = session.stub('sts', config=config)
stubber.add_response(
'assume_role_with_web_identity', response, expected_params
)
Expand Down
83 changes: 83 additions & 0 deletions tests/unit/data/endpoints/valid-rules/aws-account-id.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
"parameters": {
"Region": {
"type": "string",
"builtIn": "AWS::Region",
"documentation": "The region to dispatch this request, eg. `us-east-1`."
},
"AccountId": {
"type": "string",
"builtIn": "AWS::Auth::AccountId",
"documentation": "The account ID to dispatch this request, eg. `123456789012`."
}
},
"rules": [
{
"documentation": "Template the account ID into the URI when account ID is set",
"conditions": [
{
"fn": "isSet",
"argv": [
{
"ref": "AccountId"
}
]
},
{
"fn": "isSet",
"argv": [
{
"ref": "Region"
}
]
}
],
"endpoint": {
"url": "https://{AccountId}.amazonaws.com",
"properties": {
"authSchemes": [
{
"name": "sigv4",
"signingName": "serviceName",
"signingRegion": "{Region}"
}
]
}
},
"type": "endpoint"
},
{
"documentation": "Fallback when account ID isn't set",
"conditions": [
{
"fn": "isSet",
"argv": [
{
"ref": "Region"
}
]
}
],
"endpoint": {
"url": "https://amazonaws.com",
"properties": {
"authSchemes": [
{
"name": "sigv4",
"signingName": "serviceName",
"signingRegion": "{Region}"
}
]
}
},
"type": "endpoint"
},
{
"documentation": "fallback when region is unset",
"conditions": [],
"error": "Region must be set to resolve a valid endpoint",
"type": "error"
}
],
"version": "1.3"
}
25 changes: 25 additions & 0 deletions tests/unit/test_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,30 @@ def test_bad_value_disable_request_compression(self):
config = client_args['client_config']
self.assertFalse(config.disable_request_compression)

def test_account_id_endpoint_mode_config_store(self):
self.config_store.set_config_variable(
'account_id_endpoint_mode', 'preferred'
)
config = self.call_get_client_args()['client_config']
self.assertEqual(config.account_id_endpoint_mode, 'preferred')

def test_account_id_endpoint_mode_client_config(self):
config = Config(account_id_endpoint_mode='preferred')
config = self.call_get_client_args(client_config=config)
client_config = config['client_config']
self.assertEqual(client_config.account_id_endpoint_mode, 'preferred')

def test_account_id_endpoint_mode_client_config_overrides_config_store(
self,
):
self.config_store.set_config_variable(
'account_id_endpoint_mode', 'preferred'
)
config = Config(account_id_endpoint_mode='required')
config = self.call_get_client_args(client_config=config)
client_config = config['client_config']
self.assertEqual(client_config.account_id_endpoint_mode, 'required')


class TestEndpointResolverBuiltins(unittest.TestCase):
def setUp(self):
Expand Down Expand Up @@ -679,6 +703,7 @@ def test_builtins_defaults(self):
bins['AWS::S3::DisableMultiRegionAccessPoints'], False
)
self.assertEqual(bins['SDK::Endpoint'], None)
self.assertEqual(bins['AWS::Auth::AccountId'], None)

def test_aws_region(self):
bins = self.call_compute_endpoint_resolver_builtin_defaults(
Expand Down
Loading

0 comments on commit 39cb368

Please sign in to comment.