Skip to content

Commit 122df5a

Browse files
Fix async credentials mock for WIF unit tests
Create AsyncCredentialsWrapper to properly mock aiobotocore credentials with async get_frozen_credentials() method. This allows unit tests to pass while the production code correctly handles real aiobotocore AioRefreshableCredentials.
1 parent 5433ee2 commit 122df5a

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

test/unit/aio/csp_helpers_async.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,21 @@ class FakeGceMetadataServiceAsync(FakeMetadataServiceAsync, FakeGceMetadataServi
154154
pass
155155

156156

157+
class AsyncCredentialsWrapper:
158+
"""Wrapper around boto credentials to make get_frozen_credentials async for testing."""
159+
160+
def __init__(self, credentials):
161+
self._credentials = credentials
162+
163+
async def get_frozen_credentials(self):
164+
"""Async version of get_frozen_credentials that returns the wrapped credentials."""
165+
return self._credentials
166+
167+
def __getattr__(self, name):
168+
"""Delegate all other attributes to the wrapped credentials."""
169+
return getattr(self._credentials, name)
170+
171+
157172
class FakeAwsEnvironmentAsync(FakeAwsEnvironment):
158173
"""Emulates the AWS environment-specific functions used in async wif_util.py.
159174
@@ -166,15 +181,19 @@ async def get_region(self):
166181
return self.region
167182

168183
async def get_credentials(self):
169-
return self.credentials
184+
if self.credentials is None:
185+
return None
186+
return AsyncCredentialsWrapper(self.credentials)
170187

171188
def __enter__(self):
172189
# First call the parent's __enter__ to get base functionality
173190
super().__enter__()
174191

175192
# Then add async-specific patches
176193
async def async_get_credentials():
177-
return self.credentials
194+
if self.credentials is None:
195+
return None
196+
return AsyncCredentialsWrapper(self.credentials)
178197

179198
async def async_get_caller_identity():
180199
return {"Arn": self.arn}

0 commit comments

Comments
 (0)