Repository: getmoto/moto

Issue:
cognito-idp admin_confirm_sign_up is not implemented
Feature request for adding `admin_confirm_sign_up` in `cognito-idp` client


Discussion:

Resolving patch:
diff --git a/moto/cognitoidp/models.py b/moto/cognitoidp/models.py
--- a/moto/cognitoidp/models.py
+++ b/moto/cognitoidp/models.py
@@ -706,6 +706,18 @@ def admin_create_user(
         user_pool.users[user.username] = 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):
         user_pool = self.user_pools.get(user_pool_id)
         if not user_pool:
diff --git a/moto/cognitoidp/responses.py b/moto/cognitoidp/responses.py
--- a/moto/cognitoidp/responses.py
+++ b/moto/cognitoidp/responses.py
@@ -318,6 +318,13 @@ def admin_create_user(self):
 
         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):
         user_pool_id = self._get_param("UserPoolId")
         username = self._get_param("Username")


Test patch:
diff --git a/tests/test_cognitoidp/test_cognitoidp.py b/tests/test_cognitoidp/test_cognitoidp.py
--- a/tests/test_cognitoidp/test_cognitoidp.py
+++ b/tests/test_cognitoidp/test_cognitoidp.py
@@ -1276,6 +1276,59 @@ def test_admin_create_existing_user():
     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
 def test_admin_resend_invitation_existing_user():
     conn = boto3.client("cognito-idp", "us-west-2")