@@ -398,12 +398,30 @@ def test_get_caller_identity_arn_from_a_role(sts_regional_endpoint, boto_session
398
398
@patch ("os.path.exists" , side_effect = mock_exists (NOTEBOOK_METADATA_FILE , False ))
399
399
@patch ("sagemaker.session.sts_regional_endpoint" , return_value = STS_ENDPOINT )
400
400
def test_get_caller_identity_arn_from_an_execution_role (sts_regional_endpoint , boto_session ):
401
+ sess = Session (boto_session )
402
+ sts_arn = "arn:aws:sts::369233609183:assumed-role/AmazonSageMaker-ExecutionRole-20171129T072388/SageMaker"
403
+ sess .boto_session .client ("sts" , endpoint_url = STS_ENDPOINT ).get_caller_identity .return_value = {
404
+ "Arn" : sts_arn
405
+ }
406
+ iam_arn = "arn:aws:iam::369233609183:role/AmazonSageMaker-ExecutionRole-20171129T072388"
407
+ sess .boto_session .client ("iam" ).get_role .return_value = {"Role" : {"Arn" : iam_arn }}
408
+
409
+ actual = sess .get_caller_identity_arn ()
410
+ assert actual == iam_arn
411
+
412
+
413
+ @patch ("os.path.exists" , side_effect = mock_exists (NOTEBOOK_METADATA_FILE , False ))
414
+ @patch ("sagemaker.session.sts_regional_endpoint" , return_value = STS_ENDPOINT )
415
+ def test_get_caller_identity_arn_from_a_sagemaker_execution_role_with_iam_client_error (
416
+ sts_regional_endpoint , boto_session
417
+ ):
401
418
sess = Session (boto_session )
402
419
arn = "arn:aws:sts::369233609183:assumed-role/AmazonSageMaker-ExecutionRole-20171129T072388/SageMaker"
403
420
sess .boto_session .client ("sts" , endpoint_url = STS_ENDPOINT ).get_caller_identity .return_value = {
404
421
"Arn" : arn
405
422
}
406
- sess .boto_session .client ("iam" ).get_role .return_value = {"Role" : {"Arn" : arn }}
423
+
424
+ sess .boto_session .client ("iam" ).get_role .side_effect = ClientError ({}, {})
407
425
408
426
actual = sess .get_caller_identity_arn ()
409
427
assert (
0 commit comments