Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cognito-idp UserPool id format does not match AWS format #1857

Closed
georgealton opened this issue Oct 8, 2018 · 0 comments · Fixed by #1859
Closed

cognito-idp UserPool id format does not match AWS format #1857

georgealton opened this issue Oct 8, 2018 · 0 comments · Fixed by #1859

Comments

@georgealton
Copy link
Contributor

The format for a Cognito UserPool Id produced by the the cognito-idp mock does not produce ids in the expected format for a Cognito UserPool - The ids produced are uuids. The format for the Id field of a UserPool is documented as

Id

The ID of the user pool.

Type: String

Length Constraints: Minimum length of 1. Maximum length of 55.

Pattern: [\w-]+_[0-9a-zA-Z]+

Required: No

https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_UserPoolType.html

So a uuid isn't a valid representation of an Id

This can be reproduced by

import moto
import boto3

create_pool_kwargs = {
            "PoolName": "test_pool",
            "Schema": [
                {
                    "Name": "email",
                    "AttributeDataType": "String",
                    "Required": True,
                    "Mutable": True,
                },
                {
                    "Name": "tenant_id",
                    "AttributeDataType": "String",
                    "Mutable": False,
                },
            ],
            "AdminCreateUserConfig": {
                "AllowAdminCreateUserOnly": True,
                "UnusedAccountValidityDays": 1,
            },
        }


def set_up_tear_down_user_pool():
    cognito_idp = boto3.client('cognito-idp')
    pool = cognito_idp.create_user_pool(**create_pool_kwargs)
    pool_id = pool['UserPool']['Id']
    print(pool_id)
    cognito_idp.delete_user_pool(UserPoolId=pool_id)


# with moto
with moto.mock_cognitoidp() as mock_cognito:
    set_up_tear_down_user_pool()

# without
set_up_tear_down_user_pool()

Produces:

eb9ef17e-acea-4a95-8440-7ee79dd1f172
eu-west-1_qtdBQSSL4

The general expectation is that the pool_id is in the format "{region}_{id}". I usually use the region part when attempting to determine, from a pool id, the region that pool is available in.

I'm using the package installed via pip and python mocks.

moto==1.3.4
botocore==1.10.52
boto3==1.7.3
spulec added a commit that referenced this issue Oct 15, 2018
Fixes #1857 Ensures a UserPool Id starts like {region}_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant