Add test for security_manager_is_app_from_pid() 24/317824/1
authorTomasz Swierczek <t.swierczek@samsung.com>
Wed, 8 Jan 2025 07:26:06 +0000 (08:26 +0100)
committerTomasz Swierczek <t.swierczek@samsung.com>
Wed, 8 Jan 2025 07:53:44 +0000 (08:53 +0100)
Change-Id: I069cda129f9df3fc52a4bf123692ab1a9fe75a5c

src/security-manager-tests/test_cases.cpp

index 3bfdccb60279fcf6d27af82db73d6e7b4f0cb41e..2cac54932edc5cf8e20dbe4d0b64a274082088d0 100644 (file)
@@ -1184,3 +1184,44 @@ RUNNER_CHILD_TEST(security_manager_26_2_security_manager_self_is_app)
     }
     app.checkAfterUninstall();
 }
+
+RUNNER_CHILD_TEST(security_manager_26_3_security_manager_is_app_from_pid)
+{
+    SynchronizationPipe pipe;
+    TemporaryTestUser testUser("sm_test_26_3_user_name", GUM_USERTYPE_NORMAL);
+    testUser.create();
+
+    AppInstallHelperExt app("sm_test_26_3");
+    {
+        ScopedInstaller appInstall(app);
+
+        app.checkAfterInstall();
+
+        pid_t pid = fork();
+        RUNNER_ASSERT_ERRNO_MSG(pid >= 0, "Fork failed");
+        if (pid != 0) {
+            pipe.claimParentEp();
+            // here we can check if function will return it is NOT an app
+            bool is_app;
+            RUNNER_ASSERT_MSG(security_manager_is_app_from_pid(getpid(), &is_app) == SECURITY_MANAGER_SUCCESS,
+                              "failed security_manager_is_app_from_pid");
+            RUNNER_ASSERT_MSG(is_app == false, "this should not be an app");
+            pipe.wait(); //synchronization point of setting Smack label - A1
+            RUNNER_ASSERT_MSG(security_manager_is_app_from_pid(pid, &is_app) == SECURITY_MANAGER_SUCCESS,
+                              "failed security_manager_is_app_from_pid");
+            RUNNER_ASSERT_MSG(is_app == true, "this should be an app");
+            waitPid(pid);
+        } else {
+            pipe.claimChildEp();
+            // here we can check if the function will return it IS an app
+            Api::setProcessLabel(app.getAppId());
+            pipe.post(); // A1
+            bool is_app;
+            RUNNER_ASSERT_MSG(security_manager_is_app_from_pid(getpid(), &is_app) == SECURITY_MANAGER_SUCCESS,
+                              "failed security_manager_is_app_from_pid");
+            RUNNER_ASSERT_MSG(is_app == true, "this should be an app");
+            exit(0);
+        }
+    }
+    app.checkAfterUninstall();
+}