Cognito IdP: Raise UsernameExistsException from sign_up when user exists (#3765)
* Raise UsernameExistsException from sign_up when user exists * Run formatter * Use pytest.raises * Fix test
This commit is contained in:
parent
5fe3a707ed
commit
b9f83c200f
@ -883,6 +883,8 @@ class CognitoIdpBackend(BaseBackend):
|
||||
user_pool = p
|
||||
if user_pool is None:
|
||||
raise ResourceNotFoundError(client_id)
|
||||
elif username in user_pool.users:
|
||||
raise UsernameExistsException(username)
|
||||
|
||||
user = CognitoIdpUser(
|
||||
user_pool_id=user_pool.id,
|
||||
|
@ -1603,6 +1603,26 @@ def test_sign_up():
|
||||
result["UserSub"].should_not.be.none
|
||||
|
||||
|
||||
@mock_cognitoidp
|
||||
def test_sign_up_existing_user():
|
||||
conn = boto3.client("cognito-idp", "us-west-2")
|
||||
user_pool_id = conn.create_user_pool(PoolName=str(uuid.uuid4()))["UserPool"]["Id"]
|
||||
client_id = conn.create_user_pool_client(
|
||||
UserPoolId=user_pool_id, ClientName=str(uuid.uuid4()),
|
||||
)["UserPoolClient"]["ClientId"]
|
||||
username = str(uuid.uuid4())
|
||||
password = str(uuid.uuid4())
|
||||
|
||||
# Add initial user
|
||||
conn.sign_up(ClientId=client_id, Username=username, Password=password)
|
||||
|
||||
with pytest.raises(ClientError) as err:
|
||||
# Attempt to add user again
|
||||
conn.sign_up(ClientId=client_id, Username=username, Password=password)
|
||||
|
||||
err.value.response["Error"]["Code"].should.equal("UsernameExistsException")
|
||||
|
||||
|
||||
@mock_cognitoidp
|
||||
def test_confirm_sign_up():
|
||||
conn = boto3.client("cognito-idp", "us-west-2")
|
||||
|
Loading…
Reference in New Issue
Block a user