1
- # Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
1
+ # Copyright 2017-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
#
3
3
# Licensed under the Apache License, Version 2.0 (the "License"). You
4
4
# may not use this file except in compliance with the License. A copy of
31
31
SAMPLE_PARAM_RANGES = [{"Name" : "mini_batch_size" , "MinValue" : "10" , "MaxValue" : "100" }]
32
32
33
33
REGION = "us-west-2"
34
+ STS_ENDPOINT = "sts.us-west-2.amazonaws.com"
34
35
35
36
36
37
@pytest .fixture ()
@@ -88,7 +89,9 @@ def test_get_execution_role_throws_exception_if_arn_is_not_role_with_role_in_nam
88
89
def test_get_caller_identity_arn_from_an_user (boto_session ):
89
90
sess = Session (boto_session )
90
91
arn = "arn:aws:iam::369233609183:user/mia"
91
- sess .boto_session .client ("sts" ).get_caller_identity .return_value = {"Arn" : arn }
92
+ sess .boto_session .client ("sts" , endpoint_url = STS_ENDPOINT ).get_caller_identity .return_value = {
93
+ "Arn" : arn
94
+ }
92
95
sess .boto_session .client ("iam" ).get_role .return_value = {"Role" : {"Arn" : arn }}
93
96
94
97
actual = sess .get_caller_identity_arn ()
@@ -98,7 +101,9 @@ def test_get_caller_identity_arn_from_an_user(boto_session):
98
101
def test_get_caller_identity_arn_from_an_user_without_permissions (boto_session ):
99
102
sess = Session (boto_session )
100
103
arn = "arn:aws:iam::369233609183:user/mia"
101
- sess .boto_session .client ("sts" ).get_caller_identity .return_value = {"Arn" : arn }
104
+ sess .boto_session .client ("sts" , endpoint_url = STS_ENDPOINT ).get_caller_identity .return_value = {
105
+ "Arn" : arn
106
+ }
102
107
sess .boto_session .client ("iam" ).get_role .side_effect = ClientError ({}, {})
103
108
104
109
with patch ("logging.Logger.warning" ) as mock_logger :
@@ -112,7 +117,9 @@ def test_get_caller_identity_arn_from_a_role(boto_session):
112
117
arn = (
113
118
"arn:aws:sts::369233609183:assumed-role/SageMakerRole/6d009ef3-5306-49d5-8efc-78db644d8122"
114
119
)
115
- sess .boto_session .client ("sts" ).get_caller_identity .return_value = {"Arn" : arn }
120
+ sess .boto_session .client ("sts" , endpoint_url = STS_ENDPOINT ).get_caller_identity .return_value = {
121
+ "Arn" : arn
122
+ }
116
123
117
124
expected_role = "arn:aws:iam::369233609183:role/SageMakerRole"
118
125
sess .boto_session .client ("iam" ).get_role .return_value = {"Role" : {"Arn" : expected_role }}
@@ -124,7 +131,9 @@ def test_get_caller_identity_arn_from_a_role(boto_session):
124
131
def test_get_caller_identity_arn_from_a_execution_role (boto_session ):
125
132
sess = Session (boto_session )
126
133
arn = "arn:aws:sts::369233609183:assumed-role/AmazonSageMaker-ExecutionRole-20171129T072388/SageMaker"
127
- sess .boto_session .client ("sts" ).get_caller_identity .return_value = {"Arn" : arn }
134
+ sess .boto_session .client ("sts" , endpoint_url = STS_ENDPOINT ).get_caller_identity .return_value = {
135
+ "Arn" : arn
136
+ }
128
137
sess .boto_session .client ("iam" ).get_role .return_value = {"Role" : {"Arn" : arn }}
129
138
130
139
actual = sess .get_caller_identity_arn ()
@@ -138,7 +147,7 @@ def test_get_caller_identity_arn_from_role_with_path(boto_session):
138
147
sess = Session (boto_session )
139
148
arn_prefix = "arn:aws:iam::369233609183:role"
140
149
role_name = "name"
141
- sess .boto_session .client ("sts" ).get_caller_identity .return_value = {
150
+ sess .boto_session .client ("sts" , endpoint_url = STS_ENDPOINT ).get_caller_identity .return_value = {
142
151
"Arn" : "/" .join ([arn_prefix , role_name ])
143
152
}
144
153
@@ -344,7 +353,9 @@ def test_s3_input_all_arguments():
344
353
@pytest .fixture ()
345
354
def sagemaker_session ():
346
355
boto_mock = Mock (name = "boto_session" )
347
- boto_mock .client ("sts" ).get_caller_identity .return_value = {"Account" : "123" }
356
+ boto_mock .client ("sts" , endpoint_url = STS_ENDPOINT ).get_caller_identity .return_value = {
357
+ "Account" : "123"
358
+ }
348
359
ims = sagemaker .Session (boto_session = boto_mock , sagemaker_client = Mock ())
349
360
ims .expand_role = Mock (return_value = EXPANDED_ROLE )
350
361
return ims
0 commit comments