Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/tests/unit/customizations/test_overridesslcommonname.py
1567 views
1
# Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License"). You
4
# may not use this file except in compliance with the License. A copy of
5
# the License is located at
6
#
7
# http://aws.amazon.com/apache2.0/
8
#
9
# or in the "license" file accompanying this file. This file is
10
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
# ANY KIND, either express or implied. See the License for the specific
12
# language governing permissions and limitations under the License.
13
14
from awscli.testutils import create_clidriver
15
from awscli.customizations.overridesslcommonname import (
16
update_endpoint_url,
17
SSL_COMMON_NAMES,
18
)
19
20
import pytest
21
import argparse
22
23
24
def parameters():
25
for service, regions in SSL_COMMON_NAMES.items():
26
for region in regions:
27
yield (service, region)
28
29
30
@pytest.fixture
31
def parsed_globals():
32
pg = argparse.Namespace()
33
pg.endpoint_url = None
34
pg.region = None
35
return pg
36
37
38
@pytest.fixture
39
def session():
40
driver = create_clidriver()
41
return driver.session
42
43
44
@pytest.mark.parametrize("service,region", parameters())
45
def test_update_endpoint_url(parsed_globals, session, service, region):
46
parsed_globals.command = service
47
session.set_config_variable("region", region)
48
update_endpoint_url(session, parsed_globals)
49
assert parsed_globals.endpoint_url == (
50
f"https://{SSL_COMMON_NAMES[service][region]}"
51
)
52
53
54
@pytest.mark.parametrize("service,region", parameters())
55
def test_url_modified_from_event(parsed_globals, session, service, region):
56
assert parsed_globals.endpoint_url is None
57
parsed_globals.command = service
58
session.set_config_variable("region", region)
59
session.emit(
60
f"before-building-argument-table-parser.{service}",
61
args=[],
62
session=session,
63
argument_table={},
64
parsed_globals=parsed_globals,
65
)
66
assert parsed_globals.endpoint_url == (
67
f"https://{SSL_COMMON_NAMES[service][region]}"
68
)
69
70
71
def test_dont_modify_provided_url(parsed_globals, session):
72
parsed_globals.endpoint_url = "http://test.com"
73
parsed_globals.command = "sqs"
74
update_endpoint_url(session, parsed_globals)
75
assert parsed_globals.endpoint_url == "http://test.com"
76
77