Add tests for security_manager_set_identity() 28/316728/11
authorJan Wojtkowski <j.wojtkowski@samsung.com>
Mon, 2 Dec 2024 16:02:24 +0000 (17:02 +0100)
committerJan Wojtkowski <j.wojtkowski@samsung.com>
Fri, 20 Dec 2024 15:31:44 +0000 (15:31 +0000)
Change-Id: I4a125d42d5e0c9cd579472df0bba54053e5489a2

src/security-manager-tests/test_cases.cpp

index 2d8cf74d6b5a3fb1ea3dbde89e2d557b7a14091b..dada281b1d80116c28d3973ac97e27f61f8e67b2 100644 (file)
@@ -706,6 +706,49 @@ RUNNER_CHILD_TEST(security_manager_10_app_has_privilege)
     // FIXME - all other existing privileges should be checked
 }
 
+RUNNER_CHILD_TEST(security_manager_11_set_identity)
+{
+    pid_t pid1 = fork();
+    RUNNER_ASSERT_ERRNO_MSG(pid1 >= 0, "Fork 1 failed");
+    if (pid1 != 0) { //parent process
+        waitPid(pid1);
+    } else {
+        int result = security_manager_set_identity(process_type::SM_PROCESS_TYPE_SYSTEM, nullptr);
+        RUNNER_ASSERT_MSG(result == SECURITY_MANAGER_SUCCESS,
+                "security_manager_set_identity(SM_PROCESS_TYPE_SYSTEM, nullptr) failed");
+        exit(0);
+    }
+
+    pid_t pid2 = fork();
+    RUNNER_ASSERT_ERRNO_MSG(pid2 >= 0, "Fork 2 failed");
+    if (pid2 != 0) { //parent process
+        waitPid(pid2);
+    } else {
+        int result = security_manager_set_identity(process_type::SM_PROCESS_TYPE_SYSTEM_PRIVILEGED, nullptr);
+        RUNNER_ASSERT_MSG(result == SECURITY_MANAGER_SUCCESS,
+                "security_manager_set_identity(SM_PROCESS_TYPE_SYSTEM_PRIVILEGED, nullptr) failed");
+        exit(0);
+    }
+
+    const std::string appLocalName = "sm_test_set_identity_local1";
+    AppInstallHelper appLocal(appLocalName);
+    ScopedInstaller appInstall(appLocal);
+
+    pid_t pid3 = fork();
+    RUNNER_ASSERT_ERRNO_MSG(pid3 >= 0, "Fork 3 failed");
+    if (pid3 != 0) { //parent process
+        waitPid(pid3);
+    } else {
+        int result = security_manager_set_identity(process_type::SM_PROCESS_TYPE_APP, nullptr);
+        RUNNER_ASSERT_MSG(result == SECURITY_MANAGER_ERROR_INPUT_PARAM,
+                "security_manager_set_identity(SM_PROCESS_TYPE_APP, nullptr) wrongly succeeded");
+        result = security_manager_set_identity(process_type::SM_PROCESS_TYPE_APP, appLocal.getAppId().c_str());
+        RUNNER_ASSERT_MSG(result == SECURITY_MANAGER_SUCCESS,
+                "security_manager_set_identity(SM_PROCESS_TYPE_APP, appLocal.getAppId().c_str()) failed");
+        exit(0);
+    }
+}
+
 RUNNER_TEST_GROUP_INIT(SECURITY_MANAGER_POLICY)
 
 RUNNER_TEST(security_manager_20_user_cynara_policy)