From: Tomasz Swierczek Date: Mon, 16 Dec 2024 11:47:58 +0000 (+0100) Subject: Add tests for new APIs X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F73%2F316673%2F4;p=platform%2Fcore%2Ftest%2Fsecurity-tests.git Add tests for new APIs * security_manager_get_app_owner_uid * security_manager_self_is_app Change-Id: I34bd9a719417cdc1b05554bbaff0886a6b9322ec --- diff --git a/src/security-manager-tests/test_cases.cpp b/src/security-manager-tests/test_cases.cpp index dada281b..3bfdccb6 100644 --- a/src/security-manager-tests/test_cases.cpp +++ b/src/security-manager-tests/test_cases.cpp @@ -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(); +}