fix cognito-idp UserPool ClientId (#3165)
* fix cognito-idp UserPool ClientId * add test * replace uuid4 to create_id
This commit is contained in:
parent
bf8eb11dc3
commit
448ff45174
@ -23,6 +23,7 @@ from .exceptions import (
|
|||||||
UsernameExistsException,
|
UsernameExistsException,
|
||||||
InvalidParameterException,
|
InvalidParameterException,
|
||||||
)
|
)
|
||||||
|
from .utils import create_id
|
||||||
|
|
||||||
UserStatus = {
|
UserStatus = {
|
||||||
"FORCE_CHANGE_PASSWORD": "FORCE_CHANGE_PASSWORD",
|
"FORCE_CHANGE_PASSWORD": "FORCE_CHANGE_PASSWORD",
|
||||||
@ -214,7 +215,7 @@ class CognitoIdpUserPoolDomain(BaseModel):
|
|||||||
class CognitoIdpUserPoolClient(BaseModel):
|
class CognitoIdpUserPoolClient(BaseModel):
|
||||||
def __init__(self, user_pool_id, generate_secret, extended_config):
|
def __init__(self, user_pool_id, generate_secret, extended_config):
|
||||||
self.user_pool_id = user_pool_id
|
self.user_pool_id = user_pool_id
|
||||||
self.id = str(uuid.uuid4())
|
self.id = create_id()
|
||||||
self.secret = str(uuid.uuid4())
|
self.secret = str(uuid.uuid4())
|
||||||
self.generate_secret = generate_secret or False
|
self.generate_secret = generate_secret or False
|
||||||
self.extended_config = extended_config or {}
|
self.extended_config = extended_config or {}
|
||||||
|
10
moto/cognitoidp/utils.py
Normal file
10
moto/cognitoidp/utils.py
Normal 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))
|
@ -3,6 +3,8 @@ from __future__ import unicode_literals
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
|
import re
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
@ -15,6 +17,7 @@ from jose import jws, jwk, jwt
|
|||||||
from nose.tools import assert_raises
|
from nose.tools import assert_raises
|
||||||
|
|
||||||
from moto import mock_cognitoidp, settings
|
from moto import mock_cognitoidp, settings
|
||||||
|
from moto.cognitoidp.utils import create_id
|
||||||
from moto.core import ACCOUNT_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"]["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"]["ClientName"].should.equal(client_name)
|
||||||
result["UserPoolClient"].should_not.have.key("ClientSecret")
|
result["UserPoolClient"].should_not.have.key("ClientSecret")
|
||||||
result["UserPoolClient"]["CallbackURLs"].should.have.length_of(1)
|
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"]["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"]["ClientName"].should.equal(client_name)
|
||||||
result["UserPoolClient"]["ClientSecret"].should_not.be.none
|
result["UserPoolClient"]["ClientSecret"].should_not.be.none
|
||||||
result["UserPoolClient"]["CallbackURLs"].should.have.length_of(1)
|
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():
|
def test_forgot_password():
|
||||||
conn = boto3.client("cognito-idp", "us-west-2")
|
conn = boto3.client("cognito-idp", "us-west-2")
|
||||||
|
|
||||||
result = conn.forgot_password(
|
result = conn.forgot_password(ClientId=create_id(), Username=str(uuid.uuid4()))
|
||||||
ClientId=str(uuid.uuid4()), Username=str(uuid.uuid4())
|
|
||||||
)
|
|
||||||
result["CodeDeliveryDetails"].should_not.be.none
|
result["CodeDeliveryDetails"].should_not.be.none
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user