Skip to content

Commit 7fb68d5

Browse files
Lawhyclaude
andcommitted
test(aws): verify RefreshableCredentials is wired correctly
Add test to confirm assumed role sessions use RefreshableCredentials with a refresh callback, ensuring credentials auto-refresh on expiry. Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 3fdce47 commit 7fb68d5

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/unit/test_aws.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,34 @@ def test_cached_by_role_arn(self, mock_get_session, mock_boto3_client):
130130
# assume_role should only be called once due to caching
131131
assert mock_sts.assume_role.call_count == 1
132132

133+
@patch("strands_env.utils.aws.boto3.client")
134+
def test_has_refreshable_credentials(self, mock_boto3_client):
135+
"""Session should have RefreshableCredentials with refresh callback."""
136+
from datetime import datetime, timedelta, timezone
137+
138+
from botocore.credentials import RefreshableCredentials
139+
140+
mock_sts = MagicMock()
141+
mock_sts.assume_role.return_value = {
142+
"Credentials": {
143+
"AccessKeyId": "AKIA_TEST",
144+
"SecretAccessKey": "secret_test",
145+
"SessionToken": "token_test",
146+
"Expiration": datetime.now(timezone.utc) + timedelta(hours=1),
147+
}
148+
}
149+
mock_boto3_client.return_value = mock_sts
150+
151+
role_arn = "arn:aws:iam::123456789:role/TestRole"
152+
session = get_assumed_role_session(role_arn=role_arn)
153+
154+
# Get the underlying botocore credentials directly
155+
botocore_creds = session._session._credentials
156+
157+
# Verify it's RefreshableCredentials with a refresh callback
158+
assert isinstance(botocore_creds, RefreshableCredentials)
159+
assert botocore_creds._refresh_using is not None
160+
133161

134162
class TestClearSessions:
135163
"""Tests for clear_sessions."""

0 commit comments

Comments
 (0)