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 57c8470..0cca754 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 3afb04b..031782a 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 e1ca540..5cb0918 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 dcef042..03fdf23 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);