parent
728039bce1
commit
ce91a8d615
@ -706,6 +706,18 @@ class CognitoIdpBackend(BaseBackend):
|
|||||||
user_pool.users[user.username] = user
|
user_pool.users[user.username] = user
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
def admin_confirm_sign_up(self, user_pool_id, username):
|
||||||
|
user_pool = self.user_pools.get(user_pool_id)
|
||||||
|
if not user_pool:
|
||||||
|
raise ResourceNotFoundError(f"User pool {user_pool_id} does not exist.")
|
||||||
|
|
||||||
|
user = user_pool._get_user(username)
|
||||||
|
if not user:
|
||||||
|
raise UserNotFoundError(f"User does not exist.")
|
||||||
|
|
||||||
|
user.status = UserStatus["CONFIRMED"]
|
||||||
|
return ""
|
||||||
|
|
||||||
def admin_get_user(self, user_pool_id, username):
|
def admin_get_user(self, user_pool_id, username):
|
||||||
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:
|
||||||
|
@ -318,6 +318,13 @@ class CognitoIdpResponse(BaseResponse):
|
|||||||
|
|
||||||
return json.dumps({"User": user.to_json(extended=True)})
|
return json.dumps({"User": user.to_json(extended=True)})
|
||||||
|
|
||||||
|
def admin_confirm_sign_up(self):
|
||||||
|
user_pool_id = self._get_param("UserPoolId")
|
||||||
|
username = self._get_param("Username")
|
||||||
|
return cognitoidp_backends[self.region].admin_confirm_sign_up(
|
||||||
|
user_pool_id, username
|
||||||
|
)
|
||||||
|
|
||||||
def admin_get_user(self):
|
def admin_get_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")
|
||||||
|
@ -1276,6 +1276,59 @@ def test_admin_create_existing_user():
|
|||||||
caught.should.be.true
|
caught.should.be.true
|
||||||
|
|
||||||
|
|
||||||
|
@mock_cognitoidp
|
||||||
|
def test_admin_confirm_sign_up():
|
||||||
|
conn = boto3.client("cognito-idp", "us-east-1")
|
||||||
|
|
||||||
|
username = str(uuid.uuid4())
|
||||||
|
password = "Passw0rd!"
|
||||||
|
user_pool_id = conn.create_user_pool(
|
||||||
|
PoolName="us-east-1_aaaaaaaa", AutoVerifiedAttributes=["email"]
|
||||||
|
)["UserPool"]["Id"]
|
||||||
|
client_id = conn.create_user_pool_client(
|
||||||
|
UserPoolId=user_pool_id, ClientName=str(uuid.uuid4()), GenerateSecret=False
|
||||||
|
)["UserPoolClient"]["ClientId"]
|
||||||
|
conn.sign_up(ClientId=client_id, Username=username, Password=password)
|
||||||
|
user = conn.admin_get_user(UserPoolId=user_pool_id, Username=username)
|
||||||
|
|
||||||
|
user["UserStatus"].should.equal("UNCONFIRMED")
|
||||||
|
|
||||||
|
conn.admin_confirm_sign_up(UserPoolId=user_pool_id, Username=username)
|
||||||
|
user = conn.admin_get_user(UserPoolId=user_pool_id, Username=username,)
|
||||||
|
|
||||||
|
user["UserStatus"].should.equal("CONFIRMED")
|
||||||
|
|
||||||
|
|
||||||
|
@mock_cognitoidp
|
||||||
|
def test_admin_confirm_sign_up_non_existing_user():
|
||||||
|
conn = boto3.client("cognito-idp", "us-east-1")
|
||||||
|
|
||||||
|
username = str(uuid.uuid4())
|
||||||
|
user_pool_id = conn.create_user_pool(
|
||||||
|
PoolName="us-east-1_aaaaaaaa", AutoVerifiedAttributes=["email"]
|
||||||
|
)["UserPool"]["Id"]
|
||||||
|
|
||||||
|
with pytest.raises(ClientError) as exc:
|
||||||
|
conn.admin_confirm_sign_up(UserPoolId=user_pool_id, Username=username)
|
||||||
|
|
||||||
|
err = exc.value.response["Error"]
|
||||||
|
err["Code"].should.equal("UserNotFoundException")
|
||||||
|
err["Message"].should.equal(f"User does not exist.")
|
||||||
|
|
||||||
|
|
||||||
|
@mock_cognitoidp
|
||||||
|
def test_admin_confirm_sign_up_non_existing_pool():
|
||||||
|
conn = boto3.client("cognito-idp", "us-east-1")
|
||||||
|
|
||||||
|
user_pool_id = "us-east-1_aaaaaaaa"
|
||||||
|
with pytest.raises(ClientError) as exc:
|
||||||
|
conn.admin_confirm_sign_up(UserPoolId=user_pool_id, Username=str(uuid.uuid4()))
|
||||||
|
|
||||||
|
err = exc.value.response["Error"]
|
||||||
|
err["Code"].should.equal("ResourceNotFoundException")
|
||||||
|
err["Message"].should.equal(f"User pool {user_pool_id} does not exist.")
|
||||||
|
|
||||||
|
|
||||||
@mock_cognitoidp
|
@mock_cognitoidp
|
||||||
def test_admin_resend_invitation_existing_user():
|
def test_admin_resend_invitation_existing_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