Skip to content

Commit 07a92f2

Browse files
test: add test
1 parent e6ef8cf commit 07a92f2

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tests/unit/test_image.py renamed to tests/unit/sagemaker/local/test_local_image.py

+20
Original file line numberDiff line numberDiff line change
@@ -859,5 +859,25 @@ def test__aws_credentials_with_short_lived_credentials_and_ec2_metadata_service_
859859
]
860860

861861

862+
@patch("sagemaker.local.image._aws_credentials_available_in_metadata_service")
863+
def test__aws_credentials_with_short_lived_credentials_and_ec2_metadata_service_having_credentials_override(
864+
mock,
865+
):
866+
os.environ["USE_SHORT_LIVED_CREDENTIALS"] = "1"
867+
credentials = Credentials(
868+
access_key=_random_string(), secret_key=_random_string(), token=_random_string()
869+
)
870+
session = Mock()
871+
session.get_credentials.return_value = credentials
872+
mock.return_value = True
873+
aws_credentials = _aws_credentials(session)
874+
875+
assert aws_credentials == [
876+
"AWS_ACCESS_KEY_ID=%s" % credentials.access_key,
877+
"AWS_SECRET_ACCESS_KEY=%s" % credentials.secret_key,
878+
"AWS_SESSION_TOKEN=%s" % credentials.token,
879+
]
880+
881+
862882
def _random_string(size=6, chars=string.ascii_uppercase):
863883
return "".join(random.choice(chars) for x in range(size))

0 commit comments

Comments
 (0)