Fix the privilege check skipping logic 65/322865/2
authorDongsun Lee <ds73.lee@samsung.com>
Thu, 17 Apr 2025 04:08:22 +0000 (13:08 +0900)
committerDongsun Lee <ds73.lee@samsung.com>
Thu, 17 Apr 2025 08:30:06 +0000 (17:30 +0900)
Change-Id: Ib42fd9e8d7ac8067bb52eb48be4494f013594b56

tests/test-admin.cpp
tests/test-client.cpp
tests/test-util.h

index c35dbced9f397e06a3445ccf647d92a3552b44f3..0e4be6999f6f2cf9e2fc47fd5b7f4532f7ba056a 100644 (file)
@@ -764,19 +764,12 @@ TESTCASE(T00210_reset_passwd_privilege)
        auto reset_passwd_function = [] () -> int {
                return auth_passwd_reset_passwd(AUTH_PWD_NORMAL, test::get_test_uid(false), default_pass);
        };
-       if(access(org_tizen_setting_main,F_OK) == 0){
-               TEST_EXPECT(true, test::run_in_process(SM_PROCESS_TYPE_APP, org_tizen_setting_main,
-                       AUTH_PASSWD_API_ERROR_ACCESS_DENIED, reset_passwd_function));
-       }else{
-               std::cout << "reset_passwd_function in reset_passwd_privileg() skipped" << ", appId=" << org_tizen_setting_main << std::endl;
-       }
-
-       if(access(org_tizen_apps,F_OK) == 0){
-               TEST_EXPECT(true, test::run_in_process(SM_PROCESS_TYPE_APP, org_tizen_apps,
-                       AUTH_PASSWD_API_SUCCESS, reset_passwd_function));
-       }else{
-               std::cout << "reset_passwd_function in reset_passwd_privileg() skipped" << ", appId=" << org_tizen_apps << std::endl;
-       }
+
+       TEST_EXPECT(true, test::run_in_process(SM_PROCESS_TYPE_APP, org_tizen_setting_main,
+               AUTH_PASSWD_API_ERROR_ACCESS_DENIED, reset_passwd_function));
+
+       TEST_EXPECT(true, test::run_in_process(SM_PROCESS_TYPE_APP, org_tizen_apps,
+               AUTH_PASSWD_API_SUCCESS, reset_passwd_function));
 
        TEST_EXPECT(true, test::run_in_process(SM_PROCESS_TYPE_SYSTEM, "",
                AUTH_PASSWD_API_SUCCESS, reset_passwd_function));
@@ -803,19 +796,13 @@ TESTCASE(T00211_set_policy_privilege)
 
                return auth_passwd_set_policy(policy);;
        };
-       if(access(org_tizen_setting_main,F_OK) == 0){
-               TEST_EXPECT(true, test::run_in_process(SM_PROCESS_TYPE_APP, org_tizen_setting_main,
-                       AUTH_PASSWD_API_ERROR_ACCESS_DENIED, set_policy_function));
-       }else{
-               std::cout << "set_policy_function in set_policy_privilege() skipped" << ", appId=" << org_tizen_setting_main << std::endl;
-       }
-
-       if(access(org_tizen_apps,F_OK) == 0){
-               TEST_EXPECT(true, test::run_in_process(SM_PROCESS_TYPE_APP, org_tizen_apps,
-                       AUTH_PASSWD_API_SUCCESS, set_policy_function));
-       }else{
-               std::cout << "set_policy_function in set_policy_privilege() skipped" << ", appId=" << org_tizen_apps << std::endl;
-       }
+
+       TEST_EXPECT(true, test::run_in_process(SM_PROCESS_TYPE_APP, org_tizen_setting_main,
+               AUTH_PASSWD_API_ERROR_ACCESS_DENIED, set_policy_function));
+
+       TEST_EXPECT(true, test::run_in_process(SM_PROCESS_TYPE_APP, org_tizen_apps,
+               AUTH_PASSWD_API_SUCCESS, set_policy_function));
+
 
        TEST_EXPECT(true, test::run_in_process(SM_PROCESS_TYPE_SYSTEM, "",
                AUTH_PASSWD_API_SUCCESS, set_policy_function));
index 316fae30e9f7cbf572b70f4d3b9e619cbc8647cf..dfa7887ee92dcc687b9cf097fe147d00aeda9f3e 100644 (file)
@@ -280,18 +280,13 @@ TESTCASE(T00120_check_passwd_privilege)
        TEST_EXPECT(AUTH_PASSWD_API_SUCCESS, ret);
        ret = auth_passwd_disable_policy(AUTH_PWD_NORMAL, test::get_test_uid(true));
        TEST_EXPECT(AUTH_PASSWD_API_SUCCESS, ret);
-       if(access(org_tizen_setting_main,F_OK) == 0){
-               TEST_EXPECT(true, test::run_in_process(SM_PROCESS_TYPE_APP, org_tizen_setting_main,
-                       AUTH_PASSWD_API_ERROR_ACCESS_DENIED, check_passwd_function));
-       }else{
-               std::cout << "check_passwd_function in check_passwd_privilege() skipped" << ", appId=" << org_tizen_setting_main << std::endl;
-       }
-       if(access(org_tizen_apps,F_OK) == 0){
-               TEST_EXPECT(true, test::run_in_process(SM_PROCESS_TYPE_APP, org_tizen_apps,
-                       AUTH_PASSWD_API_SUCCESS, check_passwd_function));
-       }else{
-               std::cout << "check_passwd_function in check_passwd_privilege() skipped" << ", appId=" << org_tizen_apps << std::endl;
-       }
+
+       TEST_EXPECT(true, test::run_in_process(SM_PROCESS_TYPE_APP, org_tizen_setting_main,
+               AUTH_PASSWD_API_ERROR_ACCESS_DENIED, check_passwd_function));
+
+       TEST_EXPECT(true, test::run_in_process(SM_PROCESS_TYPE_APP, org_tizen_apps,
+               AUTH_PASSWD_API_SUCCESS, check_passwd_function));
+
        TEST_EXPECT(true, test::run_in_process(SM_PROCESS_TYPE_SYSTEM, "",
                AUTH_PASSWD_API_SUCCESS, check_passwd_function));
 
@@ -307,24 +302,17 @@ TESTCASE(T00121_set_passwd_privilege)
                return auth_passwd_set_passwd(AUTH_PWD_NORMAL, default_pass, AUTH_PWD_NORMAL, NULL);
        };
 
-       if(access(org_tizen_setting_main,F_OK) == 0){
-               int ret = auth_passwd_reset_passwd(AUTH_PWD_NORMAL, test::get_test_uid(true), default_pass);
-               TEST_EXPECT(AUTH_PASSWD_API_SUCCESS, ret);
-               TEST_EXPECT(true, test::run_in_process(SM_PROCESS_TYPE_APP, org_tizen_setting_main,
-                       AUTH_PASSWD_API_ERROR_ACCESS_DENIED, set_passwd_function));
-       }else{
-               std::cout << "set_passwd_function in set_passwd_privilege() skipped" << ", appId=" << org_tizen_setting_main << std::endl;
-       }
-
-       if(access(org_tizen_apps,F_OK) == 0){
-               int ret = auth_passwd_reset_passwd(AUTH_PWD_NORMAL, test::get_test_uid(true), default_pass);
-               TEST_EXPECT(AUTH_PASSWD_API_SUCCESS, ret);
-               TEST_EXPECT(true, test::run_in_process(SM_PROCESS_TYPE_APP, org_tizen_apps,
-                       AUTH_PASSWD_API_SUCCESS, set_passwd_function));
-       }else{
-               std::cout << "set_passwd_function in set_passwd_privilege() skipped" << ", appId=" << org_tizen_apps << std::endl;
-       }
-       int ret = auth_passwd_reset_passwd(AUTH_PWD_NORMAL, test::get_test_uid(false), default_pass);
+       int ret = auth_passwd_reset_passwd(AUTH_PWD_NORMAL, test::get_test_uid(true), default_pass);
+       TEST_EXPECT(AUTH_PASSWD_API_SUCCESS, ret);
+       TEST_EXPECT(true, test::run_in_process(SM_PROCESS_TYPE_APP, org_tizen_setting_main,
+               AUTH_PASSWD_API_ERROR_ACCESS_DENIED, set_passwd_function));
+
+       ret = auth_passwd_reset_passwd(AUTH_PWD_NORMAL, test::get_test_uid(true), default_pass);
+       TEST_EXPECT(AUTH_PASSWD_API_SUCCESS, ret);
+       TEST_EXPECT(true, test::run_in_process(SM_PROCESS_TYPE_APP, org_tizen_apps,
+               AUTH_PASSWD_API_SUCCESS, set_passwd_function));
+
+       ret = auth_passwd_reset_passwd(AUTH_PWD_NORMAL, test::get_test_uid(false), default_pass);
        TEST_EXPECT(AUTH_PASSWD_API_SUCCESS, ret);
        TEST_EXPECT(true, test::run_in_process(SM_PROCESS_TYPE_SYSTEM, "",
                AUTH_PASSWD_API_SUCCESS, set_passwd_function));
index daf545c71476e7bd8169f418282cd9d0337a68ed..f765715bd4249698d5fdde2a5b97d92e7cca6a10 100644 (file)
@@ -32,6 +32,9 @@
 
 #include <app-runtime.h>
 
+#include <unistd.h>
+#include <sys/types.h>
+
 namespace test {
 
 policy_h *create_policy_h();
@@ -44,6 +47,8 @@ int set_relative_date(int days);
 
 using ScopedPolicy = std::unique_ptr<policy_h, decltype(&auth_passwd_free_policy)>;
 
+constexpr int APP_UID = 5001;
+
 template<typename Functor>
 bool run_in_process(process_type ptype, const std::string& appId, int expected, Functor functor)
 {
@@ -58,9 +63,14 @@ bool run_in_process(process_type ptype, const std::string& appId, int expected,
 
                if(ret != SECURITY_MANAGER_SUCCESS) {
                        std::cout << "security_manager_set_identity() failed... ret=" << ret
-                               << ", appId=" << appId << std::endl;
-                       exit(2); // error case
+                               << ", appId=" << appId << ",... Not Supported TC. Skipping..." << std::endl;
+                       exit(0); // Skipping
                }
+
+               if (ptype == SM_PROCESS_TYPE_APP) {
+                       setuid(APP_UID); // Do not check the return code
+               }
+
                ret = functor();
                if(ret != expected) {
                        std::cout << "The test in separated process failed..."