cognito-identity: Support for list identity pools (#7055)

This commit is contained in:
nonchan 2023-11-23 20:02:54 +09:00 committed by GitHub
parent 7c83ca157f
commit 0cce33695b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 0 deletions

View File

@ -174,5 +174,17 @@ class CognitoIdentityBackend(BaseBackend):
"""
return json.dumps(self.pools_identities[identity_pool_id])
def list_identity_pools(self) -> str:
"""
The MaxResults-parameter has not yet been implemented
"""
return json.dumps(
{
"IdentityPools": [
json.loads(pool.to_json()) for pool in self.identity_pools.values()
]
}
)
cognitoidentity_backends = BackendDict(CognitoIdentityBackend, "cognito-identity")

View File

@ -80,3 +80,6 @@ class CognitoIdentityResponse(BaseResponse):
return self.backend.list_identities(
self._get_param("IdentityPoolId") or get_random_identity_id(self.region)
)
def list_identity_pools(self) -> str:
return self.backend.list_identity_pools()

View File

@ -240,3 +240,15 @@ def test_list_identities():
identities = conn.list_identities(IdentityPoolId=identity_pool_id, MaxResults=123)
assert "IdentityPoolId" in identities and "Identities" in identities
assert identity_id in [x["IdentityId"] for x in identities["Identities"]]
@mock_cognitoidentity
def test_list_identity_pools():
conn = boto3.client("cognito-identity", "us-west-2")
identity_pool_data = conn.create_identity_pool(
IdentityPoolName="test_identity_pool", AllowUnauthenticatedIdentities=True
)
identity_pool_id = identity_pool_data["IdentityPoolId"]
identity_data = conn.list_identity_pools(MaxResults=10)
assert identity_pool_id == identity_data["IdentityPools"][0]["IdentityPoolId"]
assert "test_identity_pool" == identity_data["IdentityPools"][0]["IdentityPoolName"]