MessageAction for cognito admin_create_user is now handled
If an invitation is attempted to be reset to a pool we validate that the user is indeed already in the pool else we raise a UserNotFoundException to match AWS behaviour
This commit is contained in:
parent
39751a6961
commit
fa3904df29
@ -564,12 +564,15 @@ class CognitoIdpBackend(BaseBackend):
|
||||
user.groups.discard(group)
|
||||
|
||||
# User
|
||||
def admin_create_user(self, user_pool_id, username, temporary_password, attributes):
|
||||
def admin_create_user(self, user_pool_id, username, message_action, temporary_password, attributes):
|
||||
user_pool = self.user_pools.get(user_pool_id)
|
||||
if not user_pool:
|
||||
raise ResourceNotFoundError(user_pool_id)
|
||||
|
||||
if username in user_pool.users:
|
||||
if message_action and message_action == "RESEND":
|
||||
if username not in user_pool.users:
|
||||
raise UserNotFoundError(username)
|
||||
elif username in user_pool.users:
|
||||
raise UsernameExistsException(username)
|
||||
|
||||
user = CognitoIdpUser(
|
||||
|
@ -259,10 +259,12 @@ class CognitoIdpResponse(BaseResponse):
|
||||
def admin_create_user(self):
|
||||
user_pool_id = self._get_param("UserPoolId")
|
||||
username = self._get_param("Username")
|
||||
message_action = self._get_param("MessageAction")
|
||||
temporary_password = self._get_param("TemporaryPassword")
|
||||
user = cognitoidp_backends[self.region].admin_create_user(
|
||||
user_pool_id,
|
||||
username,
|
||||
message_action,
|
||||
temporary_password,
|
||||
self._get_param("UserAttributes", []),
|
||||
)
|
||||
|
@ -911,6 +911,55 @@ def test_admin_create_existing_user():
|
||||
caught.should.be.true
|
||||
|
||||
|
||||
@mock_cognitoidp
|
||||
def test_admin_resend_invitation_existing_user():
|
||||
conn = boto3.client("cognito-idp", "us-west-2")
|
||||
|
||||
username = str(uuid.uuid4())
|
||||
value = str(uuid.uuid4())
|
||||
user_pool_id = conn.create_user_pool(PoolName=str(uuid.uuid4()))["UserPool"]["Id"]
|
||||
conn.admin_create_user(
|
||||
UserPoolId=user_pool_id,
|
||||
Username=username,
|
||||
UserAttributes=[{"Name": "thing", "Value": value}],
|
||||
)
|
||||
|
||||
caught = False
|
||||
try:
|
||||
conn.admin_create_user(
|
||||
UserPoolId=user_pool_id,
|
||||
Username=username,
|
||||
UserAttributes=[{"Name": "thing", "Value": value}],
|
||||
MessageAction="RESEND",
|
||||
)
|
||||
except conn.exceptions.UsernameExistsException:
|
||||
caught = True
|
||||
|
||||
caught.should.be.false
|
||||
|
||||
|
||||
@mock_cognitoidp
|
||||
def test_admin_resend_invitation_missing_user():
|
||||
conn = boto3.client("cognito-idp", "us-west-2")
|
||||
|
||||
username = str(uuid.uuid4())
|
||||
value = str(uuid.uuid4())
|
||||
user_pool_id = conn.create_user_pool(PoolName=str(uuid.uuid4()))["UserPool"]["Id"]
|
||||
|
||||
caught = False
|
||||
try:
|
||||
conn.admin_create_user(
|
||||
UserPoolId=user_pool_id,
|
||||
Username=username,
|
||||
UserAttributes=[{"Name": "thing", "Value": value}],
|
||||
MessageAction="RESEND",
|
||||
)
|
||||
except conn.exceptions.UserNotFoundException:
|
||||
caught = True
|
||||
|
||||
caught.should.be.true
|
||||
|
||||
|
||||
@mock_cognitoidp
|
||||
def test_admin_get_user():
|
||||
conn = boto3.client("cognito-idp", "us-west-2")
|
||||
|
Loading…
Reference in New Issue
Block a user