Merge pull request #2403 from wesselvdv/feature/cognito-describe-identity-pool
Adds Cognito Identity describe-identity-pool
This commit is contained in:
commit
ff3e3de387
@ -1237,7 +1237,7 @@
|
||||
- [ ] delete_identities
|
||||
- [ ] delete_identity_pool
|
||||
- [ ] describe_identity
|
||||
- [ ] describe_identity_pool
|
||||
- [X] describe_identity_pool
|
||||
- [X] get_credentials_for_identity
|
||||
- [X] get_id
|
||||
- [ ] get_identity_pool_roles
|
||||
|
15
moto/cognitoidentity/exceptions.py
Normal file
15
moto/cognitoidentity/exceptions.py
Normal file
@ -0,0 +1,15 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import json
|
||||
|
||||
from werkzeug.exceptions import BadRequest
|
||||
|
||||
|
||||
class ResourceNotFoundError(BadRequest):
|
||||
|
||||
def __init__(self, message):
|
||||
super(ResourceNotFoundError, self).__init__()
|
||||
self.description = json.dumps({
|
||||
"message": message,
|
||||
'__type': 'ResourceNotFoundException',
|
||||
})
|
@ -8,7 +8,7 @@ import boto.cognito.identity
|
||||
from moto.compat import OrderedDict
|
||||
from moto.core import BaseBackend, BaseModel
|
||||
from moto.core.utils import iso_8601_datetime_with_milliseconds
|
||||
|
||||
from .exceptions import ResourceNotFoundError
|
||||
from .utils import get_random_identity_id
|
||||
|
||||
|
||||
@ -39,10 +39,29 @@ class CognitoIdentityBackend(BaseBackend):
|
||||
self.__dict__ = {}
|
||||
self.__init__(region)
|
||||
|
||||
def create_identity_pool(self, identity_pool_name, allow_unauthenticated_identities,
|
||||
supported_login_providers, developer_provider_name, open_id_connect_provider_arns,
|
||||
cognito_identity_providers, saml_provider_arns):
|
||||
def describe_identity_pool(self, identity_pool_id):
|
||||
identity_pool = self.identity_pools.get(identity_pool_id, None)
|
||||
|
||||
if not identity_pool:
|
||||
raise ResourceNotFoundError(identity_pool)
|
||||
|
||||
response = json.dumps({
|
||||
'AllowUnauthenticatedIdentities': identity_pool.allow_unauthenticated_identities,
|
||||
'CognitoIdentityProviders': identity_pool.cognito_identity_providers,
|
||||
'DeveloperProviderName': identity_pool.developer_provider_name,
|
||||
'IdentityPoolId': identity_pool.identity_pool_id,
|
||||
'IdentityPoolName': identity_pool.identity_pool_name,
|
||||
'IdentityPoolTags': {},
|
||||
'OpenIdConnectProviderARNs': identity_pool.open_id_connect_provider_arns,
|
||||
'SamlProviderARNs': identity_pool.saml_provider_arns,
|
||||
'SupportedLoginProviders': identity_pool.supported_login_providers
|
||||
})
|
||||
|
||||
return response
|
||||
|
||||
def create_identity_pool(self, identity_pool_name, allow_unauthenticated_identities,
|
||||
supported_login_providers, developer_provider_name, open_id_connect_provider_arns,
|
||||
cognito_identity_providers, saml_provider_arns):
|
||||
new_identity = CognitoIdentity(self.region, identity_pool_name,
|
||||
allow_unauthenticated_identities=allow_unauthenticated_identities,
|
||||
supported_login_providers=supported_login_providers,
|
||||
@ -77,12 +96,12 @@ class CognitoIdentityBackend(BaseBackend):
|
||||
response = json.dumps(
|
||||
{
|
||||
"Credentials":
|
||||
{
|
||||
"AccessKeyId": "TESTACCESSKEY12345",
|
||||
"Expiration": expiration_str,
|
||||
"SecretKey": "ABCSECRETKEY",
|
||||
"SessionToken": "ABC12345"
|
||||
},
|
||||
{
|
||||
"AccessKeyId": "TESTACCESSKEY12345",
|
||||
"Expiration": expiration_str,
|
||||
"SecretKey": "ABCSECRETKEY",
|
||||
"SessionToken": "ABC12345"
|
||||
},
|
||||
"IdentityId": identity_id
|
||||
})
|
||||
return response
|
||||
|
@ -1,7 +1,6 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from moto.core.responses import BaseResponse
|
||||
|
||||
from .models import cognitoidentity_backends
|
||||
from .utils import get_random_identity_id
|
||||
|
||||
@ -16,6 +15,7 @@ class CognitoIdentityResponse(BaseResponse):
|
||||
open_id_connect_provider_arns = self._get_param('OpenIdConnectProviderARNs')
|
||||
cognito_identity_providers = self._get_param('CognitoIdentityProviders')
|
||||
saml_provider_arns = self._get_param('SamlProviderARNs')
|
||||
|
||||
return cognitoidentity_backends[self.region].create_identity_pool(
|
||||
identity_pool_name=identity_pool_name,
|
||||
allow_unauthenticated_identities=allow_unauthenticated_identities,
|
||||
@ -28,6 +28,9 @@ class CognitoIdentityResponse(BaseResponse):
|
||||
def get_id(self):
|
||||
return cognitoidentity_backends[self.region].get_id()
|
||||
|
||||
def describe_identity_pool(self):
|
||||
return cognitoidentity_backends[self.region].describe_identity_pool(self._get_param('IdentityPoolId'))
|
||||
|
||||
def get_credentials_for_identity(self):
|
||||
return cognitoidentity_backends[self.region].get_credentials_for_identity(self._get_param('IdentityId'))
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import boto3
|
||||
from botocore.exceptions import ClientError
|
||||
from nose.tools import assert_raises
|
||||
|
||||
from moto import mock_cognitoidentity
|
||||
import sure # noqa
|
||||
|
||||
from moto.cognitoidentity.utils import get_random_identity_id
|
||||
|
||||
|
||||
@ -28,6 +28,47 @@ def test_create_identity_pool():
|
||||
assert result['IdentityPoolId'] != ''
|
||||
|
||||
|
||||
@mock_cognitoidentity
|
||||
def test_describe_identity_pool():
|
||||
conn = boto3.client('cognito-identity', 'us-west-2')
|
||||
|
||||
res = conn.create_identity_pool(IdentityPoolName='TestPool',
|
||||
AllowUnauthenticatedIdentities=False,
|
||||
SupportedLoginProviders={'graph.facebook.com': '123456789012345'},
|
||||
DeveloperProviderName='devname',
|
||||
OpenIdConnectProviderARNs=['arn:aws:rds:eu-west-2:123456789012:db:mysql-db'],
|
||||
CognitoIdentityProviders=[
|
||||
{
|
||||
'ProviderName': 'testprovider',
|
||||
'ClientId': 'CLIENT12345',
|
||||
'ServerSideTokenCheck': True
|
||||
},
|
||||
],
|
||||
SamlProviderARNs=['arn:aws:rds:eu-west-2:123456789012:db:mysql-db'])
|
||||
|
||||
result = conn.describe_identity_pool(IdentityPoolId=res['IdentityPoolId'])
|
||||
|
||||
assert result['IdentityPoolId'] == res['IdentityPoolId']
|
||||
assert result['AllowUnauthenticatedIdentities'] == res['AllowUnauthenticatedIdentities']
|
||||
assert result['SupportedLoginProviders'] == res['SupportedLoginProviders']
|
||||
assert result['DeveloperProviderName'] == res['DeveloperProviderName']
|
||||
assert result['OpenIdConnectProviderARNs'] == res['OpenIdConnectProviderARNs']
|
||||
assert result['CognitoIdentityProviders'] == res['CognitoIdentityProviders']
|
||||
assert result['SamlProviderARNs'] == res['SamlProviderARNs']
|
||||
|
||||
|
||||
@mock_cognitoidentity
|
||||
def test_describe_identity_pool_with_invalid_id_raises_error():
|
||||
conn = boto3.client('cognito-identity', 'us-west-2')
|
||||
|
||||
with assert_raises(ClientError) as cm:
|
||||
conn.describe_identity_pool(IdentityPoolId='us-west-2_non-existent')
|
||||
|
||||
cm.exception.operation_name.should.equal('DescribeIdentityPool')
|
||||
cm.exception.response['Error']['Code'].should.equal('ResourceNotFoundException')
|
||||
cm.exception.response['ResponseMetadata']['HTTPStatusCode'].should.equal(400)
|
||||
|
||||
|
||||
# testing a helper function
|
||||
def test_get_random_identity_id():
|
||||
assert len(get_random_identity_id('us-west-2')) > 0
|
||||
@ -44,7 +85,8 @@ def test_get_id():
|
||||
'someurl': '12345'
|
||||
})
|
||||
print(result)
|
||||
assert result.get('IdentityId', "").startswith('us-west-2') or result.get('ResponseMetadata').get('HTTPStatusCode') == 200
|
||||
assert result.get('IdentityId', "").startswith('us-west-2') or result.get('ResponseMetadata').get(
|
||||
'HTTPStatusCode') == 200
|
||||
|
||||
|
||||
@mock_cognitoidentity
|
||||
@ -71,6 +113,7 @@ def test_get_open_id_token_for_developer_identity():
|
||||
assert len(result['Token']) > 0
|
||||
assert result['IdentityId'] == '12345'
|
||||
|
||||
|
||||
@mock_cognitoidentity
|
||||
def test_get_open_id_token_for_developer_identity_when_no_explicit_identity_id():
|
||||
conn = boto3.client('cognito-identity', 'us-west-2')
|
||||
@ -84,6 +127,7 @@ def test_get_open_id_token_for_developer_identity_when_no_explicit_identity_id()
|
||||
assert len(result['Token']) > 0
|
||||
assert len(result['IdentityId']) > 0
|
||||
|
||||
|
||||
@mock_cognitoidentity
|
||||
def test_get_open_id_token():
|
||||
conn = boto3.client('cognito-identity', 'us-west-2')
|
||||
|
Loading…
x
Reference in New Issue
Block a user