fix cognito-idp UserPool ClientId (#3165)

* fix cognito-idp UserPool ClientId

* add test

* replace uuid4 to create_id
This commit is contained in:
Koichi Ogura 2020-07-22 22:08:17 +09:00 committed by GitHub
parent bf8eb11dc3
commit 448ff45174
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 6 deletions

View File

@ -23,6 +23,7 @@ from .exceptions import (
UsernameExistsException,
InvalidParameterException,
)
from .utils import create_id
UserStatus = {
"FORCE_CHANGE_PASSWORD": "FORCE_CHANGE_PASSWORD",
@ -214,7 +215,7 @@ class CognitoIdpUserPoolDomain(BaseModel):
class CognitoIdpUserPoolClient(BaseModel):
def __init__(self, user_pool_id, generate_secret, extended_config):
self.user_pool_id = user_pool_id
self.id = str(uuid.uuid4())
self.id = create_id()
self.secret = str(uuid.uuid4())
self.generate_secret = generate_secret or False
self.extended_config = extended_config or {}

10
moto/cognitoidp/utils.py Normal file
View File

@ -0,0 +1,10 @@
from __future__ import unicode_literals
import six
import random
import string
def create_id():
size = 26
chars = list(range(10)) + list(string.ascii_lowercase)
return "".join(six.text_type(random.choice(chars)) for x in range(size))

View File

@ -3,6 +3,8 @@ from __future__ import unicode_literals
import json
import os
import random
import re
import requests
import uuid
@ -15,6 +17,7 @@ from jose import jws, jwk, jwt
from nose.tools import assert_raises
from moto import mock_cognitoidp, settings
from moto.cognitoidp.utils import create_id
from moto.core import ACCOUNT_ID
@ -211,7 +214,7 @@ def test_create_user_pool_client():
)
result["UserPoolClient"]["UserPoolId"].should.equal(user_pool_id)
result["UserPoolClient"]["ClientId"].should_not.be.none
bool(re.match(r"^[0-9a-z]{26}$", result["UserPoolClient"]["ClientId"])).should.be.ok
result["UserPoolClient"]["ClientName"].should.equal(client_name)
result["UserPoolClient"].should_not.have.key("ClientSecret")
result["UserPoolClient"]["CallbackURLs"].should.have.length_of(1)
@ -233,7 +236,7 @@ def test_create_user_pool_client_returns_secret():
)
result["UserPoolClient"]["UserPoolId"].should.equal(user_pool_id)
result["UserPoolClient"]["ClientId"].should_not.be.none
bool(re.match(r"^[0-9a-z]{26}$", result["UserPoolClient"]["ClientId"])).should.be.ok
result["UserPoolClient"]["ClientName"].should.equal(client_name)
result["UserPoolClient"]["ClientSecret"].should_not.be.none
result["UserPoolClient"]["CallbackURLs"].should.have.length_of(1)
@ -1334,9 +1337,7 @@ def test_change_password__using_custom_user_agent_header():
def test_forgot_password():
conn = boto3.client("cognito-idp", "us-west-2")
result = conn.forgot_password(
ClientId=str(uuid.uuid4()), Username=str(uuid.uuid4())
)
result = conn.forgot_password(ClientId=create_id(), Username=str(uuid.uuid4()))
result["CodeDeliveryDetails"].should_not.be.none