Merge pull request #2742 from xnegativx/master
MessageAction for cognito admin_create_user is now handled
This commit is contained in:
commit
100dbd529f
@ -569,12 +569,17 @@ class CognitoIdpBackend(BaseBackend):
|
|||||||
user.groups.discard(group)
|
user.groups.discard(group)
|
||||||
|
|
||||||
# User
|
# 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)
|
user_pool = self.user_pools.get(user_pool_id)
|
||||||
if not user_pool:
|
if not user_pool:
|
||||||
raise ResourceNotFoundError(user_pool_id)
|
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)
|
raise UsernameExistsException(username)
|
||||||
|
|
||||||
user = CognitoIdpUser(
|
user = CognitoIdpUser(
|
||||||
|
@ -259,10 +259,12 @@ class CognitoIdpResponse(BaseResponse):
|
|||||||
def admin_create_user(self):
|
def admin_create_user(self):
|
||||||
user_pool_id = self._get_param("UserPoolId")
|
user_pool_id = self._get_param("UserPoolId")
|
||||||
username = self._get_param("Username")
|
username = self._get_param("Username")
|
||||||
|
message_action = self._get_param("MessageAction")
|
||||||
temporary_password = self._get_param("TemporaryPassword")
|
temporary_password = self._get_param("TemporaryPassword")
|
||||||
user = cognitoidp_backends[self.region].admin_create_user(
|
user = cognitoidp_backends[self.region].admin_create_user(
|
||||||
user_pool_id,
|
user_pool_id,
|
||||||
username,
|
username,
|
||||||
|
message_action,
|
||||||
temporary_password,
|
temporary_password,
|
||||||
self._get_param("UserAttributes", []),
|
self._get_param("UserAttributes", []),
|
||||||
)
|
)
|
||||||
|
@ -916,6 +916,55 @@ def test_admin_create_existing_user():
|
|||||||
caught.should.be.true
|
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
|
@mock_cognitoidp
|
||||||
def test_admin_get_user():
|
def test_admin_get_user():
|
||||||
conn = boto3.client("cognito-idp", "us-west-2")
|
conn = boto3.client("cognito-idp", "us-west-2")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user