Add tests for new APIs 73/316673/4
authorTomasz Swierczek <t.swierczek@samsung.com>
Mon, 16 Dec 2024 11:47:58 +0000 (12:47 +0100)
committerTomasz Swierczek <t.swierczek@samsung.com>
Mon, 30 Dec 2024 12:24:24 +0000 (12:24 +0000)
* security_manager_get_app_owner_uid
* security_manager_self_is_app

Change-Id: I34bd9a719417cdc1b05554bbaff0886a6b9322ec

src/security-manager-tests/test_cases.cpp

index dada281b1d80116c28d3973ac97e27f61f8e67b2..3bfdccb60279fcf6d27af82db73d6e7b4f0cb41e 100644 (file)
@@ -1128,3 +1128,59 @@ RUNNER_CHILD_TEST(security_manager_26_hybrid_pkg_uninstall_artifacts_check)
     app1.checkAfterUninstall(false);
     app2.checkAfterUninstall();
 }
+
+RUNNER_CHILD_TEST(security_manager_26_1_security_manager_get_app_owner_uid)
+{
+    TemporaryTestUser testUser("sm_test_26_1_user_name", GUM_USERTYPE_NORMAL);
+    testUser.create();
+    pid_t pid = fork();
+    RUNNER_ASSERT_ERRNO_MSG(pid >= 0, "Fork failed");
+    if (pid != 0) {
+        uid_t parent_uid;
+        RUNNER_ASSERT_MSG(security_manager_get_app_owner_uid(getpid(), &parent_uid) == SECURITY_MANAGER_SUCCESS,
+                                "Invalid return from security_manager_get_app_owner_uid()");
+        RUNNER_ASSERT_MSG(parent_uid == getuid(), "Invalid uid returned");
+        waitPid(pid);
+    } else {
+        RUNNER_ASSERT_ERRNO_MSG(setuid(testUser.getUid()) == 0, "setuid failed");
+        uid_t uid;
+        RUNNER_ASSERT_MSG(security_manager_get_app_owner_uid(getpid(), &uid) == SECURITY_MANAGER_SUCCESS,
+                                "Invalid return from security_manager_get_app_owner_uid()");
+        RUNNER_ASSERT_MSG(uid == testUser.getUid(), "Invalid uid returned");
+        exit(0);
+    }
+}
+
+
+RUNNER_CHILD_TEST(security_manager_26_2_security_manager_self_is_app)
+{
+    TemporaryTestUser testUser("sm_test_26_2_user_name", GUM_USERTYPE_NORMAL);
+    testUser.create();
+
+    AppInstallHelperExt app("sm_test_26_2");
+    {
+        ScopedInstaller appInstall(app);
+
+        app.checkAfterInstall();
+
+        pid_t pid = fork();
+        RUNNER_ASSERT_ERRNO_MSG(pid >= 0, "Fork failed");
+        if (pid != 0) {
+            // here we can check if function will return it is NOT an app
+            bool is_app;
+            RUNNER_ASSERT_MSG(security_manager_self_is_app(&is_app) == SECURITY_MANAGER_SUCCESS,
+                              "failed security_manager_self_is_app");
+            RUNNER_ASSERT_MSG(is_app == false, "this should not be an app");
+            waitPid(pid);
+        } else {
+            // here we can check if the function will return it IS an app
+            Api::setProcessLabel(app.getAppId());
+            bool is_app;
+            RUNNER_ASSERT_MSG(security_manager_self_is_app(&is_app) == SECURITY_MANAGER_SUCCESS,
+                              "failed security_manager_self_is_app");
+            RUNNER_ASSERT_MSG(is_app == true, "this should be an app");
+            exit(0);
+        }
+    }
+    app.checkAfterUninstall();
+}