Separate user uid/gid for libprivilege-control tests 97/39997/1
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Wed, 27 May 2015 10:44:35 +0000 (12:44 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Wed, 27 May 2015 10:46:49 +0000 (12:46 +0200)
[Problem] APP_UID/APP_GID is used by other tests and getting root uid/gid affects their results.
[Solution] Introduce separate uid/gid for libprivilege-control

[Verification] Run tests libprivilege-control-tests --output=text

Change-Id: Ib4773cddb0f0af11422684b20aa727a00433aa46

src/common/tests_common.h
src/libprivilege-control-tests/common/libprivilege-control_test_common.h
src/libprivilege-control-tests/test_cases.cpp
src/libprivilege-control-tests/test_cases_nosmack.cpp

index 57c84709cf8d67ba2982d308d51e7230fa514c5f..0cca75454a1573023d217c0a0bc08bd2a196f2d8 100644 (file)
 #include <tuple>
 #include <errno.h>
 #include <string.h>
-#include <tzplatform_config.h>
 
-const uid_t APP_UID = tzplatform_getuid(TZ_USER_NAME);
-const gid_t APP_GID = tzplatform_getgid(TZ_USER_NAME);
+const uid_t APP_UID = 5000;
+const gid_t APP_GID = 5000;
 const uid_t DB_ALARM_UID = 6001;
 const gid_t DB_ALARM_GID = 6001;
 const std::string TMP_DIR("/tmp");
index 3afb04b0bd514ac35c1d92d802a2951affe68db8..031782af013c4eb9fb9fbc2dbe6ff7716bef464c 100644 (file)
@@ -32,6 +32,7 @@
 #include <privilege-control.h>
 #include <tests_common.h>
 #include <unistd.h>
+#include <tzplatform_config.h>
 
 // How many open file descriptors should ftw() function use?
 #define FTW_MAX_FDS 16
@@ -45,6 +46,9 @@
 #define APPID_DIR              "test_APP_ID_dir"
 #define GENERATED_APP_ID       "User" // TODO to be replaced in the future
 
+const uid_t TZ_APP_UID = tzplatform_getuid(TZ_USER_NAME);
+const gid_t TZ_APP_GID = tzplatform_getgid(TZ_USER_NAME);
+
 #define PERM_TO_REDEFINE       "Test::RedefinePermission"
 #define PERM_SUB_TO_REDEFINE   "Test::RedefinePermission::Sub"
 
index e1ca540a8e1564481d8356c5d489ab3dca158eba..5cb0918362d994271b3939db43fb9f1355aa7acd 100644 (file)
@@ -228,7 +228,7 @@ void test_set_app_privilege(
     RUNNER_ASSERT_MSG(result == 1, "Permissions not added.");
 
     std::set<unsigned> groups_before;
-    read_user_gids(groups_before, APP_UID);
+    read_user_gids(groups_before, TZ_APP_UID);
 
     result = perm_app_set_privilege(app_id, type, app_path);
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
index dcef0427ae98e738b67521f644765531750965b3..03fdf237db76b7a7463a7349af7eac5d3102afb4 100644 (file)
@@ -138,7 +138,7 @@ void test_set_app_privilege_nosmack(
             " Permissions shouldn't be added. Result: " << result);
 
     std::set<unsigned> groups_before;
-    read_user_gids(groups_before, APP_UID);
+    read_user_gids(groups_before, TZ_APP_UID);
 
     result = perm_app_set_privilege(app_id, type, app_path);
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
@@ -176,7 +176,7 @@ RUNNER_CHILD_TEST_NOSMACK(privilege_control05_set_app_privilege_nosmack)
     DB_END
 
     std::set<unsigned> groups_before;
-    read_user_gids(groups_before, APP_UID);
+    read_user_gids(groups_before, TZ_APP_UID);
 
     //Set app privileges
     result = perm_app_set_privilege(APP_ID, nullptr, APP_SET_PRIV_PATH);
@@ -191,8 +191,8 @@ RUNNER_CHILD_TEST_NOSMACK(privilege_control05_set_app_privilege_nosmack)
     RUNNER_ASSERT_MSG(label == nullptr, "new_label_from_self shouldn't allocate memory for label.");
 
     //Check if DAC privileges really set
-    RUNNER_ASSERT_MSG(getuid() == APP_UID, "Wrong UID");
-    RUNNER_ASSERT_MSG(getgid() == APP_GID, "Wrong GID");
+    RUNNER_ASSERT_MSG(getuid() == TZ_APP_UID, "Wrong UID");
+    RUNNER_ASSERT_MSG(getgid() == TZ_APP_GID, "Wrong GID");
 
     result = strcmp(getenv("HOME"), APP_HOME_DIR);
     RUNNER_ASSERT_MSG(result == 0, "Wrong HOME DIR. Result: " << result);