Skip to content

Commit

Permalink
cognito-identity: Support for list identity pools (#7055)
Browse files Browse the repository at this point in the history
  • Loading branch information
nonchan7720 committed Nov 23, 2023
1 parent 7c83ca1 commit 0cce336
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
12 changes: 12 additions & 0 deletions moto/cognitoidentity/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,5 +174,17 @@ def list_identities(self, identity_pool_id: str) -> str:
"""
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")
3 changes: 3 additions & 0 deletions moto/cognitoidentity/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,6 @@ def list_identities(self) -> str:
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()
12 changes: 12 additions & 0 deletions tests/test_cognitoidentity/test_cognitoidentity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

0 comments on commit 0cce336

Please sign in to comment.