-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cleanup
- Loading branch information
David Miller
committed
Jul 20, 2022
1 parent
d0e5dc2
commit 1b54127
Showing
5 changed files
with
236 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Copyright 2022 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. | ||
|
||
from awscli.testutils import mock, create_clidriver | ||
from awscli.customizations.overridesslcommonname import ssl_common_names | ||
|
||
import pytest | ||
|
||
|
||
|
||
@pytest.fixture | ||
def driver(): | ||
return create_clidriver() | ||
|
||
|
||
@pytest.fixture | ||
def invoke(): | ||
patch = mock.patch("awscli.clidriver.CLIOperationCaller.invoke", return_value=0) | ||
return patch.start() | ||
|
||
|
||
def common_name_test_cases(): | ||
|
||
service_ops = { | ||
"sqs": "list-queues", | ||
"emr": "list-clusters", | ||
"rds": "describe-db-clusters", | ||
} | ||
for service in ssl_common_names: | ||
for region in ssl_common_names[service]: | ||
yield (service, service_ops[service], region) | ||
|
||
|
||
@pytest.mark.parametrize("service,operation,region", common_name_test_cases()) | ||
@mock.patch("awscli.clidriver.CLIOperationCaller.invoke", return_value=0) | ||
def test_set_endpoint_url_arg(invoke, driver, service, operation, region): | ||
driver.main(f"{service} {operation} --region {region}".split()) | ||
formatted_op = "".join([part.lower() for part in operation.split("-")]) | ||
call_args = invoke.call_args[0] | ||
assert call_args[0] == service | ||
assert call_args[1].lower() == formatted_op | ||
assert call_args[3].endpoint_url == f"https://{ssl_common_names[service][region]}" |
72 changes: 72 additions & 0 deletions
72
tests/integration/customizations/test_override_ssl_common_name.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# Copyright 2022 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. | ||
|
||
from awscli.testutils import aws | ||
from awscli.customizations.overridesslcommonname import ssl_common_names | ||
|
||
import pytest | ||
|
||
|
||
def common_name_test_cases(): | ||
|
||
regions_to_exclude = [ | ||
"af-south-1", | ||
"ap-east-1", | ||
"ap-southeast-3", | ||
"eu-south-1", | ||
"me-south-1", | ||
"cn-north-1", | ||
"cn-northwest-1", | ||
"us-gov-west-1", | ||
"us-isob-east-1", | ||
] | ||
|
||
service_ops = { | ||
"sqs": { | ||
"op": "create-queue --queue-name test", | ||
"return_key": "QueueUrl", | ||
}, | ||
"emr": {"op": "list-clusters", "return_key": "Clusters"}, | ||
"rds": { | ||
"op": "describe-db-clusters", | ||
"return_key": "DBClusters", | ||
}, | ||
} | ||
for service in ssl_common_names: | ||
for region in ssl_common_names[service]: | ||
if region not in regions_to_exclude: | ||
yield ( | ||
service, | ||
service_ops[service]["op"], | ||
service_ops[service]["return_key"], | ||
region, | ||
) | ||
|
||
|
||
def cleanup(service, json, region): | ||
if service == "sqs": | ||
p = aws( | ||
f"{service} delete-queue --queue-url {json['QueueUrl']} --region {region}" | ||
) | ||
assert p.rc == 0 | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"service,operation,return_key,region", common_name_test_cases() | ||
) | ||
def test_update_endpoint_url(service, operation, return_key, region): | ||
|
||
p = aws(f"{service} {operation} --region {region}") | ||
assert p.rc == 0 | ||
assert return_key in p.json | ||
cleanup(service, p.json, region) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters