common: Get system user from GumdRunner 05/323605/8
authorZofia Abramowska <z.abramowska@samsung.com>
Tue, 15 Apr 2025 11:46:50 +0000 (13:46 +0200)
committerZofia Abramowska <z.abramowska@samsung.com>
Tue, 13 May 2025 09:11:29 +0000 (09:11 +0000)
* rename TempTestUser to TestUser
* add getSystemUser to TestUser
* fetch owner user using TestUser instead of
  hardcoding owner uid in test cases.

Change-Id: I6246f6b80e657d64bab64c4073eb774dbb700c49

28 files changed:
src/common/CMakeLists.txt
src/common/scoped_app_launcher.cpp
src/common/scoped_app_launcher.h
src/common/scoped_installer.h
src/common/sm_commons.cpp
src/common/sm_commons.h
src/common/temp_test_user.cpp [deleted file]
src/common/temp_test_user.h [deleted file]
src/common/test_user.cpp [new file with mode: 0644]
src/common/test_user.h [new file with mode: 0644]
src/common/tzplatform.cpp
src/common/tzplatform.h
src/nether-tests/nether_tests.cpp
src/ode/ode-tests-internal-encryption.cpp
src/ode/ode-tests-keys.cpp
src/security-manager-tests/test_cases.cpp
src/security-manager-tests/test_cases_app_defined_privilege.cpp
src/security-manager-tests/test_cases_app_policy.cpp
src/security-manager-tests/test_cases_dyntransition.cpp
src/security-manager-tests/test_cases_nss.cpp
src/security-manager-tests/test_cases_paths.cpp
src/security-manager-tests/test_cases_permissible_file_repair.cpp
src/security-manager-tests/test_cases_prepare_app.cpp
src/security-manager-tests/test_cases_privacy_manager.cpp
src/security-manager-tests/test_cases_public_sharing.cpp
src/security-manager-tests/test_cases_register_paths.cpp
src/security-manager-tests/test_cases_smack_privileges.cpp
src/security-manager-tests/test_cases_trusted_sharing.cpp

index f4ba8b655039bfd183b53e46b896b63bcb7591b1..08de67285652fc7177b0936348db22af546fea71 100644 (file)
@@ -37,7 +37,7 @@ SET(COMMON_TARGET_TEST_SOURCES
     ${PROJECT_SOURCE_DIR}/src/common/message_pipe.cpp
     ${PROJECT_SOURCE_DIR}/src/common/synchronization_pipe.cpp
     ${PROJECT_SOURCE_DIR}/src/common/timeout.cpp
-    ${PROJECT_SOURCE_DIR}/src/common/temp_test_user.cpp
+    ${PROJECT_SOURCE_DIR}/src/common/test_user.cpp
     ${PROJECT_SOURCE_DIR}/src/common/cynara_helpers_creds.cpp
     ${PROJECT_SOURCE_DIR}/src/common/label_generator.cpp
     ${PROJECT_SOURCE_DIR}/src/common/app_install_helper.cpp
index 1f53fc40ba386523563c0cf0204ca21e04941d3b..d372c6acb2807d127a3c844f4daaf206349f64e0 100644 (file)
@@ -31,7 +31,7 @@ ScopedAppLauncher::ScopedAppLauncher(const AppInstallHelper& app,
     launch(runInAppContext);
 }
 
-ScopedAppLauncher::ScopedAppLauncher(const AppInstallHelper &app, const TemporaryTestUser &user,
+ScopedAppLauncher::ScopedAppLauncher(const AppInstallHelper &app, const TestUser &user,
                                      const std::function<void(void)> &runInAppContext)
 
     : m_uid(user.getUid()),
index 970fedff457e465d7607e503a4a5bb1610a6ae99..2ba5e1699f23908086650fc40733b116a1cbebea 100644 (file)
 
 #include <app_install_helper.h>
 #include <synchronization_pipe.h>
-#include <temp_test_user.h>
+#include <test_user.h>
 
 class ScopedAppLauncher final {
 public:
     explicit ScopedAppLauncher(const AppInstallHelper& app,
                                const std::function<void(void)>& runInAppContext = []{});
-    ScopedAppLauncher(const AppInstallHelper& app, const TemporaryTestUser& user,
+    ScopedAppLauncher(const AppInstallHelper& app, const TestUser& user,
                       const std::function<void(void)>& runInAppContext = []{});
     ~ScopedAppLauncher();
 
index 2eafe2522e00a553de32bd55e6e1e748c9771ec1..3ff203b0b65ddcea8995fdc58e77e60b16a0fc50 100644 (file)
@@ -29,7 +29,7 @@
 #include <memory.h>
 #include <sm_request.h>
 #include <sm_api.h>
-#include <temp_test_user.h>
+#include <test_user.h>
 #include <synchronization_pipe.h>
 #include <dpl/test/safe_cleanup.h>
 
index 3fceea9e43cc471368ea8bda4d39d924ef5fdda7..9a58320eb2ac77e624a026fa8025b394c4494772 100644 (file)
 
 #include <dpl/test/test_runner.h>
 #include <memory.h>
+#include <scoped_app_launcher.h>
 #include <sm_api.h>
 #include <sm_commons.h>
 
 #include <tests_common.h>
 #include "tzplatform.h"
-#include <temp_test_user.h>
+#include <test_user.h>
 
 #include "dac.h"
 
@@ -213,6 +214,11 @@ void runAccessTest(const AppInstallHelper &app, const std::string &testPath, int
     Api::cleanupApp(app.getAppId(), app.getUID(), pid);
 }
 
+void runAccessTest(const AppInstallHelper &app, const TestUser &user,
+                   const std::string &testPath, int accessType) {
+    ScopedAppLauncher(app, user, [&] { accessTest(app.getAppId(), testPath, accessType);});
+}
+
 void runAccessTest(const AppInstallHelper &app, const std::string &testPath,
                    uid_t uid, gid_t gid, int accessType) {
     auto fun = [&](){
@@ -284,7 +290,7 @@ int setLauncherSecurityAttributes(uid_t uid, gid_t gid)
 
     return ret;
 }
-int setLauncherSecurityAttributes(TemporaryTestUser &user)
+int setLauncherSecurityAttributes(TestUser &user)
 {
     return setLauncherSecurityAttributes(user.getUid(), user.getGid());
 }
index c06a8040c9a299bea6a86b45c2b88fc1d6138ed3..8c9a97d7a82bd4baefbe4b50877361b4959a654a 100644 (file)
@@ -25,7 +25,7 @@
 
 #include <app_install_helper.h>
 #include <memory.h>
-#include <temp_test_user.h>
+#include <test_user.h>
 
 DEFINE_SMARTPTR(cap_free, _cap_struct, CapsSetsUniquePtr);
 
@@ -44,6 +44,8 @@ void runAccessTest(const std::string &label, uid_t uid, gid_t gid,
 void runAccessTest(const AppInstallHelper &app, const std::string &testPath, int accessType);
 void runAccessTest(const AppInstallHelper &app, const std::string &testPath,
                    uid_t uid, gid_t gid, int accessType);
+void runAccessTest(const AppInstallHelper &app, const TestUser &user, const std::string &testPath,
+                   int accessType);
 void runSystemAccessTest(uid_t uid, gid_t gid, const std::string &testPath, int accessType);
 
 bool isAskuserDisabled();
@@ -52,4 +54,4 @@ int countPrivacyPrivileges(const PrivilegeVector &privs);
 int countPrivacyPrivileges(const std::vector<std::string> &privs);
 
 int setLauncherSecurityAttributes(uid_t uid, gid_t gid);
-int setLauncherSecurityAttributes(TemporaryTestUser &user);
+int setLauncherSecurityAttributes(TestUser &user);
diff --git a/src/common/temp_test_user.cpp b/src/common/temp_test_user.cpp
deleted file mode 100644 (file)
index a1343f9..0000000
+++ /dev/null
@@ -1,241 +0,0 @@
-/*
- * Copyright (c) 2015-2016 Samsung Electronics Co., Ltd All Rights Reserved
- *
- *    Licensed under the Apache License, Version 2.0 (the "License");
- *    you may not use this file except in compliance with the License.
- *    You may obtain a copy of the License at
- *
- *        http://www.apache.org/licenses/LICENSE-2.0
- *
- *    Unless required by applicable law or agreed to in writing, software
- *    distributed under the License is distributed on an "AS IS" BASIS,
- *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *    See the License for the specific language governing permissions and
- *    limitations under the License.
-*/
-
-/*
- * @file        temp_test_user.cpp
- * @author      Jan Cybulski (j.cybulski@partner.samsung.com)
- * @author      Rafal Krypa (j.cybulski@samsung.com)
- * @version     1.0
- * @brief       File with class for users management
- */
-
-
-#include <exception>
-#include <memory.h>
-#include <tests_common.h>
-#include <temp_test_user.h>
-#include <glib-object.h>
-#include <dpl/test/test_runner.h>
-#include <unistd.h>
-#include <signal.h>
-#include <sys/prctl.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-
-TemporaryTestUser::TemporaryTestUser(TemporaryTestUser &&other)
-    : m_uid(other.m_uid), m_gid(other.m_gid), m_userName(std::move(other.m_userName)),
-      m_userType(other.m_userType), m_offline(other.m_offline), m_creatorPid(other.m_creatorPid)
-{
-    other.m_creatorPid = -1;
-}
-
-void TemporaryTestUser::create(void)
-{
-    if (m_uid != 0)
-        remove();
-
-/*
-    Below line of code is a hack for Gumd commit that removes Smack management capabilities:
-
-    | commit 9b45c1afa49103dcb4101f4b28bf7c145f3294a6
-    |/  Author: Yunmi Ha <yunmi.ha@samsung.com>
-    |   Date:   Tue Jul 5 13:40:16 2016 +0900
-    |
-    |       Remove smack capability
-    |
-    |       with wearable profile, CAP_MAC_ADMIN and CAP_MAC_OVERRIDE capabilities are removed.
-    |       (can't use useradd/del/modify function without offline option.)
-    |       with other profile, only CAP_MAC_OVERRIDE capability is removed.
-    |
-    |       For this, gumd launcher was changed to systemd.
-    |
-    |       Change-Id: Ic95fceed41afc41e37e93606c3abf830536ac7d6
-    |       Signed-off-by: Yunmi Ha <yunmi.ha@samsung.com>
-*/
-    m_offline = true;
-
-    bool ret = m_runner.userCreate(m_userName, m_userType, m_offline, m_uid, m_gid);
-    RUNNER_ASSERT_MSG(ret, "Failed to add user");
-    RUNNER_ASSERT_MSG(m_uid != 0, "Something strange happened during user creation. uid == 0.");
-    RUNNER_ASSERT_MSG(m_gid != 0, "Something strange happened during user creation. gid == 0.");
-}
-
-void TemporaryTestUser::remove(void)
-{
-    if (m_uid == 0)
-        return;
-
-    m_runner.userRemove(m_uid, m_offline);
-    m_uid = m_gid = 0;
-}
-
-TemporaryTestUser::~TemporaryTestUser()
-{
-    if (m_creatorPid == getpid())
-        remove();
-}
-
-TemporaryTestUser::GumdRunner TemporaryTestUser::m_runner = TemporaryTestUser::GumdRunner();
-
-TemporaryTestUser::GumdRunner::GumdRunner()
-{
-    int sock[2];
-    int ret = socketpair(AF_UNIX, SOCK_STREAM, 0, sock);
-    RUNNER_ASSERT_MSG(ret != -1, "socketpair() failed");
-
-    pid_t parent_pid = getpid();
-    pid_t pid = fork();
-    RUNNER_ASSERT_MSG(pid != -1, "fork() failed");
-    if (pid) { // parent
-        m_sock = sock[0];
-        close(sock[1]);
-        return;
-    } else { // child
-        m_sock = sock[1];
-        close(sock[0]);
-        prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); // Don't outlive parent process
-        // If the parent died before prctl(), we won't be SIGKILLed
-        if (parent_pid != getppid())
-            std::terminate();
-        run(); // Never returns
-    }
-}
-
-TemporaryTestUser::GumdRunner::~GumdRunner()
-{
-    close(m_sock);
-}
-
-bool TemporaryTestUser::GumdRunner::userCreate(std::string userName,
-    GumUserType userType, bool offline, uid_t &uid, gid_t &gid)
-{
-    put(static_cast<int>(opType::USER_CREATE));
-    put(userName.size());
-    put(userName.c_str(), userName.size());
-    put(userType);
-    put(offline);
-
-    bool ret = get<bool>();
-    if (ret) {
-        uid = get<uid_t>();
-        gid = get<gid_t>();
-    }
-    return ret;
-}
-
-bool TemporaryTestUser::GumdRunner::userRemove(uid_t uid, bool offline)
-{
-    put(static_cast<int>(opType::USER_REMOVE));
-    put(uid);
-    put(offline);
-    return get<bool>();
-}
-
-
-void TemporaryTestUser::GumdRunner::run()
-{
-    DEFINE_SMARTPTR(g_object_unref, GumUser, GumUserPtr);
-
-    while (true) {
-        switch(static_cast<opType>(get<int>())) {
-        case opType::USER_CREATE:
-            {
-                size_t userNameLen = get<size_t>();
-                std::unique_ptr<char[]> userNamePtr(new char[userNameLen + 1]);
-                get(userNamePtr.get(), userNameLen);
-                userNamePtr[userNameLen] = '\0';
-                GumUserType userType = get<GumUserType>();
-                bool offline = get<bool>();
-
-                bool result = false;
-                uid_t uid;
-                gid_t gid;
-
-                GumUserPtr userPtr(gum_user_create_sync(offline));
-                if (userPtr) {
-                    g_object_set(G_OBJECT(userPtr.get()),
-                        "username", userNamePtr.get(),
-                        "usertype", userType,
-                        nullptr);
-                    gboolean ret = gum_user_add_sync(userPtr.get());
-                    if (ret == TRUE) {
-                        g_object_get(G_OBJECT(userPtr.get()), "uid", &uid, nullptr);
-                        g_object_get(G_OBJECT(userPtr.get()), "gid", &gid, nullptr);
-                        result = true;
-                    }
-                }
-
-                put(result);
-                if (result) {
-                    put(uid);
-                    put(gid);
-                }
-            }
-            break;
-
-        case opType::USER_REMOVE:
-            {
-                uid_t uid = get<uid_t>();
-                bool offline = get<bool>();
-                bool result = false;
-
-                GumUserPtr userPtr(gum_user_get_sync(uid, offline));
-                if (userPtr) {
-                    gboolean ret = gum_user_delete_sync(userPtr.get(), TRUE);
-                    result = (ret == TRUE);
-                }
-                put(static_cast<bool>(result));
-            }
-            break;
-        }
-    }
-}
-
-void TemporaryTestUser::GumdRunner::get(void *buf, size_t cnt)
-{
-    int ret;
-    for (size_t pos = 0; pos < cnt; pos += ret) {
-        ret = TEMP_FAILURE_RETRY(
-            read(m_sock, static_cast<char *>(buf) + pos, cnt - pos));
-        RUNNER_ASSERT_MSG(ret != -1, "read() failed");
-        RUNNER_ASSERT_MSG(ret > 0, "expected " << cnt << " bytes, but read only " << pos
-                                   << " and the socket closed");
-    }
-}
-
-void TemporaryTestUser::GumdRunner::put(const void *buf, size_t cnt)
-{
-    int ret;
-    for (size_t pos = 0; pos < cnt; pos += ret) {
-        ret = TEMP_FAILURE_RETRY(
-            write(m_sock, static_cast<const char *>(buf) + pos, cnt - pos));
-        RUNNER_ASSERT_MSG(ret != -1, "write() failed");
-    }
-}
-
-template<typename T>
-T TemporaryTestUser::GumdRunner::get()
-{
-    T x;
-    get(&x, sizeof(x));
-    return std::move(x);
-}
-
-template<typename T>
-void TemporaryTestUser::GumdRunner::put(const T x)
-{
-    put(&x, sizeof(x));
-}
diff --git a/src/common/temp_test_user.h b/src/common/temp_test_user.h
deleted file mode 100644 (file)
index 291d506..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright (c) 2015-2016 Samsung Electronics Co., Ltd All Rights Reserved
- *
- *    Licensed under the Apache License, Version 2.0 (the "License");
- *    you may not use this file except in compliance with the License.
- *    You may obtain a copy of the License at
- *
- *        http://www.apache.org/licenses/LICENSE-2.0
- *
- *    Unless required by applicable law or agreed to in writing, software
- *    distributed under the License is distributed on an "AS IS" BASIS,
- *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *    See the License for the specific language governing permissions and
- *    limitations under the License.
-*/
-
-#ifndef TEMP_TEST_USER_H
-#define TEMP_TEST_USER_H
-
-#include <string>
-#include <sys/types.h>
-#include <gum-user.h>
-#include <common/gum-user-types.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-class TemporaryTestUser {
-public:
-    TemporaryTestUser(std::string userName, GumUserType userType, bool offline = false) :
-            m_uid(0),
-            m_gid(0),
-            m_userName(userName),
-            m_userType(userType),
-            m_offline(offline),
-            m_creatorPid(getpid())
-            {};
-    TemporaryTestUser(const TemporaryTestUser &) = delete;
-    TemporaryTestUser(TemporaryTestUser &&other);
-    TemporaryTestUser& operator=(const TemporaryTestUser &) = delete;
-    ~TemporaryTestUser();
-    void remove(void);
-    uid_t getUid() const {return m_uid;}
-    uid_t getGid() const {return m_gid;}
-    void create(void);
-    std::string getUidString() const {return std::to_string(static_cast<unsigned int>(m_uid));}
-    const std::string& getUserName() const {return m_userName;}
-    GumUserType getUserType() const {return m_userType;}
-
-private:
-    class GumdRunner {
-    public:
-        GumdRunner();
-        ~GumdRunner();
-        bool userCreate(std::string userName, GumUserType userType, bool offline,
-            uid_t &uid, gid_t &gid);
-        bool userRemove(uid_t uid, bool offline);
-
-    private:
-        enum class opType {USER_CREATE, USER_REMOVE};
-        int m_sock;
-
-        void run();
-        void get(void *buf, size_t count);
-        void put(const void *buf, size_t count);
-        template<typename T> T get();
-        template<typename T> void put(const T x);
-    };
-
-    static GumdRunner m_runner;
-    uid_t m_uid;
-    uid_t m_gid;
-    std::string m_userName;
-    GumUserType m_userType;
-    bool m_offline;
-    pid_t m_creatorPid;
-};
-
-#endif
diff --git a/src/common/test_user.cpp b/src/common/test_user.cpp
new file mode 100644 (file)
index 0000000..c646bb3
--- /dev/null
@@ -0,0 +1,514 @@
+/*
+ * Copyright (c) 2015-2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+*/
+
+/*
+ * @file        test_user.cpp
+ * @author      Jan Cybulski (j.cybulski@partner.samsung.com)
+ * @author      Rafal Krypa (j.cybulski@samsung.com)
+ * @version     1.0
+ * @brief       File with class for users management
+ */
+
+
+#include <exception>
+#include <iostream>
+#include <string_view>
+#include <memory.h>
+#include <tests_common.h>
+#include <test_user.h>
+#include <glib-object.h>
+#include <glib.h>
+#include <dpl/test/test_runner.h>
+#include <unistd.h>
+#include <signal.h>
+#include <sys/prctl.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <gum-user-service.h>
+#include <unordered_set>
+#include <unordered_map>
+
+namespace {
+
+constexpr uid_t OWNER_UID = 5001;
+
+const static std::unordered_set<std::string_view> SYSTEM_USER_NAMES = {
+    "owner",
+};
+
+const static std::unordered_map<SystemUser, uid_t> SYSTEM_USER_IDS = {
+    {SystemUser::OWNER, OWNER_UID}
+};
+
+bool isSystemUser(const std::string_view &userName) {
+    return SYSTEM_USER_NAMES.find(userName) != SYSTEM_USER_NAMES.end();
+}
+
+uid_t systemUserId(SystemUser user) {
+    return SYSTEM_USER_IDS.at(user);
+}
+
+#define FAIL_IF(cond, message) \
+    do                                                                                \
+    {                                                                                 \
+        if (!(cond))                                                                  \
+        {                                                                             \
+            std::cerr << "Failed: " #cond " : " << message << std::endl;              \
+            exit(1);                                                                  \
+        }                                                                             \
+    } while (0)
+
+class GumdRunner {
+public:
+    GumdRunner()
+    {
+        int sock[2];
+        int ret = socketpair(AF_UNIX, SOCK_STREAM, 0, sock);
+        FAIL_IF(ret != -1, "socketpair() failed");
+
+        pid_t parent_pid = getpid();
+        pid_t pid = fork();
+        FAIL_IF(pid != -1, "fork() failed");
+        if (pid) { // parent
+            m_sock = sock[0];
+            close(sock[1]);
+            return;
+        } else { // child
+            m_sock = sock[1];
+            close(sock[0]);
+            prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); // Don't outlive parent process
+            // If the parent died before prctl(), we won't be SIGKILLed
+            if (parent_pid != getppid())
+                std::terminate();
+            try {
+                run(); // Never returns
+            } catch (...) {
+                FAIL_IF(true, "Run process failed");
+            }
+        }
+    }
+
+    ~GumdRunner()
+    {
+        close(m_sock);
+    }
+
+    bool userExists(const std::string_view &userName, bool offline, bool &exists){
+        put(opType::USER_EXISTS);
+        put(userName);
+        put(offline);
+
+        auto ret = get<bool>();
+        if (ret) {
+            exists = get<bool>();
+        }
+
+        return ret;
+    }
+
+    bool userGet(uid_t uid, bool offline, gid_t &gid,
+                 std::string &userName, GumUserType &userType)
+    {
+        put(opType::USER_GET);
+        put(uid);
+        put(offline);
+
+        auto ret = get<bool>();
+        if (ret) {
+            gid = get<gid_t>();
+            userName = get<std::string>();
+            userType = get<GumUserType>();
+        }
+
+        return ret;
+    }
+
+    bool userGetByName(const std::string_view &userName, bool offline,
+                       uid_t &uid, gid_t &gid, GumUserType &userType)
+    {
+        put(static_cast<int>(opType::USER_GET_BY_NAME));
+        put(userName);
+        put(offline);
+
+        auto ret = get<bool>();
+        if (ret) {
+            uid = get<uid_t>();
+            gid = get<gid_t>();
+            userType = get<GumUserType>();
+        }
+
+        return ret;
+    }
+
+    bool userCreate(const std::string_view &userName, GumUserType userType, bool offline,
+                    uid_t &uid, gid_t &gid)
+    {
+        put(opType::USER_CREATE);
+        put(userName);
+        put(userType);
+        put(offline);
+
+        auto ret = get<bool>();
+        if (ret) {
+            uid = get<uid_t>();
+            gid = get<gid_t>();
+        }
+        return ret;
+    }
+
+    bool userRemove(uid_t uid, bool offline)
+    {
+        put(opType::USER_REMOVE);
+        put(uid);
+        put(offline);
+        return get<bool>();
+    }
+
+private:
+    enum class opType {USER_EXISTS, USER_GET, USER_GET_BY_NAME, USER_CREATE, USER_REMOVE};
+    int m_sock;
+
+    [[noreturn]]
+    void run()
+    {
+        DEFINE_SMARTPTR(g_object_unref, GumUser, GumUserPtr);
+        DEFINE_SMARTPTR(g_object_unref, GumUserService, GumUserServicePtr);
+        DEFINE_SMARTPTR(gum_user_service_list_free, GumUserList, GumUserListPtr);
+
+        while (true) {
+            switch(get<opType>()) {
+            case opType::USER_EXISTS:
+            {
+                auto userName = get<std::string>();
+                auto offline = get<bool>();
+
+                bool result = false;
+                bool exists = false;
+
+                GumUserServicePtr servicePtr(gum_user_service_create_sync(offline));
+                if (!servicePtr) {
+                    put(result);
+                    break;
+                }
+                const gchar *const types[] = {"normal", "admin", nullptr};
+                GumUserListPtr userList(
+                    gum_user_service_get_user_list_sync(servicePtr.get(), types));
+
+                if (!userList) {
+                    put(result);
+                    break;
+                }
+
+                GList *last = userList.get();
+                result = true;
+                for (; last != NULL; last = last->next) {
+                    GumUser *user = static_cast<GumUser *>(last->data);
+                    gchar *exUserName;
+                    g_object_get(G_OBJECT(user), "username", &exUserName, nullptr);
+
+                    if (userName == exUserName) {
+                        exists = true;
+                        break;
+                    }
+                }
+
+                put(result);
+                put(exists);
+            }
+            break;
+            case opType::USER_GET:
+            {
+                auto uid = get<uid_t>();
+                auto offline = get<bool>();
+
+                bool result = false;
+                gid_t gid;
+                gchar *username;
+                GumUserType userType;
+
+                GumUserPtr userPtr(gum_user_get_sync(uid, offline));
+                if (userPtr) {
+                    g_object_get(G_OBJECT(userPtr.get()), "gid", &gid, nullptr);
+                    g_object_get(G_OBJECT(userPtr.get()), "username", &username, nullptr);
+                    g_object_get(G_OBJECT(userPtr.get()), "usertype", &userType, nullptr);
+                    result = true;
+                }
+
+                put(result);
+                if (result) {
+                    put(gid);
+                    put(username);
+                    put(userType);
+                }
+            }
+            break;
+
+            case opType::USER_GET_BY_NAME:
+            {
+                auto userName = get<std::string>();
+                auto offline = get<bool>();
+
+                bool result = false;
+                uid_t uid;
+                gid_t gid;
+                GumUserType userType;
+
+                GumUserPtr userPtr(gum_user_get_by_name_sync(userName.c_str(), offline));
+                if (userPtr) {
+                    g_object_get(G_OBJECT(userPtr.get()), "uid", &uid, nullptr);
+                    g_object_get(G_OBJECT(userPtr.get()), "gid", &gid, nullptr);
+                    g_object_get(G_OBJECT(userPtr.get()), "usertype", &userType, nullptr);
+                    result = true;
+                }
+
+                put(result);
+                if (result) {
+                    put(uid);
+                    put(gid);
+                    put(userType);
+                }
+            }
+            break;
+
+            case opType::USER_CREATE:
+            {
+                auto userName = get<std::string>();
+                auto userType = get<GumUserType>();
+                auto offline = get<bool>();
+
+                bool result = false;
+                uid_t uid;
+                gid_t gid;
+
+                GumUserPtr userPtr(gum_user_create_sync(offline));
+                if (userPtr) {
+                    g_object_set(G_OBJECT(userPtr.get()),
+                                 "username", userName.c_str(),
+                                 "usertype", userType,
+                                 nullptr);
+                    gboolean ret = gum_user_add_sync(userPtr.get());
+                    if (ret == TRUE) {
+                        g_object_get(G_OBJECT(userPtr.get()), "uid", &uid, nullptr);
+                        g_object_get(G_OBJECT(userPtr.get()), "gid", &gid, nullptr);
+                        result = true;
+                    }
+                }
+
+                put(result);
+                if (result) {
+                    put(uid);
+                    put(gid);
+                }
+            }
+            break;
+
+            case opType::USER_REMOVE:
+            {
+                auto uid = get<uid_t>();
+                auto offline = get<bool>();
+
+                auto result = false;
+
+                GumUserPtr userPtr(gum_user_get_sync(uid, offline));
+                if (userPtr) {
+                    gboolean ret = gum_user_delete_sync(userPtr.get(), TRUE);
+                    result = (ret == TRUE);
+                }
+                put(result);
+            }
+            break;
+            }
+        }
+    }
+
+    void get(void *buf, size_t cnt)
+    {
+        int ret;
+        for (size_t pos = 0; pos < cnt; pos += ret) {
+            ret = TEMP_FAILURE_RETRY(
+                read(m_sock, static_cast<char *>(buf) + pos, cnt - pos));
+            RUNNER_ASSERT_MSG(ret != -1, "read() failed");
+            RUNNER_ASSERT_MSG(ret > 0, "expected " << cnt << " bytes, but read only " << pos
+                              << " and the socket closed");
+        }
+    }
+
+    void put(const void *buf, size_t cnt)
+    {
+        int ret;
+        for (size_t pos = 0; pos < cnt; pos += ret) {
+            ret = TEMP_FAILURE_RETRY(
+                write(m_sock, static_cast<const char *>(buf) + pos, cnt - pos));
+            RUNNER_ASSERT_MSG(ret != -1, "write() failed");
+        }
+    }
+
+    template<typename T,
+             typename std::enable_if_t<std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>,
+                                       int> = 0>
+    T get()
+    {
+        T x;
+        get(&x, sizeof(x));
+        return std::move(x);
+    }
+
+    template<typename T,
+             typename std::enable_if_t<std::is_same_v<T, std::string>, int> = 0>
+    T get()
+    {
+        auto len = get<size_t>();
+
+        std::string str(len, '\0');
+        get(str.data(), len);
+
+        return str;
+    }
+
+    void put(const std::string_view &str)
+    {
+        put(static_cast<size_t>(str.size()));
+        put(str.data(), str.size());
+    }
+
+    template<typename T,
+             typename std::enable_if_t<std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>,
+                                       int> = 0>
+    void put(const T& x)
+    {
+        put(&x, sizeof(x));
+    }
+};
+
+__attribute__((constructor))
+GumdRunner& getGumdRunner() {
+    static auto runner = GumdRunner{};
+    return runner;
+}
+
+}
+
+TestUser::TestUser(TestUser &&other)
+    : m_uid(other.m_uid), m_gid(other.m_gid), m_userName(std::move(other.m_userName)),
+      m_userType(other.m_userType), m_offline(other.m_offline), m_creatorPid(other.m_creatorPid),
+      m_created(other.m_created)
+{
+    other.m_creatorPid = -1;
+    other.m_created = false;
+}
+
+TestUser& TestUser::operator=(TestUser &&other) {
+    if (this == &other) {
+        return *this;
+    }
+
+    m_uid = other.m_uid;
+    m_gid = other.m_gid;
+    m_userName = std::move(other.m_userName);
+    m_userType = other.m_userType;
+    m_offline = other.m_offline;
+    m_creatorPid = other.m_creatorPid;
+    other.m_creatorPid = -1;
+    m_created = other.m_created;
+    other.m_created = false;
+
+    return *this;
+}
+
+TestUser TestUser::createTemporary(const std::string_view& userName, GumUserType userType, bool offline)
+{
+    RUNNER_ASSERT_MSG(!isSystemUser(userName), "Cannot create a system user " << userName);
+
+    bool exists = false;
+    RUNNER_ASSERT_MSG(getGumdRunner().userExists(userName, offline, exists),
+                      "Failed to check if user " << userName << " exists");
+    if (exists) {
+        uid_t uid;
+        gid_t gid;
+        GumUserType userType;
+        RUNNER_ASSERT_MSG(getGumdRunner().userGetByName(userName, offline, uid, gid, userType),
+                          "Failed to get user " << userName);
+        getGumdRunner().userRemove(uid, offline);
+    }
+
+/*
+    Below line of code is a hack for Gumd commit that removes Smack management capabilities:
+
+    | commit 9b45c1afa49103dcb4101f4b28bf7c145f3294a6
+    |/  Author: Yunmi Ha <yunmi.ha@samsung.com>
+    |   Date:   Tue Jul 5 13:40:16 2016 +0900
+    |
+    |       Remove smack capability
+    |
+    |       with wearable profile, CAP_MAC_ADMIN and CAP_MAC_OVERRIDE capabilities are removed.
+    |       (can't use useradd/del/modify function without offline option.)
+    |       with other profile, only CAP_MAC_OVERRIDE capability is removed.
+    |
+    |       For this, gumd launcher was changed to systemd.
+    |
+    |       Change-Id: Ic95fceed41afc41e37e93606c3abf830536ac7d6
+    |       Signed-off-by: Yunmi Ha <yunmi.ha@samsung.com>
+*/
+    offline = true;
+    uid_t uid;
+    gid_t gid;
+
+    bool ret = getGumdRunner().userCreate(userName, userType, offline, uid, gid);
+    RUNNER_ASSERT_MSG(ret, "Failed to add user");
+    RUNNER_ASSERT_MSG(uid != 0, "Something strange happened during user creation. uid == 0.");
+    RUNNER_ASSERT_MSG(gid != 0, "Something strange happened during user creation. gid == 0.");
+
+    return TestUser(uid, gid, userName, userType, true, offline);
+}
+
+void TestUser::remove(void)
+{
+    if (!m_created)
+        return;
+
+    getGumdRunner().userRemove(m_uid, m_offline);
+    m_created = false;
+}
+
+const TestUser& TestUser::getSystemUser(SystemUser systemUser, bool offline)
+{
+    static std::map<uid_t, TestUser> systemUsers;
+    uid_t uid = systemUserId(systemUser);
+
+    auto it = systemUsers.find(uid);
+    if (it != systemUsers.end()) {
+        return it->second;
+    }
+
+    gid_t gid;
+    std::string userName;
+    GumUserType userType;
+
+    bool ret = getGumdRunner().userGet(uid, offline, gid, userName, userType);
+
+    RUNNER_ASSERT_MSG(ret, "Failed to get user with uid=" << uid);
+
+    TestUser user(uid, gid, userName, userType, false, offline);
+
+    // oh, how I love std::pair
+    return systemUsers.try_emplace(uid, std::move(user)).first->second;
+}
+
+TestUser::~TestUser()
+{
+    if (m_creatorPid == getpid())
+        remove();
+}
diff --git a/src/common/test_user.h b/src/common/test_user.h
new file mode 100644 (file)
index 0000000..a5a123a
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2015-2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+*/
+
+#ifndef TEST_USER_H
+#define TEST_USER_H
+
+#include <cstring>
+#include <string>
+#include <string_view>
+#include <sys/types.h>
+#include <gum-user.h>
+#include <common/gum-user-types.h>
+#include <sys/types.h>
+#include <type_traits>
+#include <unistd.h>
+#include <map>
+#include <vector>
+
+enum class SystemUser {OWNER};
+
+class TestUser {
+public:
+    static TestUser createTemporary(const std::string_view &userName,
+                                    GumUserType userType, bool offline = false);
+    static const TestUser& getSystemUser(SystemUser user, bool offline = false);
+
+    TestUser(TestUser &&);
+    TestUser& operator=(TestUser &&);
+    TestUser(const TestUser &) = delete;
+    TestUser& operator=(const TestUser &) = delete;
+
+    ~TestUser();
+
+    void remove(void);
+    uid_t getUid() const { return m_uid; }
+    gid_t getGid() const { return m_gid; }
+
+    std::string getUidString() const { return std::to_string(m_uid); }
+    const std::string& getUserName() const { return m_userName; }
+    GumUserType getUserType() const { return m_userType; }
+
+private:
+    TestUser(uid_t uid, gid_t gid, const std::string_view &userName,
+             GumUserType userType, bool isCreated, bool offline)
+        : m_uid(uid),
+          m_gid(gid),
+          m_userName(userName),
+          m_userType(userType),
+          m_offline(offline),
+          m_creatorPid(getpid()),
+          m_created(isCreated)
+    {}
+
+    uid_t m_uid;
+    gid_t m_gid;
+    std::string m_userName;
+    GumUserType m_userType;
+    bool m_offline;
+    pid_t m_creatorPid;
+    bool m_created;
+};
+
+#endif
index 92e5535ec155de4d18abb5c930848281658efffc..b2b11163f112ab57c4f9c9e2fd5aa52e74540a8d 100644 (file)
@@ -19,7 +19,7 @@
 
 #include <dpl/test/test_runner.h>
 #include <memory.h>
-#include <temp_test_user.h>
+#include <test_user.h>
 #include <tzplatform.h>
 
 namespace TzPlatformConfig {
@@ -47,7 +47,7 @@ uid_t getGlobalGroupId(void)
     return pw->pw_gid;
 }
 
-const std::string appDirPath(const TemporaryTestUser &user, const std::string &appId,
+const std::string appDirPath(const TestUser &user, const std::string &appId,
                              const std::string &pkgId)
 {
     return appDirPath(user.getUid()) + pkgId + "/" + appId;
index 0182ba0d4e1eeea18f6e7f05b4a94eebcb163138..c30ca2fc7d91bb7968e07c791aa656efe09cb282 100644 (file)
@@ -20,7 +20,7 @@
 
 #include <tzplatform_config.h>
 
-#include <temp_test_user.h>
+#include <test_user.h>
 
 namespace TzPlatformConfig {
 
@@ -32,7 +32,7 @@ uid_t getGlobalUserId(void);
 
 uid_t getGlobalGroupId(void);
 
-const std::string appDirPath(const TemporaryTestUser &user, const std::string &appId,
+const std::string appDirPath(const TestUser &user, const std::string &appId,
                              const std::string &pkgId);
 
 const std::string appDirPath(uid_t uid);
index 95c066c716b74887c869f4fab6f0ce0411214d2a..4f814c74e7615b593745452dc4d7a2af6890c93d 100644 (file)
@@ -44,6 +44,7 @@
 #include <scoped_installer.h>
 #include <sm_commons.h>
 #include <tests_common.h>
+#include <test_user.h>
 #include <dpl/test/safe_cleanup.h>
 
 
@@ -193,10 +194,8 @@ class TemporaryNormalTestUser
 {
 public:
     TemporaryNormalTestUser(const std::string &userName)
-    : m_user(userName, GUM_USERTYPE_NORMAL, false)
-    {
-        m_user.create();
-    }
+        : m_user(TestUser::createTemporary(userName, GUM_USERTYPE_NORMAL, false))
+    {}
 
     uid_t getUid() const
     {
@@ -204,7 +203,7 @@ public:
     }
 
 private:
-    TemporaryTestUser m_user;
+    TestUser m_user;
 };
 
 
index 44cc4c23e22d068e5cd5ce7567612abf37291402..01530aec223e2398d580fbbd6a354650b9417779 100644 (file)
@@ -24,7 +24,7 @@
 #include <dpl/test/test_runner.h>
 #include <dpl/test/test_runner_child.h>
 #include <dpl/log/log.h>
-#include <temp_test_user.h>
+#include <test_user.h>
 #include <app_install_helper.h>
 #include <tests_common.h>
 #include <scoped_installer.h>
@@ -262,8 +262,9 @@ RUNNER_CHILD_TEST(T1021_internal_encryption_permission_denied)
                        "instead of the ODE_ERROR_PERMISSION_DENIED. "
                        "Needs improvement in ode module.");
 
-    TemporaryTestUser adminUserToSwitch("ode_test_T1021_user", GUM_USERTYPE_ADMIN);
-    adminUserToSwitch.create();
+    TestUser adminUserToSwitch =
+        TestUser::createTemporary("ode_test_T1021_user", GUM_USERTYPE_ADMIN);
+
 
     AppInstallHelper appInstallHelper("ode_test_T1021_app_install_helper",
         adminUserToSwitch.getUid());
index c4cec68b5e884cf7a27ce4b24db1572f88ee9c18..3d59a1f625b510846a946753541ecffea4078e06 100644 (file)
@@ -22,7 +22,7 @@
 
 #include <dpl/test/test_runner.h>
 #include <dpl/test/test_runner_child.h>
-#include <temp_test_user.h>
+#include <test_user.h>
 #include <app_install_helper.h>
 #include <tests_common.h>
 #include <scoped_installer.h>
@@ -316,8 +316,8 @@ RUNNER_CHILD_TEST(T2017_ode_keys_permission_denied)
     RUNNER_IGNORED_MSG("Test ignored because the ODE_ERROR_UNKNOWN is returned "
                        "instead of the ODE_ERROR_PERMISSION_DENIED.");
 
-    TemporaryTestUser adminUserToSwitch("ode_test_T2016_user", GUM_USERTYPE_ADMIN);
-    adminUserToSwitch.create();
+    TestUser adminUserToSwitch =
+        TestUser::createTemporary("ode_test_T2016_user", GUM_USERTYPE_ADMIN);
 
     AppInstallHelper appInstallHelper("ode_test_T2016_app_install_helper",
         adminUserToSwitch.getUid());
index 1022f34b5cdeac76e1ebac9e02e9cc936b385cff..384c7a3c2aca8f8d840bb87178eb625fd204e228 100644 (file)
@@ -38,7 +38,7 @@
 #include <sm_commons.h>
 #include <sm_request.h>
 #include <synchronization_pipe.h>
-#include <temp_test_user.h>
+#include <test_user.h>
 #include <tests_common.h>
 #include <tzplatform.h>
 #include <uds.h>
@@ -259,8 +259,8 @@ RUNNER_CHILD_TEST(security_manager_04a_app_install_uninstall_by_app_user_for_sel
     const PrivilegeVector allowedPrivs = {PRIV_BLUETOOTH, PRIV_POWER};
     const PrivilegeVector someDeniedPrivs = {PRIV_DISPLAY, PRIV_NFC};
 
-    TemporaryTestUser testUser("sm_test_04a_user_name", GUM_USERTYPE_NORMAL);
-    testUser.create();
+    TestUser testUser =
+        TestUser::createTemporary("sm_test_04a_user_name", GUM_USERTYPE_NORMAL);
 
     AppInstallHelperExt app("sm_test_04a", testUser.getUid());
     app.addPrivileges(allowedPrivs);
@@ -280,8 +280,8 @@ RUNNER_CHILD_TEST(security_manager_04b_app_install_by_root_for_app_user) {
     const PrivilegeVector allowedPrivs = {PRIV_INTERNET, PRIV_LED};
     const PrivilegeVector someDeniedPrivs = {PRIV_LOCATION, PRIV_NOTIFICATION};
 
-    TemporaryTestUser testUser("sm_test_04b_user_name", GUM_USERTYPE_NORMAL);
-    testUser.create();
+    TestUser testUser =
+        TestUser::createTemporary("sm_test_04b_user_name", GUM_USERTYPE_NORMAL);
 
     AppInstallHelperExt app("sm_test_04b", testUser.getUid());
     app.addPrivileges(allowedPrivs);
@@ -334,8 +334,8 @@ RUNNER_CHILD_TEST(security_manager_07a_user_add_app_install)
     const PrivilegeVector allowedPrivs = {PRIV_INTERNET, PRIV_LED};
     const PrivilegeVector someDeniedPrivs = {PRIV_LOCATION, PRIV_NOTIFICATION};
 
-    TemporaryTestUser testUser("sm_test_07a_user_name", GUM_USERTYPE_NORMAL);
-    testUser.create();
+    TestUser testUser =
+        TestUser::createTemporary("sm_test_07a_user_name", GUM_USERTYPE_NORMAL);
 
     AppInstallHelperExt app("sm_test_07a", testUser.getUid());
     app.addPrivileges(allowedPrivs);
@@ -364,8 +364,8 @@ RUNNER_CHILD_TEST(security_manager_07b_user_add_offline)
     ServiceManager serviceManager("security-manager.socket");
     serviceManager.stopService();
 
-    TemporaryTestUser testUser("sm_test_07b_user_name", GUM_USERTYPE_NORMAL, true);
-    testUser.create();
+    TestUser testUser =
+        TestUser::createTemporary("sm_test_07b_user_name", GUM_USERTYPE_NORMAL, true);
 
     AppInstallHelperExt app("sm_test_07b", testUser.getUid());
     ScopedInstaller appInstall(app);
@@ -382,8 +382,8 @@ RUNNER_CHILD_TEST(security_manager_08_user_double_add_double_remove)
     const PrivilegeVector somePrivs = {PRIV_LED, PRIV_NOTIFICATION};
 
     // gumd
-    TemporaryTestUser testUser("sm_test_08_user_name", GUM_USERTYPE_NORMAL);
-    testUser.create();
+    TestUser testUser =
+        TestUser::createTemporary("sm_test_08_user_name", GUM_USERTYPE_NORMAL);
 
     // security-manager
     UserRequest addUserRequest;
@@ -433,14 +433,11 @@ RUNNER_CHILD_TEST(security_manager_09_app_install_constraint_check)
         Api::update(request);
     };
 
-    TemporaryTestUser users[] = {
-        {"sm_test_09_user_name_0", GUM_USERTYPE_NORMAL, false},
-        {"sm_test_09_user_name_1", GUM_USERTYPE_NORMAL, false}
+    TestUser users[] = {
+        TestUser::createTemporary("sm_test_09_user_name_0", GUM_USERTYPE_NORMAL, false),
+        TestUser::createTemporary("sm_test_09_user_name_1", GUM_USERTYPE_NORMAL, false)
     };
 
-    for (auto& gu : users)
-        gu.create();
-
     const char *const pkgIdPrefix[] =   {"sm_test_09_0",            "sm_test_09_1"};
     const char *const appIdPrefix[] =   {"sm_test_09_0",            "sm_test_09_1"};
     const char *const version[] =       {"sm_test_09_0_version",    "sm_test_09_1_version"};
@@ -790,8 +787,8 @@ namespace
 
 RUNNER_CHILD_TEST(security_manager_12a_internet_access_positive)
 {
-    TemporaryTestUser testUser("sm_test_12a_internet_access", GUM_USERTYPE_NORMAL);
-    testUser.create();
+    TestUser testUser =
+        TestUser::createTemporary("sm_test_12a_internet_access", GUM_USERTYPE_NORMAL);
     AppInstallHelperExt app("sm_test_12a", "sm_test_12a", testUser.getUid());
     app.addPrivilege(PRIV_INTERNET);
     ScopedInstaller appInstall(app);
@@ -810,8 +807,8 @@ RUNNER_CHILD_TEST(security_manager_12a_internet_access_positive)
 
 RUNNER_CHILD_TEST(security_manager_12b_internet_access_negative)
 {
-    TemporaryTestUser testUser("sm_test_12b_internet_access", GUM_USERTYPE_NORMAL);
-    testUser.create();
+    TestUser testUser =
+        TestUser::createTemporary("sm_test_12b_internet_access", GUM_USERTYPE_NORMAL);
     AppInstallHelperExt app("sm_test_12b", "sm_test_12b", testUser.getUid());
     ScopedInstaller appInstall(app);
 
@@ -839,8 +836,8 @@ RUNNER_TEST(security_manager_20_user_cynara_policy)
     const char *const USER_TYPE_NORMAL_BUCKET = "USER_TYPE_NORMAL";
     CynaraTestAdmin::Admin admin;
 
-    TemporaryTestUser user("sm_test_20_user_name", GUM_USERTYPE_NORMAL, false);
-    user.create();
+    TestUser user =
+        TestUser::createTemporary("sm_test_20_user_name", GUM_USERTYPE_NORMAL, false);
     std::string uid_string = user.getUidString();
 
     CynaraTestAdmin::CynaraPoliciesContainer nonemptyContainer;
@@ -864,11 +861,10 @@ RUNNER_CHILD_TEST(security_manager_21_security_manager_admin_deny_user_priv)
     const PrivilegeVector allowedPrivsAfterChange = {PRIV_DATASHARING};
     const PrivilegeVector deniedPrivsAfterChange = {PRIV_INTERNET};
 
-    TemporaryTestUser adminUser("sm_test_21_admin_user_name", GUM_USERTYPE_ADMIN, false);
-    TemporaryTestUser normalUser("sm_test_21_normal_user_name", GUM_USERTYPE_NORMAL, false);
-
-    adminUser.create();
-    normalUser.create();
+    TestUser adminUser =
+        TestUser::createTemporary("sm_test_21_admin_user_name", GUM_USERTYPE_ADMIN, false);
+    TestUser normalUser =
+        TestUser::createTemporary("sm_test_21_normal_user_name", GUM_USERTYPE_NORMAL, false);
 
     AppInstallHelper adminApp("sm_test_21_admin", adminUser.getUid());
     adminApp.addPrivileges(adminRequiredPrivs);
@@ -907,8 +903,8 @@ RUNNER_TEST(security_manager_22_security_manager_cmd_install)
     const std::string pkg_id = "sm_test_22_pkg_id";
     const std::string username("sm_test_22_user_name");
 
-    TemporaryTestUser user(username, GUM_USERTYPE_NORMAL);
-    user.create();
+    TestUser user =
+        TestUser::createTemporary(username, GUM_USERTYPE_NORMAL);
 
     const std::string path1 = TzPlatformConfig::appDirPath(user, app_id, pkg_id) + "/p1";
     const std::string path2 = TzPlatformConfig::appDirPath(user, app_id, pkg_id) + "/p2";
@@ -953,8 +949,8 @@ RUNNER_TEST(security_manager_23_security_manager_cmd_users)
 {
     const int SUCCESS = 0;
     const int FAILURE = 256;
-    TemporaryTestUser user("sm_test_23_user_name", GUM_USERTYPE_NORMAL, false);
-    user.create();
+    TestUser user =
+        TestUser::createTemporary("sm_test_23_user_name", GUM_USERTYPE_NORMAL, false);
     const std::string uidopt = " --uid=" + user.getUidString();
 
     struct operation {
@@ -1064,8 +1060,8 @@ RUNNER_CHILD_TEST(security_manager_25e_unprivileged_install_type_global)
 {
     RUNNER_IGNORED_MSG("This test is turned off because multiuser feature is not supported by platform correctly");
 
-    TemporaryTestUser testUser("sm_test_25e_user_name", GUM_USERTYPE_NORMAL);
-    testUser.create();
+    TestUser testUser =
+        TestUser::createTemporary("sm_test_25e_user_name", GUM_USERTYPE_NORMAL);
 
     AppInstallHelper app("sm_test_25e");
 
@@ -1085,8 +1081,8 @@ RUNNER_CHILD_TEST(security_manager_25f_unprivileged_install_type_preloaded)
 {
     RUNNER_IGNORED_MSG("This test is turned off because multiuser feature is not supported by platform correctly");
 
-    TemporaryTestUser testUser("sm_test_25f_user_name", GUM_USERTYPE_NORMAL);
-    testUser.create();
+    TestUser testUser =
+        TestUser::createTemporary("sm_test_25f_user_name", GUM_USERTYPE_NORMAL);
 
     AppInstallHelper app("sm_test_25f");
 
@@ -1105,8 +1101,8 @@ RUNNER_CHILD_TEST(security_manager_25g_local_user_set_install_type_local)
     const PrivilegeVector allowedPrivs = {PRIV_VOLUME_SET, PRIV_SYSTEMMONITOR, PRIV_INTERNET};
     const PrivilegeVector someDeniedPrivs = {PRIV_PUSH, PRIV_POWER, PRIV_NOTIFICATION};
 
-    TemporaryTestUser testUser("sm_test_25g_user_name", GUM_USERTYPE_NORMAL);
-    testUser.create();
+    TestUser testUser =
+        TestUser::createTemporary("sm_test_25g_user_name", GUM_USERTYPE_NORMAL);
 
     AppInstallHelperExt app("sm_test_25g", testUser.getUid());
     app.createPrivateDir();
@@ -1127,8 +1123,8 @@ RUNNER_CHILD_TEST(security_manager_25g_local_user_set_install_type_local)
 
 RUNNER_CHILD_TEST(security_manager_25h_local_path_global_install)
 {
-    TemporaryTestUser testUser("sm_test_25h_user_name", GUM_USERTYPE_NORMAL);
-    testUser.create();
+    TestUser testUser =
+        TestUser::createTemporary("sm_test_25h_user_name", GUM_USERTYPE_NORMAL);
 
     AppInstallHelper app("sm_test_25h", testUser.getUid());
     app.createPrivateDir();
@@ -1143,8 +1139,8 @@ RUNNER_CHILD_TEST(security_manager_25h_local_path_global_install)
 
 RUNNER_CHILD_TEST(security_manager_25i_local_path_preloaded_install)
 {
-    TemporaryTestUser testUser("sm_test_25i_user_name", GUM_USERTYPE_NORMAL);
-    testUser.create();
+    TestUser testUser =
+        TestUser::createTemporary("sm_test_25i_user_name", GUM_USERTYPE_NORMAL);
 
     AppInstallHelper app("sm_test_25i", testUser.getUid());
     app.createPrivateDir();
@@ -1159,8 +1155,8 @@ RUNNER_CHILD_TEST(security_manager_25i_local_path_preloaded_install)
 
 RUNNER_CHILD_TEST(security_manager_25j_global_path_local_install)
 {
-    TemporaryTestUser testUser("sm_test_25j_user_name", GUM_USERTYPE_NORMAL);
-    testUser.create();
+    TestUser testUser =
+        TestUser::createTemporary("sm_test_25j_user_name", GUM_USERTYPE_NORMAL);
 
     AppInstallHelper appLocal("sm_test_25j", testUser.getUid());
 
@@ -1183,8 +1179,8 @@ RUNNER_CHILD_TEST(security_manager_25j_global_path_local_install)
 
 RUNNER_CHILD_TEST(security_manager_26_hybrid_pkg_uninstall_artifacts_check)
 {
-    TemporaryTestUser testUser("sm_test_26_user_name", GUM_USERTYPE_NORMAL);
-    testUser.create();
+    TestUser testUser =
+        TestUser::createTemporary("sm_test_26_user_name", GUM_USERTYPE_NORMAL);
 
     const PrivilegeVector allowedPrivs = {PRIV_WIFIDIRECT, PRIV_TELEPHONY};
 
@@ -1209,8 +1205,8 @@ RUNNER_CHILD_TEST(security_manager_26_hybrid_pkg_uninstall_artifacts_check)
 
 RUNNER_CHILD_TEST(security_manager_26_1a_security_manager_get_app_owner_uid)
 {
-    TemporaryTestUser testUser("sm_test_26_1a_user_name", GUM_USERTYPE_NORMAL);
-    testUser.create();
+    TestUser testUser =
+        TestUser::createTemporary("sm_test_26_1a_user_name", GUM_USERTYPE_NORMAL);
     AppInstallHelperExt app("sm_test_26_1a", "sm_test_26_1a", testUser.getUid());
     ScopedInstaller appInstall(app);
 
@@ -1251,8 +1247,8 @@ RUNNER_CHILD_TEST(security_manager_26_1b_security_manager_get_app_owner_uid)
         }
     };
 
-    TemporaryTestUser testUser("sm_test_26_1b_user_name", GUM_USERTYPE_NORMAL);
-    testUser.create();
+    TestUser testUser =
+        TestUser::createTemporary("sm_test_26_1b_user_name", GUM_USERTYPE_NORMAL);
 
     runInChildParentWait([&]{
         test();
@@ -1263,8 +1259,8 @@ RUNNER_CHILD_TEST(security_manager_26_1b_security_manager_get_app_owner_uid)
 
 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();
+    TestUser testUser =
+        TestUser::createTemporary("sm_test_26_2_user_name", GUM_USERTYPE_NORMAL);
 
     AppInstallHelperExt app("sm_test_26_2");
     {
@@ -1293,8 +1289,8 @@ RUNNER_CHILD_TEST(security_manager_26_2_security_manager_self_is_app)
 RUNNER_CHILD_TEST(security_manager_26_3_security_manager_is_app_from_pid)
 {
     SynchronizationPipe pipe;
-    TemporaryTestUser testUser("sm_test_26_3_user_name", GUM_USERTYPE_NORMAL);
-    testUser.create();
+    TestUser testUser =
+        TestUser::createTemporary("sm_test_26_3_user_name", GUM_USERTYPE_NORMAL);
 
     AppInstallHelperExt app("sm_test_26_3");
     {
@@ -1334,9 +1330,9 @@ RUNNER_CHILD_TEST(security_manager_26_3_security_manager_is_app_from_pid)
 
 RUNNER_CHILD_TEST(security_manager_26_4a_security_manager_get_app_full_credentials_from_pid)
 {
-    TemporaryTestUser testUser("sm_test_26_4_user_name", GUM_USERTYPE_NORMAL);
-    testUser.create();
-    AppInstallHelperExt app("sm_test_26_4", "sm_test_26_4", testUser.getUid());
+    TestUser testUser = TestUser::createTemporary("sm_test_26_4a_user_name", GUM_USERTYPE_NORMAL);
+
+    AppInstallHelperExt app("sm_test_26_4a", "sm_test_26_4a", testUser.getUid());
     ScopedInstaller appInstall(app);
     auto pid = runInChildParentWait([&]{
         // child - the actual application
@@ -1363,9 +1359,9 @@ RUNNER_CHILD_TEST(security_manager_26_4a_security_manager_get_app_full_credentia
 
 RUNNER_CHILD_TEST(security_manager_26_4b_security_manager_get_app_full_credentials_from_pid)
 {
-    TemporaryTestUser testUser("sm_test_26_4_user_name", GUM_USERTYPE_NORMAL);
-    testUser.create();
-    AppInstallHelperExt app("sm_test_26_4", "sm_test_26_4", testUser.getUid());
+    TestUser testUser = TestUser::createTemporary("sm_test_26_4b_user_name", GUM_USERTYPE_NORMAL);
+
+    AppInstallHelperExt app("sm_test_26_4b", "sm_test_26_4b", testUser.getUid());
     app.setHybrid();
     ScopedInstaller appInstall(app);
     auto pid = runInChildParentWait([&]{
index 2e8965c6a35009403276d584baaf713fee0792dc..7fd21544bc42ad6a364ec82a860c3c2841e6980f 100644 (file)
@@ -25,6 +25,7 @@
 #include <sm_api.h>
 #include <sm_commons.h>
 #include <sm_request.h>
+#include <test_user.h>
 #include <tests_common.h>
 #include <tzplatform.h>
 #include <app_install_helper.h>
@@ -36,6 +37,14 @@ RUNNER_TEST_GROUP_INIT(SECURITY_MANAGER_APP_DEFINED_PRIVILEGE)
 using namespace SecurityManagerTest;
 using namespace PrivilegeNames;
 
+namespace {
+
+const std::string& ownerId() {
+    static const auto &ownerId = TestUser::getSystemUser(SystemUser::OWNER).getUidString();
+    return ownerId;
+}
+};
+
 RUNNER_CHILD_TEST(app_defined_01_global_install_untrusted)
 {
     const Privilege privilege(
@@ -43,7 +52,7 @@ RUNNER_CHILD_TEST(app_defined_01_global_install_untrusted)
         Privilege::UNTRUSTED);
     const std::string providerAppId = "app_def_01_provider";
     const std::string clientAppId = "app_def_01_client";
-    const std::string ownerId = "5001";
+
     const std::string session = "S0M3S3SSI0N";
 
     AppInstallHelper provider(providerAppId);
@@ -58,12 +67,12 @@ RUNNER_CHILD_TEST(app_defined_01_global_install_untrusted)
     ScopedInstaller req2(client);
 
     CynaraTestClient::Client cynara;
-    cynara.check(clientLabel, session, ownerId, privilege, CYNARA_API_ACCESS_ALLOWED);
+    cynara.check(clientLabel, session, ownerId(), privilege, CYNARA_API_ACCESS_ALLOWED);
 
     // uninstall provider
     req1.uninstallApp();
 
-    cynara.check(clientLabel, session, ownerId, privilege, CYNARA_API_ACCESS_DENIED);
+    cynara.check(clientLabel, session, ownerId(), privilege, CYNARA_API_ACCESS_DENIED);
 }
 
 RUNNER_CHILD_TEST(app_defined_02_global_install_licensed)
@@ -76,7 +85,6 @@ RUNNER_CHILD_TEST(app_defined_02_global_install_licensed)
         "/opt/usr/globalapps/app_def_client_01_pkg_id/cert/softwaremind.pem");
     const std::string providerAppId = "app_def_provider_01";
     const std::string clientAppId = "app_def_client_01";
-    const std::string ownerId = "5001";
     const std::string session = "S0M33S3SSI0N";
 
     AppInstallHelper provider(providerAppId);
@@ -91,12 +99,12 @@ RUNNER_CHILD_TEST(app_defined_02_global_install_licensed)
     ScopedInstaller req2(client);
 
     CynaraTestClient::Client cynara;
-    cynara.check(clientLabel, session, ownerId, clientPrivilegeLicense, CYNARA_API_ACCESS_ALLOWED);
+    cynara.check(clientLabel, session, ownerId(), clientPrivilegeLicense, CYNARA_API_ACCESS_ALLOWED);
 
     // uninstall provider
     req1.uninstallApp();
 
-    cynara.check(clientLabel, session, ownerId, clientPrivilegeLicense, CYNARA_API_ACCESS_DENIED);
+    cynara.check(clientLabel, session, ownerId(), clientPrivilegeLicense, CYNARA_API_ACCESS_DENIED);
 }
 
 RUNNER_CHILD_TEST(app_defined_03_database_update)
@@ -109,7 +117,6 @@ RUNNER_CHILD_TEST(app_defined_03_database_update)
     const std::string providerAppIdA = "app_def_provider_01";
     const std::string providerAppIdB = "app_def_provider_02";
     const std::string clientAppId = "app_def_client_01";
-    const std::string ownerId = "5001";
     const std::string session = "S0M33S3SSI0N";
 
     AppInstallHelper providerA(providerAppIdA);
@@ -128,20 +135,20 @@ RUNNER_CHILD_TEST(app_defined_03_database_update)
     ScopedInstaller req3(client);
 
     CynaraTestClient::Client cynara;
-    cynara.check(clientLabel, session, ownerId, privilegeA, CYNARA_API_ACCESS_ALLOWED);
-    cynara.check(clientLabel, session, ownerId, privilegeB, CYNARA_API_ACCESS_ALLOWED);
+    cynara.check(clientLabel, session, ownerId(), privilegeA, CYNARA_API_ACCESS_ALLOWED);
+    cynara.check(clientLabel, session, ownerId(), privilegeB, CYNARA_API_ACCESS_ALLOWED);
 
     // uninstall providerA
     req1.uninstallApp();
 
-    cynara.check(clientLabel, session, ownerId, privilegeA, CYNARA_API_ACCESS_DENIED);
-    cynara.check(clientLabel, session, ownerId, privilegeB, CYNARA_API_ACCESS_ALLOWED);
+    cynara.check(clientLabel, session, ownerId(), privilegeA, CYNARA_API_ACCESS_DENIED);
+    cynara.check(clientLabel, session, ownerId(), privilegeB, CYNARA_API_ACCESS_ALLOWED);
 
     // uninstall providerB
     req2.uninstallApp();
 
-    cynara.check(clientLabel, session, ownerId, privilegeA, CYNARA_API_ACCESS_DENIED);
-    cynara.check(clientLabel, session, ownerId, privilegeB, CYNARA_API_ACCESS_DENIED);
+    cynara.check(clientLabel, session, ownerId(), privilegeA, CYNARA_API_ACCESS_DENIED);
+    cynara.check(clientLabel, session, ownerId(), privilegeB, CYNARA_API_ACCESS_DENIED);
 }
 
 RUNNER_CHILD_TEST(app_defined_04_app_update)
@@ -164,7 +171,6 @@ RUNNER_CHILD_TEST(app_defined_04_app_update)
 
     const std::string providerAppId = "app_def_provider_01";
     const std::string clientAppId = "app_def_client_01";
-    const std::string ownerId = "5001";
     const std::string session = "S0M33S3SSI0N";
 
     AppInstallHelper providerV1(providerAppId);
@@ -183,9 +189,9 @@ RUNNER_CHILD_TEST(app_defined_04_app_update)
     ScopedInstaller req2(client);
 
     CynaraTestClient::Client cynara;
-    cynara.check(clientLabel, session, ownerId, clientPrivilegeLicenseA, CYNARA_API_ACCESS_ALLOWED);
-    cynara.check(clientLabel, session, ownerId, privilegeB, CYNARA_API_ACCESS_ALLOWED);
-    cynara.check(clientLabel, session, ownerId, clientPrivilegeLicenseC, CYNARA_API_ACCESS_DENIED);
+    cynara.check(clientLabel, session, ownerId(), clientPrivilegeLicenseA, CYNARA_API_ACCESS_ALLOWED);
+    cynara.check(clientLabel, session, ownerId(), privilegeB, CYNARA_API_ACCESS_ALLOWED);
+    cynara.check(clientLabel, session, ownerId(), clientPrivilegeLicenseC, CYNARA_API_ACCESS_DENIED);
 
     // update provider version, remove privilegeA, add privilegeC
     providerV2.addAppDefinedPrivilege(privilegeB);
@@ -193,9 +199,9 @@ RUNNER_CHILD_TEST(app_defined_04_app_update)
 
     ScopedInstaller req3(providerV2);
 
-    cynara.check(clientLabel, session, ownerId, clientPrivilegeLicenseA, CYNARA_API_ACCESS_DENIED);
-    cynara.check(clientLabel, session, ownerId, privilegeB, CYNARA_API_ACCESS_ALLOWED);
-    cynara.check(clientLabel, session, ownerId, clientPrivilegeLicenseC, CYNARA_API_ACCESS_ALLOWED);
+    cynara.check(clientLabel, session, ownerId(), clientPrivilegeLicenseA, CYNARA_API_ACCESS_DENIED);
+    cynara.check(clientLabel, session, ownerId(), privilegeB, CYNARA_API_ACCESS_ALLOWED);
+    cynara.check(clientLabel, session, ownerId(), clientPrivilegeLicenseC, CYNARA_API_ACCESS_ALLOWED);
 }
 
 RUNNER_CHILD_TEST(app_defined_05_global_local_install)
@@ -218,7 +224,6 @@ RUNNER_CHILD_TEST(app_defined_05_global_local_install)
 
     const std::string providerAppId = "app_def_provider_01";
     const std::string clientAppId = "app_def_client_01";
-    const std::string ownerId = "5001";
     const std::string bobId = "5002";
     const std::string session = "S0M33S3SSI0N";
 
@@ -246,9 +251,9 @@ RUNNER_CHILD_TEST(app_defined_05_global_local_install)
     // local provider only and global consumer only
     ScopedInstaller req1(providerLocal);
     ScopedInstaller req2(clientGlobal);
-    cynara.check(clientGlobalLabel, session, ownerId, privilegeA, CYNARA_API_ACCESS_DENIED);
-    cynara.check(clientGlobalLabel, session, ownerId, clientGlobalPrivilegeLicenseB, CYNARA_API_ACCESS_DENIED);
-    cynara.check(clientGlobalLabel, session, ownerId, privilegeC, CYNARA_API_ACCESS_DENIED);
+    cynara.check(clientGlobalLabel, session, ownerId(), privilegeA, CYNARA_API_ACCESS_DENIED);
+    cynara.check(clientGlobalLabel, session, ownerId(), clientGlobalPrivilegeLicenseB, CYNARA_API_ACCESS_DENIED);
+    cynara.check(clientGlobalLabel, session, ownerId(), privilegeC, CYNARA_API_ACCESS_DENIED);
     cynara.check(clientGlobalLabel, session, bobId, privilegeA, CYNARA_API_ACCESS_ALLOWED);
     cynara.check(clientGlobalLabel, session, bobId, clientGlobalPrivilegeLicenseB, CYNARA_API_ACCESS_ALLOWED);
     cynara.check(clientGlobalLabel, session, bobId, privilegeC, CYNARA_API_ACCESS_DENIED);
@@ -261,27 +266,27 @@ RUNNER_CHILD_TEST(app_defined_05_global_local_install)
 
     // global/local provider and global/local consumer
     ScopedInstaller req4(providerGlobal);
-    cynara.check(clientGlobalLabel, session, ownerId, privilegeA, CYNARA_API_ACCESS_ALLOWED);
-    cynara.check(clientGlobalLabel, session, ownerId, clientGlobalPrivilegeLicenseB, CYNARA_API_ACCESS_DENIED);
-    cynara.check(clientGlobalLabel, session, ownerId, privilegeC, CYNARA_API_ACCESS_ALLOWED);
+    cynara.check(clientGlobalLabel, session, ownerId(), privilegeA, CYNARA_API_ACCESS_ALLOWED);
+    cynara.check(clientGlobalLabel, session, ownerId(), clientGlobalPrivilegeLicenseB, CYNARA_API_ACCESS_DENIED);
+    cynara.check(clientGlobalLabel, session, ownerId(), privilegeC, CYNARA_API_ACCESS_ALLOWED);
     cynara.check(clientLocalLabel, session, bobId, privilegeA, CYNARA_API_ACCESS_DENIED);
     cynara.check(clientLocalLabel, session, bobId, clientLocalPrivilegeLicenseB, CYNARA_API_ACCESS_ALLOWED);
     //cynara.check(clientLocalLabel, session, bobId, privilegeC, CYNARA_API_ACCESS_DENIED);
 
     // global provider only and global/local consumer
     req1.uninstallApp();
-    cynara.check(clientGlobalLabel, session, ownerId, privilegeA, CYNARA_API_ACCESS_ALLOWED);
-    cynara.check(clientGlobalLabel, session, ownerId, clientGlobalPrivilegeLicenseB, CYNARA_API_ACCESS_DENIED);
-    cynara.check(clientGlobalLabel, session, ownerId, privilegeC, CYNARA_API_ACCESS_ALLOWED);
+    cynara.check(clientGlobalLabel, session, ownerId(), privilegeA, CYNARA_API_ACCESS_ALLOWED);
+    cynara.check(clientGlobalLabel, session, ownerId(), clientGlobalPrivilegeLicenseB, CYNARA_API_ACCESS_DENIED);
+    cynara.check(clientGlobalLabel, session, ownerId(), privilegeC, CYNARA_API_ACCESS_ALLOWED);
     cynara.check(clientLocalLabel, session, bobId, privilegeA, CYNARA_API_ACCESS_DENIED);
     cynara.check(clientLocalLabel, session, bobId, clientLocalPrivilegeLicenseB, CYNARA_API_ACCESS_DENIED);
     cynara.check(clientLocalLabel, session, bobId, privilegeC, CYNARA_API_ACCESS_ALLOWED);
 
     // global provider only and global consumer only
     req3.uninstallApp();
-    cynara.check(clientGlobalLabel, session, ownerId, privilegeA, CYNARA_API_ACCESS_ALLOWED);
-    cynara.check(clientGlobalLabel, session, ownerId, clientGlobalPrivilegeLicenseB, CYNARA_API_ACCESS_DENIED);
-    cynara.check(clientGlobalLabel, session, ownerId, privilegeC, CYNARA_API_ACCESS_ALLOWED);
+    cynara.check(clientGlobalLabel, session, ownerId(), privilegeA, CYNARA_API_ACCESS_ALLOWED);
+    cynara.check(clientGlobalLabel, session, ownerId(), clientGlobalPrivilegeLicenseB, CYNARA_API_ACCESS_DENIED);
+    cynara.check(clientGlobalLabel, session, ownerId(), privilegeC, CYNARA_API_ACCESS_ALLOWED);
 }
 
 RUNNER_CHILD_TEST(app_defined_06_get_provider)
@@ -296,7 +301,7 @@ RUNNER_CHILD_TEST(app_defined_06_get_provider)
         "http://tizen.org/untrusted/gamestudio/running",
         Privilege::UNTRUSTED);
     const std::string providerAppId = "app_def_06_provider";
-    uid_t uid = 5001;
+    uid_t uid = TestUser::getSystemUser(SystemUser::OWNER).getUid();
 
     AppInstallHelper providerGlobal(providerAppId);
     AppInstallHelper providerLocal(providerAppId, uid);
@@ -566,7 +571,6 @@ RUNNER_CHILD_TEST(app_defined_11_invalid_license)
         "/opt/usr/globalapps/app_def_client_01_pkg_id/cert/futuremind.der");
     const std::string providerAppId = "app_def_provider_01";
     const std::string clientAppId = "app_def_client_01";
-    const std::string ownerId = "5001";
     const std::string session = "S0M33S3SSI0N";
 
     AppInstallHelper provider(providerAppId);
@@ -581,7 +585,7 @@ RUNNER_CHILD_TEST(app_defined_11_invalid_license)
     ScopedInstaller req2(client);
 
     CynaraTestClient::Client cynara;
-    cynara.check(clientLabel, session, ownerId, clientPrivilegeLicense, CYNARA_API_ACCESS_DENIED);
+    cynara.check(clientLabel, session, ownerId(), clientPrivilegeLicense, CYNARA_API_ACCESS_DENIED);
 }
 
 RUNNER_CHILD_TEST(app_defined_12_invalid_common_name)
@@ -594,7 +598,6 @@ RUNNER_CHILD_TEST(app_defined_12_invalid_common_name)
         "/opt/usr/globalapps/app_def_client_01_pkg_id/cert/futuremind.der");
     const std::string providerAppId = "app_def_provider_02";
     const std::string clientAppId = "app_def_client_01";
-    const std::string ownerId = "5001";
     const std::string session = "S0M33S3SSI0N";
 
     AppInstallHelper provider(providerAppId);
@@ -609,5 +612,5 @@ RUNNER_CHILD_TEST(app_defined_12_invalid_common_name)
     ScopedInstaller req2(client);
 
     CynaraTestClient::Client cynara;
-    cynara.check(clientLabel, session, ownerId, clientPrivilegeLicense, CYNARA_API_ACCESS_DENIED);
+    cynara.check(clientLabel, session, ownerId(), clientPrivilegeLicense, CYNARA_API_ACCESS_DENIED);
 }
index 86384d3479fc50ec9ae3c03f3e05074e8fa494fa..b4e963a960fb0352d7322b238915500bd52812b4 100644 (file)
@@ -22,7 +22,7 @@
 #include <scoped_installer.h>
 #include <sm_api.h>
 #include <sm_commons.h>
-#include <temp_test_user.h>
+#include <test_user.h>
 #include <tests_common.h>
 
 #include <dpl/test/test_runner.h>
@@ -41,8 +41,8 @@ using namespace SecurityManagerTest;
 RUNNER_TEST_GROUP_INIT(SECURITY_MANAGER_APP_POLICY)
 
 RUNNER_CHILD_TEST(security_manager_ap1_app_policy_fetch_for_self) {
-    TemporaryTestUser tmpUser("sm_test_ap1_user_name", GUM_USERTYPE_NORMAL, false);
-    tmpUser.create();
+    TestUser tmpUser =
+        TestUser::createTemporary("sm_test_ap1_user_name", GUM_USERTYPE_NORMAL, false);
 
     AppInstallHelper app("sm_test_ap1", tmpUser.getUid());
     app.addPrivileges(TEST_PRIVACY_PRIVILEGES);
@@ -95,10 +95,10 @@ RUNNER_CHILD_TEST(security_manager_ap1_app_policy_fetch_for_self) {
 }
 
 RUNNER_CHILD_TEST(security_manager_ap2_app_policy_fetch_for_self_different_user) {
-    TemporaryTestUser tmpUser("sm_test_ap2_1_user_name", GUM_USERTYPE_NORMAL, false);
-    tmpUser.create();
-    TemporaryTestUser tmpUser2("sm_test_ap2_2_user_name", GUM_USERTYPE_NORMAL, false);
-    tmpUser2.create();
+    TestUser tmpUser =
+        TestUser::createTemporary("sm_test_ap2_1_user_name", GUM_USERTYPE_NORMAL, false);
+    TestUser tmpUser2 =
+        TestUser::createTemporary("sm_test_ap2_2_user_name", GUM_USERTYPE_NORMAL, false);
 
     AppInstallHelper app("sm_test_ap2", tmpUser.getUid());
     app.addPrivileges(TEST_PRIVACY_PRIVILEGES);
@@ -124,10 +124,10 @@ RUNNER_CHILD_TEST(security_manager_ap2_app_policy_fetch_for_self_different_user)
 }
 
 RUNNER_CHILD_TEST(security_manager_ap3_app_policy_fetch_for_self_different_user_global) {
-    TemporaryTestUser tmpUser("sm_test_ap3_1_user_name", GUM_USERTYPE_NORMAL, false);
-    tmpUser.create();
-    TemporaryTestUser tmpUser2("sm_test_ap3_2_user_name", GUM_USERTYPE_NORMAL, false);
-    tmpUser2.create();
+    TestUser tmpUser =
+        TestUser::createTemporary("sm_test_ap3_1_user_name", GUM_USERTYPE_NORMAL, false);
+    TestUser tmpUser2 =
+        TestUser::createTemporary("sm_test_ap3_2_user_name", GUM_USERTYPE_NORMAL, false);
 
     AppInstallHelper app("sm_test_ap3");
     app.setInstallType(SM_APP_INSTALL_GLOBAL);
@@ -154,8 +154,8 @@ RUNNER_CHILD_TEST(security_manager_ap3_app_policy_fetch_for_self_different_user_
 }
 
 RUNNER_CHILD_TEST(security_manager_ap3_app_policy_fetch_for_self_different_app) {
-    TemporaryTestUser tmpUser("sm_test_ap3_user_name", GUM_USERTYPE_NORMAL, false);
-    tmpUser.create();
+    TestUser tmpUser =
+        TestUser::createTemporary("sm_test_ap3_user_name", GUM_USERTYPE_NORMAL, false);
 
     AppInstallHelper app1("sm_test_ap3_1", tmpUser.getUid());
     app1.addPrivileges(TEST_PRIVACY_PRIVILEGES);
index 6f17b83da972cd814483198bfbf24236a3c40772..35dd21d353f2e90b7b0f46d1daaa6e98367f7536 100644 (file)
@@ -31,7 +31,7 @@
 #include <sm_commons.h>
 #include <sm_label_monitor.h>
 #include <synchronization_pipe.h>
-#include <temp_test_user.h>
+#include <test_user.h>
 #include <tests_common.h>
 
 using namespace SecurityManagerTest;
@@ -66,8 +66,8 @@ RUNNER_TEST_GROUP_INIT(SECURITY_MANAGER_LABEL_MONITOR_API)
 RUNNER_CHILD_TEST(security_manager_71_app_label_monitor_user_local_global)
 {
     SynchronizationPipe synchPipe;
-    TemporaryTestUser testUser("sm_test_71_user_name", GUM_USERTYPE_NORMAL, false);
-    testUser.create();
+    TestUser testUser =
+        TestUser::createTemporary("sm_test_71_user_name", GUM_USERTYPE_NORMAL, false);
 
     pid_t pid = runInChild([&] {
         synchPipe.claimChildEp();
@@ -126,9 +126,8 @@ RUNNER_CHILD_TEST(security_manager_71_app_label_monitor_user_local_global)
 RUNNER_CHILD_TEST(security_manager_72_app_label_monitor_user_local)
 {
     SynchronizationPipe synchPipe;
-    TemporaryTestUser testUser("sm_test_75_user_name", GUM_USERTYPE_NORMAL, false);
-    testUser.create();
-
+    TestUser testUser =
+        TestUser::createTemporary("sm_test_75_user_name", GUM_USERTYPE_NORMAL, false);
 
     pid_t pid = runInChild([&] {
         synchPipe.claimChildEp();
@@ -188,11 +187,11 @@ RUNNER_CHILD_TEST(security_manager_73_app_label_monitor_different_users)
     const std::string appLocalName = "sm_test_73_local";
     const std::string appGlobalName = "sm_test_73_global";
 
-    TemporaryTestUser testUser1("sm_test_73_user_name_1", GUM_USERTYPE_NORMAL, false);
-    testUser1.create();
+    TestUser testUser1 =
+        TestUser::createTemporary("sm_test_73_user_name_1", GUM_USERTYPE_NORMAL, false);
 
-    TemporaryTestUser testUser2("sm_test_73_user_name_2", GUM_USERTYPE_NORMAL, false);
-    testUser2.create();
+    TestUser testUser2 =
+        TestUser::createTemporary("sm_test_73_user_name_2", GUM_USERTYPE_NORMAL, false);
 
     AppInstallHelper appLocal(appLocalName, testUser1.getUid());
     appLocal.setInstallType(SM_APP_INSTALL_LOCAL);
@@ -231,11 +230,10 @@ RUNNER_CHILD_TEST(security_manager_74_app_label_monitor_relabel_changes_global)
     ScopedInstaller appGlobalInstall2(appGlobal2);
 
     runInChildParentWait([&] { // child
-        TemporaryTestUser testUser("sm_test_74_user_name", GUM_USERTYPE_NORMAL, false);
-
         setCaps("all=eip");
         RUNNER_ASSERT_ERRNO_MSG(prctl(PR_SET_KEEPCAPS, 1, 0, 0) == 0, "prctl keeping caps failed");
-        testUser.create();
+        TestUser testUser =
+            TestUser::createTemporary("sm_test_74_user_name", GUM_USERTYPE_NORMAL, false);
         RUNNER_ASSERT_ERRNO_MSG(drop_root_privileges(testUser.getUid(), testUser.getGid()) == 0,
                                 "drop_root_privileges failed");
         setCaps("cap_mac_admin=eip");
@@ -256,8 +254,8 @@ RUNNER_CHILD_TEST(security_manager_75_app_label_monitor_relabel_changes_local)
     const std::string appLocalName2 = "sm_test_75_local2";
     const std::string appLocalName3 = "sm_test_75_local3";
     const std::string new_user_name = "sm_test_75";
-    TemporaryTestUser testUser("sm_test_75_user_name", GUM_USERTYPE_NORMAL, false);
-    testUser.create();
+    TestUser testUser =
+        TestUser::createTemporary("sm_test_75_user_name", GUM_USERTYPE_NORMAL, false);
     SynchronizationPipe synchPipe;
 
     pid_t pid = runInChild([&] {
index 152f4b56a13aff5583ffaed0b4c58034dd779c11..b682b9d776192bd5c6d9b2b93623c0ec674b2634 100644 (file)
@@ -27,7 +27,7 @@
 #include <sm_api.h>
 #include <sm_policy_request.h>
 #include <sm_user_request.h>
-#include <temp_test_user.h>
+#include <test_user.h>
 #include <privilege_names.h>
 
 #include <security-manager.h>
@@ -39,8 +39,8 @@ RUNNER_TEST_GROUP_INIT(SECURITY_MANAGER_NSS_PLUGIN)
 
 RUNNER_CHILD_TEST(nss_01_normal_user_without_inter_daemon_groups) {
     const std::string newUserName = "nss_01_user";
-    TemporaryTestUser testUser(newUserName, GUM_USERTYPE_NORMAL, false);
-    testUser.create();
+    TestUser testUser =
+        TestUser::createTemporary(newUserName, GUM_USERTYPE_NORMAL, false);
 
     UserRequest addUserRequest;
     addUserRequest.setUid(testUser.getUid());
@@ -68,8 +68,8 @@ RUNNER_CHILD_TEST(nss_01_normal_user_without_inter_daemon_groups) {
 
 RUNNER_CHILD_TEST(nss_02_guest_user_without_inter_daemon_groups) {
     const std::string newUserName = "nss_02_user";
-    TemporaryTestUser testUser(newUserName, GUM_USERTYPE_GUEST, false);
-    testUser.create();
+    TestUser testUser =
+        TestUser::createTemporary(newUserName, GUM_USERTYPE_GUEST, false);
 
     UserRequest addUserRequest;
     addUserRequest.setUid(testUser.getUid());
@@ -98,8 +98,8 @@ RUNNER_CHILD_TEST(nss_02_guest_user_without_inter_daemon_groups) {
 
 RUNNER_CHILD_TEST(nss_03_guest_user_without_inter_daemon_groups_unaffected_by_cynara) {
     const std::string newUserName = "nss_03_user";
-    TemporaryTestUser testUser(newUserName, GUM_USERTYPE_GUEST, false);
-    testUser.create();
+    TestUser testUser =
+        TestUser::createTemporary(newUserName, GUM_USERTYPE_GUEST, false);
 
     UserRequest addUserRequest;
     addUserRequest.setUid(testUser.getUid());
index fe5dcdae8640f91249e870ba89af41ddc261fe35..61ad2fc477bf65e10276393896a85b252e99376d 100644 (file)
@@ -17,7 +17,7 @@
 #include <app_install_helper.h>
 #include <dpl/test/test_runner.h>
 #include <scoped_installer.h>
-#include <temp_test_user.h>
+#include <test_user.h>
 #include <label_generator.h>
 #include <sm_commons.h>
 
@@ -45,8 +45,8 @@ RUNNER_TEST(security_manager_101_paths_global_extended)
 
 RUNNER_TEST(security_manager_102_paths_local_extended)
 {
-    TemporaryTestUser user("sm_test_102", GUM_USERTYPE_NORMAL);
-    user.create();
+    TestUser user =
+        TestUser::createTemporary("sm_test_102", GUM_USERTYPE_NORMAL);
 
     AppInstallHelper app("sm_test_102", user.getUid());
     app.createPrivateDir(0, AppInstallHelper::RootType::EXTENDED);
@@ -75,8 +75,8 @@ RUNNER_TEST(security_manager_103_paths_global_skel)
 
 RUNNER_TEST(security_manager_104_paths_local_skel)
 {
-    TemporaryTestUser user("sm_test_104", GUM_USERTYPE_NORMAL);
-    user.create();
+    TestUser user =
+        TestUser::createTemporary("sm_test_104", GUM_USERTYPE_NORMAL);
 
     AppInstallHelper app("sm_test_104", user.getUid());
     app.createPrivateDir(0, AppInstallHelper::RootType::SKEL);
@@ -88,4 +88,3 @@ RUNNER_TEST(security_manager_104_paths_local_skel)
     req.addPath(app.getPrivateDir(0, AppInstallHelper::RootType::SKEL), SECURITY_MANAGER_PATH_RW);
     Api::install(req, SECURITY_MANAGER_ERROR_NOT_PATH_OWNER);
 }
-
index 67b51dab41c5cb6691cb6ce51c3f0bca8235954d..28fbef5ce225a85a16a039c0a9c9424fd5d73dcb 100644 (file)
@@ -32,7 +32,7 @@
 #include <sm_commons.h>
 #include <sm_label_monitor.h>
 #include <synchronization_pipe.h>
-#include <temp_test_user.h>
+#include <test_user.h>
 #include <tests_common.h>
 
 using namespace SecurityManagerTest;
@@ -71,7 +71,7 @@ static void corruptFile(uid_t uid)
     writeToPermissibleFile(path);
 }
 
-static void clientMonitorProcess(const TemporaryTestUser &testUser)
+static void clientMonitorProcess(const TestUser &testUser)
 {
     runInChildParentWait([&] {
         setCaps("cap_mac_admin+ep cap_setuid+ep cap_setgid+ep");
@@ -104,8 +104,8 @@ RUNNER_CHILD_TEST(security_manager_121a_repair_permissible_file_daemon_global)
 
 RUNNER_CHILD_TEST(security_manager_121b_repair_permissible_file_daemon_local)
 {
-    TemporaryTestUser testUser("sm_test_121b_user_name", GUM_USERTYPE_NORMAL, false);
-    testUser.create();
+    TestUser testUser =
+        TestUser::createTemporary("sm_test_121b_user_name", GUM_USERTYPE_NORMAL, false);
     uid_t uid = testUser.getUid();
 
     AppInstallHelper appLocal("sm_test_121b_local", uid);
@@ -120,8 +120,8 @@ RUNNER_CHILD_TEST(security_manager_121b_repair_permissible_file_daemon_local)
 
 RUNNER_CHILD_TEST(security_manager_122a_repair_permissible_file_client_global)
 {
-    TemporaryTestUser testUser("sm_test_122a_user_name", GUM_USERTYPE_NORMAL, false);
-    testUser.create();
+    TestUser testUser =
+        TestUser::createTemporary("sm_test_122a_user_name", GUM_USERTYPE_NORMAL, false);
 
     corruptFile();
 
@@ -130,8 +130,8 @@ RUNNER_CHILD_TEST(security_manager_122a_repair_permissible_file_client_global)
 
 RUNNER_CHILD_TEST(security_manager_122b_repair_permissible_file_client_local)
 {
-    TemporaryTestUser testUser("sm_test_122b_user_name", GUM_USERTYPE_NORMAL, false);
-    testUser.create();
+    TestUser testUser =
+        TestUser::createTemporary("sm_test_122b_user_name", GUM_USERTYPE_NORMAL, false);
 
     corruptFile(testUser.getUid());
 
@@ -140,8 +140,8 @@ RUNNER_CHILD_TEST(security_manager_122b_repair_permissible_file_client_local)
 
 RUNNER_CHILD_TEST(security_manager_122c_repair_permissible_file_client_both)
 {
-    TemporaryTestUser testUser("sm_test_122c_user_name", GUM_USERTYPE_NORMAL, false);
-    testUser.create();
+    TestUser testUser =
+        TestUser::createTemporary("sm_test_122c_user_name", GUM_USERTYPE_NORMAL, false);
 
     corruptFile();
     corruptFile(testUser.getUid());
index f201bc10bc229f303a4e6f4be8132342dd485d32..174e2d7dc09496bad2e11d50431015169b2a3872 100644 (file)
@@ -214,8 +214,8 @@ RUNNER_TEST_GROUP_INIT(SECURITY_MANAGER_PREPARE_APP)
 
 RUNNER_CHILD_TEST(security_manager_100_synchronize_credentials_test)
 {
-    TemporaryTestUser tmpUser(APP_TEST_USER, GUM_USERTYPE_NORMAL, false);
-    tmpUser.create();
+    TestUser tmpUser =
+        TestUser::createTemporary(APP_TEST_USER, GUM_USERTYPE_NORMAL, false);
 
     AppInstallHelper app("app100", tmpUser.getUid());
     app.setAuthor("author");
@@ -245,8 +245,8 @@ RUNNER_CHILD_TEST(security_manager_100_synchronize_credentials_test)
 
 RUNNER_CHILD_TEST(security_manager_100_synchronize_credentials_no_author_test)
 {
-    TemporaryTestUser tmpUser(APP_TEST_USER, GUM_USERTYPE_NORMAL, false);
-    tmpUser.create();
+    TestUser tmpUser =
+        TestUser::createTemporary(APP_TEST_USER, GUM_USERTYPE_NORMAL, false);
 
     AppInstallHelper app("app100", tmpUser.getUid());
     ScopedInstaller appInstall(app);
@@ -275,8 +275,8 @@ RUNNER_CHILD_TEST(security_manager_100_synchronize_credentials_no_author_test)
 
 RUNNER_CHILD_TEST(security_manager_101_create_namespace_test_n)
 {
-    TemporaryTestUser tmpUser(APP_TEST_USER, GUM_USERTYPE_NORMAL, false);
-    tmpUser.create();
+    TestUser tmpUser =
+        TestUser::createTemporary(APP_TEST_USER, GUM_USERTYPE_NORMAL, false);
 
     AppInstallHelper app("app100_n", tmpUser.getUid());
     app.setAuthor("author");
@@ -303,8 +303,8 @@ RUNNER_CHILD_TEST(security_manager_101_create_namespace_test_n)
 
 RUNNER_CHILD_TEST(security_manager_101_create_namespace_test_p)
 {
-    TemporaryTestUser tmpUser(APP_TEST_USER, GUM_USERTYPE_NORMAL, false);
-    tmpUser.create();
+    TestUser tmpUser =
+        TestUser::createTemporary(APP_TEST_USER, GUM_USERTYPE_NORMAL, false);
 
     AppInstallHelper app("app101", tmpUser.getUid());
     ScopedInstaller appInstall(app);
@@ -346,8 +346,8 @@ RUNNER_CHILD_TEST(security_manager_101_create_namespace_test_p)
 
 RUNNER_CHILD_TEST(security_manager_102_check_propagation_test)
 {
-    TemporaryTestUser tmpUser(APP_TEST_USER, GUM_USERTYPE_NORMAL, false);
-    tmpUser.create();
+    TestUser tmpUser =
+        TestUser::createTemporary(APP_TEST_USER, GUM_USERTYPE_NORMAL, false);
 
     AppInstallHelper app("app102", tmpUser.getUid());
     ScopedInstaller appInstall(app);
@@ -385,8 +385,8 @@ RUNNER_CHILD_TEST(security_manager_102_check_propagation_test)
 
 RUNNER_CHILD_TEST(security_manager_103_policy_change_test)
 {
-    TemporaryTestUser tmpUser(APP_TEST_USER, GUM_USERTYPE_NORMAL, false);
-    tmpUser.create();
+    TestUser tmpUser =
+        TestUser::createTemporary(APP_TEST_USER, GUM_USERTYPE_NORMAL, false);
 
     AppInstallHelper app("app103", tmpUser.getUid());
     app.addPrivileges({PRIV_EXTERNALSTORAGE, PRIV_MEDIASTORAGE});
@@ -453,8 +453,8 @@ RUNNER_CHILD_TEST(security_manager_103_policy_change_test)
 
 RUNNER_CHILD_TEST(security_manager_104_policy_change_kill_app_test)
 {
-    TemporaryTestUser tmpUser(APP_TEST_USER, GUM_USERTYPE_NORMAL, false);
-    tmpUser.create();
+    TestUser tmpUser =
+        TestUser::createTemporary(APP_TEST_USER, GUM_USERTYPE_NORMAL, false);
 
     AppInstallHelper app("app104", tmpUser.getUid());
     app.addPrivileges({PRIV_EXTERNALSTORAGE, PRIV_MEDIASTORAGE});
@@ -558,8 +558,8 @@ constexpr size_t arraySize(T (&)[N]) { return N; }
 
 RUNNER_CHILD_TEST(security_manager_190_prepare_app_threads_malloc)
 {
-    TemporaryTestUser tmpUser(APP_TEST_USER, GUM_USERTYPE_NORMAL, false);
-    tmpUser.create();
+    TestUser tmpUser =
+        TestUser::createTemporary(APP_TEST_USER, GUM_USERTYPE_NORMAL, false);
 
     const auto uid = tmpUser.getUid();
 
@@ -601,8 +601,8 @@ RUNNER_CHILD_TEST(security_manager_200_prepare_app_perf)
     constexpr int8_t nConcurrentAppsSamples[] = { 0 /* 1 app w/ nThreads */, 1, 2, 4, 8, 16, 32 };
     constexpr uint64_t minTotalBenchTime = 60 * 1000ULL*1000*1000; // 60s
 
-    TemporaryTestUser tmpUser(APP_TEST_USER, GUM_USERTYPE_NORMAL, false);
-    tmpUser.create();
+    TestUser tmpUser =
+        TestUser::createTemporary(APP_TEST_USER, GUM_USERTYPE_NORMAL, false);
 
     struct App {
         AppInstallHelper hlp;
@@ -712,8 +712,8 @@ RUNNER_CHILD_TEST(security_manager_200_prepare_app_perf)
 RUNNER_CHILD_TEST(security_manager_300_prepare_app_recursive_threads)
 {
     std::srand(std::time(nullptr)); // use current time as seed for random generator
-    TemporaryTestUser tmpUser(APP_TEST_USER, GUM_USERTYPE_NORMAL, false);
-    tmpUser.create();
+    TestUser tmpUser =
+        TestUser::createTemporary(APP_TEST_USER, GUM_USERTYPE_NORMAL, false);
 
     AppInstallHelper app("app300", tmpUser.getUid());
     app.addPrivileges({PRIV_EXTERNALSTORAGE, PRIV_MEDIASTORAGE});
@@ -741,8 +741,8 @@ RUNNER_CHILD_TEST(security_manager_300_prepare_app_recursive_threads)
 RUNNER_CHILD_TEST(security_manager_400_prepare_app_with_concurrent_install)
 {
     std::srand(std::time(nullptr)); // use current time as seed for random generator
-    TemporaryTestUser tmpUser(APP_TEST_USER, GUM_USERTYPE_NORMAL, false);
-    tmpUser.create();
+    TestUser tmpUser =
+        TestUser::createTemporary(APP_TEST_USER, GUM_USERTYPE_NORMAL, false);
 
     // few iterations of the test...
     for (int i = 0; i < 5; ++i) {
@@ -780,8 +780,8 @@ RUNNER_CHILD_TEST(security_manager_400_prepare_app_with_concurrent_install)
 RUNNER_CHILD_TEST(security_manager_400_prepare_app_series_with_concurrent_install_stress)
 {
     std::srand(std::time(nullptr)); // use current time as seed for random generator
-    TemporaryTestUser tmpUser(APP_TEST_USER, GUM_USERTYPE_NORMAL, false);
-    tmpUser.create();
+    TestUser tmpUser =
+        TestUser::createTemporary(APP_TEST_USER, GUM_USERTYPE_NORMAL, false);
 
     pid_t pid = runInChild([&] {
         // install an app, and in a loop - fork + launch it
index 472a512d22a76b7e9765f4a7634600178aab22e8..5dad875c8eb58cfab7a17c9c77ba21e8a1053b12 100644 (file)
@@ -36,7 +36,7 @@
 #include <sm_policy_request.h>
 #include <sm_request.h>
 #include <synchronization_pipe.h>
-#include <temp_test_user.h>
+#include <test_user.h>
 #include <tests_common.h>
 #include <privilege_names.h>
 #include <app_def_privilege.h>
@@ -82,8 +82,8 @@ RUNNER_TEST_GROUP_INIT(SECURITY_MANAGER_PRIVACY_MANAGER)
 
 RUNNER_CHILD_TEST(security_manager_10_privacy_manager_fetch_whole_policy_for_self)
 {
-    TemporaryTestUser tmpUser("sm_test_10_user_name", GUM_USERTYPE_NORMAL, false);
-    tmpUser.create();
+    TestUser tmpUser =
+        TestUser::createTemporary("sm_test_10_user_name", GUM_USERTYPE_NORMAL, false);
 
     unsigned expectedPolicyCount = 0;
     std::map<std::string, AppInstallHelper> appIdToAIH;
@@ -143,14 +143,14 @@ RUNNER_CHILD_TEST(security_manager_11_privacy_manager_fetch_whole_policy_for_adm
     const std::vector<UserInfo> userInfos = {{normalNameToSwitch, GUM_USERTYPE_NORMAL},
                                              {"sm_test_11_user_name_admin", GUM_USERTYPE_ADMIN}};
 
-    std::map<std::string, TemporaryTestUser> usernameToTTU;
+    std::map<std::string, TestUser> usernameToTTU;
     // uid + app_id -> AppInstallHelper (different users can have same app_id installed)
     std::map<std::pair<uid_t,std::string>, AppInstallHelper> userAppIdToAIH;
     unsigned expectedPolicyCount = 0;
 
     for (unsigned int u_i = 0; u_i < userInfos.size(); u_i++) {
-        TemporaryTestUser user(userInfos[u_i].userName, userInfos[u_i].userType);
-        user.create();
+        TestUser user =
+            TestUser::createTemporary(userInfos[u_i].userName, userInfos[u_i].userType);
 
         for (unsigned int p_i = 0; p_i < TEST_PRIVILEGES.size(); p_i++) {
             AppInstallHelper app("sm_test_11_" + std::to_string(p_i), user.getUid());
@@ -163,7 +163,7 @@ RUNNER_CHILD_TEST(security_manager_11_privacy_manager_fetch_whole_policy_for_adm
         usernameToTTU.emplace(userInfos[u_i].userName, std::move(user));
     };
 
-    TemporaryTestUser &normalUserToSwitch = usernameToTTU.at(normalNameToSwitch);
+    TestUser &normalUserToSwitch = usernameToTTU.at(normalNameToSwitch);
 
     AppInstallHelper privManager("sm_test_11_priv_manager", normalUserToSwitch.getUid());
     std::string privManagerAppId = privManager.getAppId();
@@ -223,15 +223,15 @@ RUNNER_CHILD_TEST(security_manager_12_privacy_manager_fetch_whole_policy_for_adm
     const std::vector<UserInfo> userInfos = {{"sm_test_12_user_name_normal",GUM_USERTYPE_NORMAL},
                                              {adminNameToSwitch, GUM_USERTYPE_ADMIN}};
 
-    std::map<std::string, TemporaryTestUser> usernameToTTU;
+    std::map<std::string, TestUser> usernameToTTU;
     std::vector<std::string> uidStrings;
     // uidstring + app_id -> AppInstallHelper
     std::map<std::pair<uid_t, std::string>, AppInstallHelper> userAppIdToAIH;
     unsigned expectedPolicyCount = oldPolicyVec.size();
 
     for (unsigned int u_i = 0; u_i < userInfos.size(); u_i++) {
-        TemporaryTestUser user(userInfos[u_i].userName, userInfos[u_i].userType);
-        user.create();
+        TestUser user =
+            TestUser::createTemporary(userInfos[u_i].userName, userInfos[u_i].userType);
         uidStrings.push_back(user.getUidString());
 
         for (unsigned int p_i = 0; p_i < TEST_PRIVILEGES.size(); p_i++) {
@@ -244,7 +244,7 @@ RUNNER_CHILD_TEST(security_manager_12_privacy_manager_fetch_whole_policy_for_adm
         usernameToTTU.emplace(user.getUserName(), std::move(user));
     };
 
-    TemporaryTestUser &adminUserToSwitch = usernameToTTU.at(adminNameToSwitch);
+    TestUser &adminUserToSwitch = usernameToTTU.at(adminNameToSwitch);
 
     AppInstallHelper privManager("sm_test_12_priv_manager", adminUserToSwitch.getUid());
     std::string privManagerAppId = privManager.getAppId();
@@ -307,15 +307,15 @@ RUNNER_CHILD_TEST(security_manager_13_privacy_manager_fetch_policy_after_update_
     const std::vector<UserInfo> userInfos = {{normalName,GUM_USERTYPE_NORMAL},
                                              {adminName, GUM_USERTYPE_ADMIN}};
 
-    std::map<std::string, TemporaryTestUser> usernameToTTU;
+    std::map<std::string, TestUser> usernameToTTU;
     std::map<uid_t, std::vector<AppInstallHelper>> uidToAIHs;
     unsigned expectedPolicyCount = 0;
     std::string privManagerAppId;
 
     for (unsigned int u_i = 0; u_i < userInfos.size(); u_i++) {
         //Only entries for one of the users will be listed
-        TemporaryTestUser user(userInfos[u_i].userName, userInfos[u_i].userType);
-        user.create();
+        TestUser user =
+            TestUser::createTemporary(userInfos[u_i].userName, userInfos[u_i].userType);
 
         for (unsigned int p_i = 0; p_i < TEST_PRIVILEGES.size(); p_i++) {
             AppInstallHelper app("sm_test_13_" + std::to_string(p_i), user.getUid());
@@ -339,8 +339,8 @@ RUNNER_CHILD_TEST(security_manager_13_privacy_manager_fetch_policy_after_update_
         scopedInstallations.emplace_back(ScopedInstaller(aih));
     }
 
-    TemporaryTestUser &adminUser = usernameToTTU.at(adminName);
-    TemporaryTestUser &normalUser = usernameToTTU.at(normalName);
+    TestUser &adminUser = usernameToTTU.at(adminName);
+    TestUser &normalUser = usernameToTTU.at(normalName);
 
     runInChildParentWait([&] {
         Api::setAppProcessIdentity(privManagerAppId);
@@ -400,8 +400,8 @@ RUNNER_CHILD_TEST(security_manager_13_privacy_manager_fetch_policy_after_update_
 
 RUNNER_CHILD_TEST(security_manager_14_privacy_manager_fetch_and_update_policy_for_admin)
 {
-    TemporaryTestUser adminUserToSwitch("sm_test_14_user_name_admin", GUM_USERTYPE_ADMIN);
-    adminUserToSwitch.create();
+    TestUser adminUserToSwitch =
+        TestUser::createTemporary("sm_test_14_user_name_admin", GUM_USERTYPE_ADMIN);
 
     AppInstallHelper privManager("sm_test_14_priv_manager", adminUserToSwitch.getUid());
     privManager.addPrivilege(ADMIN_PRIVILEGE);
@@ -452,8 +452,8 @@ RUNNER_CHILD_TEST(security_manager_15_privacy_manager_send_policy_update_for_adm
 {
     const std::string& updatePriv = PRIV_LED;
 
-    TemporaryTestUser adminUser("sm_test_15_username", GUM_USERTYPE_ADMIN);
-    adminUser.create();
+    TestUser adminUser =
+        TestUser::createTemporary("sm_test_15_username", GUM_USERTYPE_ADMIN);
 
     AppInstallHelper updatedApp("security_manager_15_update");
     ScopedInstaller updatedAppInstall(updatedApp);
@@ -485,8 +485,8 @@ RUNNER_CHILD_TEST(security_manager_15_privacy_manager_send_policy_update_for_adm
 {
     const std::string& updatePriv = PRIV_LED;
 
-    TemporaryTestUser adminUser("sm_test_15_username", GUM_USERTYPE_ADMIN);
-    adminUser.create();
+    TestUser adminUser =
+        TestUser::createTemporary("sm_test_15_username", GUM_USERTYPE_ADMIN);
 
     AppInstallHelper app("security_manager_15");
     ScopedInstaller appInstall(app);
@@ -518,8 +518,8 @@ RUNNER_CHILD_TEST(security_manager_15_privacy_manager_send_policy_update_for_sel
 {
     const std::string& updatePriv = PRIV_LED;
 
-    TemporaryTestUser user("sm_test_15_username", GUM_USERTYPE_NORMAL);
-    user.create();
+    TestUser user =
+        TestUser::createTemporary("sm_test_15_username", GUM_USERTYPE_NORMAL);
 
     AppInstallHelper app("security_manager_15");
     ScopedInstaller appInstall(app);
@@ -548,8 +548,8 @@ RUNNER_CHILD_TEST(security_manager_15_privacy_manager_send_policy_update_for_sel
 
 RUNNER_CHILD_TEST(security_manager_16_policy_levels_get)
 {
-    TemporaryTestUser user("sm_test_16_user_name", GUM_USERTYPE_NORMAL);
-    user.create();
+    TestUser user =
+        TestUser::createTemporary("sm_test_16_user_name", GUM_USERTYPE_NORMAL);
 
     runInChildParentWait([&] {
         RUNNER_ASSERT_ERRNO_MSG(drop_root_privileges(user.getUid(), user.getGid()) == 0,
@@ -583,8 +583,8 @@ RUNNER_CHILD_TEST(security_manager_17a_privacy_manager_delete_policy_for_self)
 {
     const std::string& updatePriv = PRIV_LED;
 
-    TemporaryTestUser user("sm_test_17a_username", GUM_USERTYPE_NORMAL);
-    user.create();
+    TestUser user =
+        TestUser::createTemporary("sm_test_17a_username", GUM_USERTYPE_NORMAL);
 
     AppInstallHelper app("security_manager_17a");
     ScopedInstaller appInstall(app);
@@ -631,8 +631,8 @@ RUNNER_CHILD_TEST(security_manager_17b_privacy_manager_delete_policy_for_self)
 {
     const std::string& updatePriv = PRIV_LED;
 
-    TemporaryTestUser user("sm_test_17b_username", GUM_USERTYPE_NORMAL);
-    user.create();
+    TestUser user =
+        TestUser::createTemporary("sm_test_17b_username", GUM_USERTYPE_NORMAL);
 
     AppInstallHelper app("security_manager_17b");
     ScopedInstaller appInstall(app);
@@ -685,8 +685,8 @@ RUNNER_CHILD_TEST(security_manager_17_privacy_manager_fetch_whole_policy_for_sel
     std::map<std::string, unsigned> privToCount;
     unsigned policyCount = 0;
 
-    TemporaryTestUser user(username, static_cast<GumUserType>(GUM_USERTYPE_NORMAL), false);
-    user.create();
+    TestUser user =
+        TestUser::createTemporary(username, GUM_USERTYPE_NORMAL, false);
 
     for (unsigned int i = 0; i < TEST_PRIVILEGES.size(); i++) {
         AppInstallHelper app("sm_test_17_" + std::to_string(i), user.getUid());
@@ -746,8 +746,8 @@ RUNNER_CHILD_TEST(security_manager_17_privacy_manager_fetch_whole_policy_for_sel
 
 RUNNER_CHILD_TEST(security_manager_18_privacy_manager_privacy_related_privileges_policy_install_remove)
 {
-    TemporaryTestUser user("sm_test_18_username", GUM_USERTYPE_NORMAL);
-    user.create();
+    TestUser user =
+        TestUser::createTemporary("sm_test_18_username", GUM_USERTYPE_NORMAL);
 
     AppInstallHelper app("sm_test_18", user.getUid());
     app.addPrivileges(TEST_PRIVACY_PRIVILEGES[0]);
@@ -788,8 +788,8 @@ RUNNER_CHILD_TEST(security_manager_18_privacy_manager_privacy_related_privileges
 }
 
 void test_privacy_related_privileges(bool isHybrid) {
-    TemporaryTestUser user("sm_test_19_username", GUM_USERTYPE_NORMAL);
-    user.create();
+    TestUser user =
+        TestUser::createTemporary("sm_test_19_username", GUM_USERTYPE_NORMAL);
 
     const std::string pkgId = "sm_test_19_pkg_id";
 
@@ -855,8 +855,8 @@ RUNNER_CHILD_TEST(security_manager_19b_privacy_manager_privacy_related_privilege
 
 RUNNER_CHILD_TEST(security_manager_20_privacy_manager_privacy_related_privileges_policy_admin_check)
 {
-    TemporaryTestUser user("sm_test_20_username", GUM_USERTYPE_NORMAL);
-    user.create();
+    TestUser user =
+        TestUser::createTemporary("sm_test_20_username", GUM_USERTYPE_NORMAL);
 
     AppInstallHelper app("sm_test_20", user.getUid());
     app.addPrivileges(TEST_PRIVACY_PRIVILEGES[0]);
@@ -899,8 +899,8 @@ RUNNER_CHILD_TEST(security_manager_22_fetch_app_manifest_no_app)
 
 RUNNER_CHILD_TEST(security_manager_23_fetch_app_manifest_invalid_user)
 {
-    TemporaryTestUser user("sm_test_23_fetch_username", GUM_USERTYPE_NORMAL);
-    user.create();
+    TestUser user =
+        TestUser::createTemporary("sm_test_23_fetch_username", GUM_USERTYPE_NORMAL);
 
     AppInstallHelper app("security_manager_23_fetch", user.getUid());
     app.setInstallType(SM_APP_INSTALL_LOCAL);
@@ -927,8 +927,8 @@ static void check_privileges_from_manifest(const AppInstallHelper &aih, char **p
 
 RUNNER_CHILD_TEST(security_manager_24_fetch_app_manifest_global_app)
 {
-    TemporaryTestUser user("sm_test_24_fetch_username", GUM_USERTYPE_NORMAL);
-    user.create();
+    TestUser user =
+        TestUser::createTemporary("sm_test_24_fetch_username", GUM_USERTYPE_NORMAL);
 
     AppInstallHelper app("security_manager_24_fetch");
     app.setInstallType(SM_APP_INSTALL_GLOBAL);
@@ -953,8 +953,8 @@ RUNNER_CHILD_TEST(security_manager_24_fetch_app_manifest_global_app)
 
 RUNNER_CHILD_TEST(security_manager_25_fetch_app_manifest_local_app)
 {
-    TemporaryTestUser user("sm_test_25_fetch_username", GUM_USERTYPE_NORMAL);
-    user.create();
+    TestUser user =
+        TestUser::createTemporary("sm_test_25_fetch_username", GUM_USERTYPE_NORMAL);
 
     AppInstallHelper app("security_manager_25_fetch", user.getUid());
     app.setInstallType(SM_APP_INSTALL_LOCAL);
@@ -978,8 +978,8 @@ RUNNER_CHILD_TEST(security_manager_25_fetch_app_manifest_local_app)
 
 RUNNER_CHILD_TEST(security_manager_26_fetch_app_manifest_both_apps)
 {
-    TemporaryTestUser user("sm_test_26_fetch_username", GUM_USERTYPE_NORMAL);
-    user.create();
+    TestUser user =
+        TestUser::createTemporary("sm_test_26_fetch_username", GUM_USERTYPE_NORMAL);
 
     AppInstallHelper appGlobal("security_manager_26_fetch");
     appGlobal.setInstallType(SM_APP_INSTALL_GLOBAL);
@@ -1009,8 +1009,8 @@ RUNNER_CHILD_TEST(security_manager_26_fetch_app_manifest_both_apps)
 
 RUNNER_CHILD_TEST(security_manager_27_fetch_app_manifest_app_context_local_positive)
 {
-    TemporaryTestUser user("sm_test_27_fetch_username", GUM_USERTYPE_NORMAL);
-    user.create();
+    TestUser user =
+        TestUser::createTemporary("sm_test_27_fetch_username", GUM_USERTYPE_NORMAL);
 
     AppInstallHelper app("security_manager_27_fetch", user.getUid());
     app.setInstallType(SM_APP_INSTALL_LOCAL);
@@ -1033,8 +1033,8 @@ RUNNER_CHILD_TEST(security_manager_27_fetch_app_manifest_app_context_local_posit
 
 RUNNER_CHILD_TEST(security_manager_28_fetch_app_manifest_app_context_global_positive)
 {
-    TemporaryTestUser user("sm_test_28_fetch_username", GUM_USERTYPE_NORMAL);
-    user.create();
+    TestUser user =
+        TestUser::createTemporary("sm_test_28_fetch_username", GUM_USERTYPE_NORMAL);
 
     AppInstallHelper app("security_manager_28_fetch");
     app.setInstallType(SM_APP_INSTALL_GLOBAL);
@@ -1057,11 +1057,11 @@ RUNNER_CHILD_TEST(security_manager_28_fetch_app_manifest_app_context_global_posi
 
 RUNNER_CHILD_TEST(security_manager_29_fetch_app_manifest_app_context_local_different_uid)
 {
-    TemporaryTestUser user("sm_test_29_fetch_username", GUM_USERTYPE_NORMAL);
-    user.create();
+    TestUser user =
+        TestUser::createTemporary("sm_test_29_fetch_username", GUM_USERTYPE_NORMAL);
 
-    TemporaryTestUser user1("sm_test_29_fetch_username_1", GUM_USERTYPE_NORMAL);
-    user1.create();
+    TestUser user1 =
+        TestUser::createTemporary("sm_test_29_fetch_username_1", GUM_USERTYPE_NORMAL);
 
     AppInstallHelper app("security_manager_29_fetch", user.getUid());
     app.setInstallType(SM_APP_INSTALL_LOCAL);
@@ -1094,8 +1094,8 @@ RUNNER_CHILD_TEST(security_manager_29_fetch_app_manifest_app_context_local_diffe
 
 RUNNER_CHILD_TEST(security_manager_30_fetch_app_manifest_app_context_local_different_label)
 {
-    TemporaryTestUser user("sm_test_30_fetch_username", GUM_USERTYPE_NORMAL);
-    user.create();
+    TestUser user =
+        TestUser::createTemporary("sm_test_30_fetch_username", GUM_USERTYPE_NORMAL);
 
     AppInstallHelper app("security_manager_30_fetch", user.getUid());
     app.setInstallType(SM_APP_INSTALL_LOCAL);
@@ -1128,8 +1128,8 @@ RUNNER_CHILD_TEST(security_manager_30_fetch_app_manifest_app_context_local_diffe
 
 RUNNER_CHILD_TEST(security_manager_31_fetch_app_manifest_app_context_local_different_label_with_privilege)
 {
-    TemporaryTestUser user("sm_test_31_fetch_username", GUM_USERTYPE_ADMIN);
-    user.create();
+    TestUser user =
+        TestUser::createTemporary("sm_test_31_fetch_username", GUM_USERTYPE_ADMIN);
 
     AppInstallHelper app("security_manager_31_fetch", user.getUid());
     app.setInstallType(SM_APP_INSTALL_LOCAL);
index 7592f4e2b833b4797360449737d1a89209b16662..2a70ab3ea15505248ee3eae40eb6328c05636866 100644 (file)
@@ -32,9 +32,6 @@ using namespace SecurityManagerTest;
 
 namespace {
 
-const uid_t OWNER_UID = 5001;
-const uid_t OWNER_GID = 100;
-
 const std::vector<std::string> versions = {
         "2.4",
         "3.0"
@@ -52,6 +49,11 @@ VersionCombinations makeVersionCombinations(const std::vector<std::string> &vers
 
 const VersionCombinations versionCombinations = makeVersionCombinations(versions);
 
+const TestUser& ownerUser() {
+    static const auto &user = TestUser::getSystemUser(SystemUser::OWNER);
+    return user;
+}
+
 } //anonymous namespace
 
 RUNNER_TEST_GROUP_INIT(SECURITY_MANAGER_SHARED_RO)
@@ -60,27 +62,33 @@ RUNNER_TEST_GROUP_INIT(SECURITY_MANAGER_SHARED_RO)
  */
 RUNNER_CHILD_TEST(security_manager_76_owner_access)
 {
+    auto &owner = ownerUser();
+    auto ownerUid = owner.getUid();
+
     for (const auto &version : versions) {
-        AppInstallHelper app("sm_test_76a", OWNER_UID, version);
+        AppInstallHelper app("sm_test_76a", ownerUid, version);
         app.createSharedRODir();
         ScopedInstaller sharedROPkgApp(app);
 
-        runAccessTest(app, app.getSharedRODir(), OWNER_UID, OWNER_GID, R_OK|W_OK|X_OK);
+        runAccessTest(app, owner, app.getSharedRODir(), R_OK|W_OK|X_OK);
     }
 }
 
 RUNNER_CHILD_TEST(security_manager_7x_test)
 {
-    AppInstallHelper ownerApp("owner_7x", OWNER_UID);
+    auto &owner = ownerUser();
+    auto ownerUid = owner.getUid();
+
+    AppInstallHelper ownerApp("owner_7x", ownerUid);
     ownerApp.createSharedRODir();
     ScopedInstaller ownerAppInstall(ownerApp);
 
-    AppInstallHelper otherApp("other_7x", OWNER_UID);
+    AppInstallHelper otherApp("other_7x", ownerUid);
     otherApp.createSharedRODir();
     ScopedInstaller otherAppInstall(otherApp);
 
-    runAccessTest(ownerApp, ownerApp.getSharedRODir(), OWNER_UID, OWNER_GID, R_OK | W_OK | X_OK);
-    runAccessTest(ownerApp, otherApp.getSharedRODir(), OWNER_UID, OWNER_GID, R_OK | X_OK);
+    runAccessTest(ownerApp, owner, ownerApp.getSharedRODir(), R_OK | W_OK | X_OK);
+    runAccessTest(ownerApp, owner, otherApp.getSharedRODir(), R_OK | X_OK);
 }
 
 /**
@@ -90,19 +98,22 @@ RUNNER_CHILD_TEST(security_manager_7x_test)
  */
 RUNNER_CHILD_TEST(security_manager_77_owner_other_access_version_combinations)
 {
+    auto &owner = ownerUser();
+    auto ownerUid = owner.getUid();
+
     for (const auto &version : versionCombinations) {
-        AppInstallHelper sharedApp("sm_test_77_shared", OWNER_UID, version.first);
+        AppInstallHelper sharedApp("sm_test_77_shared", ownerUid, version.first);
         sharedApp.createSharedRODir();
         sharedApp.createPrivateDir();
         ScopedInstaller sharedAppInstall(sharedApp);
 
-        AppInstallHelper nonSharedApp("sm_test_77_nonshared", OWNER_UID, version.second);
+        AppInstallHelper nonSharedApp("sm_test_77_nonshared", ownerUid, version.second);
         ScopedInstaller nonSharedAppInstall(nonSharedApp);
 
-        runAccessTest(sharedApp, sharedApp.getSharedRODir(), OWNER_UID, OWNER_GID, R_OK|W_OK|X_OK);
+        runAccessTest(sharedApp, owner, sharedApp.getSharedRODir(), R_OK|W_OK|X_OK);
 
-        runAccessTest(nonSharedApp, sharedApp.getPrivateDir(), OWNER_UID, OWNER_GID, 0);
-        runAccessTest(nonSharedApp, sharedApp.getSharedRODir(), OWNER_UID, OWNER_GID, R_OK|X_OK);
+        runAccessTest(nonSharedApp, owner, sharedApp.getPrivateDir(), 0);
+        runAccessTest(nonSharedApp, owner, sharedApp.getSharedRODir(), R_OK|X_OK);
     }
 }
 
@@ -113,24 +124,27 @@ RUNNER_CHILD_TEST(security_manager_77_owner_other_access_version_combinations)
  */
 RUNNER_CHILD_TEST(security_manager_78_another_pkg_shared_ro_have_ro_access_to_shared_ro)
 {
+    auto &owner = ownerUser();
+    auto ownerUid = owner.getUid();
+
     for (const auto &version : versionCombinations) {
-        AppInstallHelper sharedApp1("sm_test_78_shared1", OWNER_UID, version.first);
+        AppInstallHelper sharedApp1("sm_test_78_shared1", ownerUid, version.first);
         sharedApp1.createSharedRODir();
         sharedApp1.createPrivateDir();
         ScopedInstaller sharedAppInstall1(sharedApp1);
 
-        AppInstallHelper sharedApp2("sm_test_78_shared2", OWNER_UID, version.second);
+        AppInstallHelper sharedApp2("sm_test_78_shared2", ownerUid, version.second);
         sharedApp2.createSharedRODir();
         sharedApp2.createPrivateDir();
         ScopedInstaller sharedApp2Install(sharedApp2);
 
-        runAccessTest(sharedApp1, sharedApp2.getSharedRODir(), OWNER_UID, OWNER_GID, R_OK|X_OK);
-        runAccessTest(sharedApp1, sharedApp1.getSharedRODir(), OWNER_UID, OWNER_GID, R_OK|W_OK|X_OK);
-        runAccessTest(sharedApp1, sharedApp2.getPrivateDir(),  OWNER_UID, OWNER_GID, 0);
+        runAccessTest(sharedApp1, owner, sharedApp2.getSharedRODir(), R_OK|X_OK);
+        runAccessTest(sharedApp1, owner, sharedApp1.getSharedRODir(), R_OK|W_OK|X_OK);
+        runAccessTest(sharedApp1, owner, sharedApp2.getPrivateDir(),  0);
 
-        runAccessTest(sharedApp2, sharedApp1.getSharedRODir(), OWNER_UID, OWNER_GID, R_OK|X_OK);
-        runAccessTest(sharedApp2, sharedApp2.getSharedRODir(), OWNER_UID, OWNER_GID, R_OK|W_OK|X_OK);
-        runAccessTest(sharedApp2, sharedApp1.getPrivateDir(),  OWNER_UID, OWNER_GID, 0);
+        runAccessTest(sharedApp2, owner, sharedApp1.getSharedRODir(), R_OK|X_OK);
+        runAccessTest(sharedApp2, owner, sharedApp2.getSharedRODir(), R_OK|W_OK|X_OK);
+        runAccessTest(sharedApp2, owner, sharedApp1.getPrivateDir(),  0);
     }
 }
 
@@ -141,19 +155,20 @@ RUNNER_CHILD_TEST(security_manager_78_another_pkg_shared_ro_have_ro_access_to_sh
 RUNNER_CHILD_TEST(security_manager_79a_same_pkg_shared_ro_have_ro_access_to_shared_ro)
 {
     const std::string sharedPkgName = "sm_test_79a";
+    auto &owner = ownerUser();
+    auto ownerUid = owner.getUid();
 
     for (const auto &version : versions) {
-        AppInstallHelper sharedApp1("sm_test_79a_shared1", sharedPkgName, OWNER_UID, version);
+        AppInstallHelper sharedApp1("sm_test_79a_shared1", sharedPkgName, ownerUid, version);
         sharedApp1.createSharedRODir();
         ScopedInstaller sharedAppInstall1(sharedApp1);
 
-        AppInstallHelper sharedApp2("sm_test_79a_shared2", sharedPkgName, OWNER_UID, version);
+        AppInstallHelper sharedApp2("sm_test_79a_shared2", sharedPkgName, ownerUid, version);
         sharedApp2.createSharedRODir();
         ScopedInstaller sharedAppInstall2(sharedApp2);
 
-
-        runAccessTest(sharedApp1, sharedApp2.getSharedRODir(), OWNER_UID, OWNER_GID, R_OK|W_OK|X_OK);
-        runAccessTest(sharedApp2, sharedApp1.getSharedRODir(), OWNER_UID, OWNER_GID, R_OK|W_OK|X_OK);
+        runAccessTest(sharedApp1, owner, sharedApp2.getSharedRODir(), R_OK|W_OK|X_OK);
+        runAccessTest(sharedApp2, owner, sharedApp1.getSharedRODir(), R_OK|W_OK|X_OK);
     }
 }
 
@@ -164,17 +179,18 @@ RUNNER_CHILD_TEST(security_manager_79a_same_pkg_shared_ro_have_ro_access_to_shar
 RUNNER_CHILD_TEST(security_manager_79b_same_pkg_shared_ro_have_ro_access_to_shared_ro)
 {
     const std::string sharedPkgName = "sm_test_79b";
+    auto &owner = ownerUser();
+    auto ownerUid = owner.getUid();
 
     for (const auto &version : versions) {
-        AppInstallHelper sharedApp("sm_test_79b_shared1", sharedPkgName, OWNER_UID, version);
+        AppInstallHelper sharedApp("sm_test_79b_shared1", sharedPkgName, ownerUid, version);
         sharedApp.createSharedRODir();
         ScopedInstaller sharedAppInstall(sharedApp);
 
-        AppInstallHelper nonSharedApp("sm_test_79b_shared2", sharedPkgName, OWNER_UID, version);
+        AppInstallHelper nonSharedApp("sm_test_79b_shared2", sharedPkgName, ownerUid, version);
         ScopedInstaller nonSharedAppInstall(nonSharedApp);
 
-        runAccessTest(nonSharedApp, sharedApp.getSharedRODir(),
-                      OWNER_UID, OWNER_GID, R_OK|W_OK|X_OK);
+        runAccessTest(nonSharedApp, owner, sharedApp.getSharedRODir(), R_OK|W_OK|X_OK);
     }
 }
 
@@ -186,36 +202,34 @@ RUNNER_CHILD_TEST(security_manager_79b_same_pkg_shared_ro_have_ro_access_to_shar
 RUNNER_CHILD_TEST(security_manager_80_same_pkg_shared_ro_have_no_access_to_shared_ro_app_ro_dir)
 {
     std::string sharedPkgName = "sm_test_80";
+    auto &owner = ownerUser();
+    auto ownerUid = owner.getUid();
+
     for (const auto &version : versions) {
-        AppInstallHelper sharedApp1("sm_test_80_shared1", sharedPkgName, OWNER_UID, version);
+        AppInstallHelper sharedApp1("sm_test_80_shared1", sharedPkgName, ownerUid, version);
         sharedApp1.createPrivateDir(1);
         sharedApp1.createSharedRODir(1);
         ScopedInstaller sharedAppInstall1(sharedApp1);
 
-        AppInstallHelper sharedApp2("sm_test_80_shared2", sharedPkgName, OWNER_UID, version);
+        AppInstallHelper sharedApp2("sm_test_80_shared2", sharedPkgName, ownerUid, version);
         sharedApp2.createPrivateDir(2);
         sharedApp2.createSharedRODir(2);
         ScopedInstaller sharedAppInstall2(sharedApp2);
 
-        AppInstallHelper nonSharedApp("sm_test_80_nonshared", sharedPkgName, OWNER_UID, version);
+        AppInstallHelper nonSharedApp("sm_test_80_nonshared", sharedPkgName, owner.getUid(), version);
         ScopedInstaller nonSharedAppInstall(nonSharedApp);
 
-        runAccessTest(sharedApp1, sharedApp2.getPrivateDir(2),
-                      OWNER_UID, OWNER_GID, R_OK|W_OK|X_OK);
-        runAccessTest(sharedApp2, sharedApp1.getPrivateDir(1),
-                      OWNER_UID, OWNER_GID, R_OK|W_OK|X_OK);
+        runAccessTest(sharedApp1, owner, sharedApp2.getPrivateDir(2), R_OK|W_OK|X_OK);
+        runAccessTest(sharedApp2, owner, sharedApp1.getPrivateDir(1), R_OK|W_OK|X_OK);
 
 
-        runAccessTest(nonSharedApp, sharedApp1.getPrivateDir(1),
-                      OWNER_UID, OWNER_GID, R_OK|W_OK|X_OK);
-        runAccessTest(nonSharedApp, sharedApp2.getPrivateDir(2),
-                      OWNER_UID, OWNER_GID, R_OK|W_OK|X_OK);
+        runAccessTest(nonSharedApp, owner, sharedApp1.getPrivateDir(1), R_OK|W_OK|X_OK);
+        runAccessTest(nonSharedApp, owner, sharedApp2.getPrivateDir(2), R_OK|W_OK|X_OK);
 
 
         sharedAppInstall1.uninstallApp();
 
-        runAccessTest(nonSharedApp, sharedApp2.getPrivateDir(2),
-                      OWNER_UID, OWNER_GID, R_OK|W_OK|X_OK);
+        runAccessTest(nonSharedApp, owner, sharedApp2.getPrivateDir(2), R_OK|W_OK|X_OK);
     }
 }
 
@@ -224,16 +238,19 @@ RUNNER_CHILD_TEST(security_manager_80_same_pkg_shared_ro_have_no_access_to_share
  */
 RUNNER_CHILD_TEST(security_manager_81_add_path_to_app_and_check_all)
 {
+    auto &owner = ownerUser();
+    auto ownerUid = owner.getUid();
+
     for (const auto &version : versionCombinations) {
-        AppInstallHelper sharedApp("sm_test_83_shared1", OWNER_UID, version.first);
+        AppInstallHelper sharedApp("sm_test_83_shared1", ownerUid, version.first);
         sharedApp.createPrivateDir();
         sharedApp.createSharedRODir();
         ScopedInstaller sharedAppInstall(sharedApp);
 
-        AppInstallHelper nonSharedApp("sm_test_83_nonshared", OWNER_UID, version.first);
+        AppInstallHelper nonSharedApp("sm_test_83_nonshared", ownerUid, version.first);
         ScopedInstaller nonSharedAppInstall(nonSharedApp);
 
-        AppInstallHelper sharedApp2("sm_test_83_shared2", OWNER_UID, version.second);
+        AppInstallHelper sharedApp2("sm_test_83_shared2", ownerUid, version.second);
         ScopedInstaller nonSharedAppInstall2(sharedApp2);
 
         //Post install
@@ -246,20 +263,16 @@ RUNNER_CHILD_TEST(security_manager_81_add_path_to_app_and_check_all)
         Api::registerPaths(sharedRORequest);
 
 
-        runAccessTest(sharedApp, sharedApp.getSharedRODir(), OWNER_UID, OWNER_GID, R_OK|W_OK|X_OK);
-        runAccessTest(sharedApp, sharedApp.getPrivateDir(), OWNER_UID, OWNER_GID, R_OK|W_OK|X_OK);
+        runAccessTest(sharedApp, owner, sharedApp.getSharedRODir(), R_OK|W_OK|X_OK);
+        runAccessTest(sharedApp, owner, sharedApp.getPrivateDir(), R_OK|W_OK|X_OK);
 
-        runAccessTest(sharedApp2, sharedApp2.getSharedRODir(),
-                      OWNER_UID, OWNER_GID, R_OK|W_OK|X_OK);
-        runAccessTest(sharedApp2, sharedApp.getSharedRODir(),
-                      OWNER_UID, OWNER_GID, R_OK|X_OK);
-        runAccessTest(sharedApp2, sharedApp.getPrivateDir(), OWNER_UID, OWNER_GID, 0);
+        runAccessTest(sharedApp2, owner, sharedApp2.getSharedRODir(), R_OK|W_OK|X_OK);
+        runAccessTest(sharedApp2, owner, sharedApp.getSharedRODir(), R_OK|X_OK);
+        runAccessTest(sharedApp2, owner, sharedApp.getPrivateDir(), 0);
 
-        runAccessTest(nonSharedApp, sharedApp.getSharedRODir(),
-                      OWNER_UID, OWNER_GID, R_OK|X_OK);
-        runAccessTest(nonSharedApp, sharedApp2.getSharedRODir(),
-                      OWNER_UID, OWNER_GID, R_OK|X_OK);
-        runAccessTest(nonSharedApp, sharedApp.getPrivateDir(), OWNER_UID, OWNER_GID, 0);
+        runAccessTest(nonSharedApp, owner, sharedApp.getSharedRODir(), R_OK|X_OK);
+        runAccessTest(nonSharedApp, owner, sharedApp2.getSharedRODir(), R_OK|X_OK);
+        runAccessTest(nonSharedApp, owner, sharedApp.getPrivateDir(), 0);
     }
 }
 
@@ -268,12 +281,15 @@ RUNNER_CHILD_TEST(security_manager_81_add_path_to_app_and_check_all)
  */
 RUNNER_CHILD_TEST(security_manager_82_add_invalid_path_to_app_and_check_all)
 {
+    auto &owner = ownerUser();
+    auto ownerUid = owner.getUid();
+
     for (const auto &version : versionCombinations) {
-        AppInstallHelper sharedApp("sm_test_84_shared", OWNER_UID, version.first);
+        AppInstallHelper sharedApp("sm_test_84_shared", ownerUid, version.first);
         sharedApp.createSharedRODir();
         ScopedInstaller sharedAppInstall(sharedApp);
 
-        AppInstallHelper nonSharedApp("sm_test_84_nonshared", OWNER_UID, version.second);
+        AppInstallHelper nonSharedApp("sm_test_84_nonshared", ownerUid, version.second);
         ScopedInstaller nonSharedAppInstall(nonSharedApp);
 
         PathsRequest sharedRORequest;
@@ -289,27 +305,29 @@ RUNNER_CHILD_TEST(security_manager_82_add_invalid_path_to_app_and_check_all)
  */
 RUNNER_CHILD_TEST(security_manager_83_install_uninstall_shared_ro_app_and_check_cleaning)
 {
+    auto &owner = ownerUser();
+    auto ownerUid = owner.getUid();
+
     for (const auto &verComb : versionCombinations) {
-        AppInstallHelper sharedApp1("sm_test_85_shared1", OWNER_UID, verComb.first);
+        AppInstallHelper sharedApp1("sm_test_85_shared1", ownerUid, verComb.first);
         sharedApp1.createSharedRODir();
         ScopedInstaller sharedAppInstall1(sharedApp1);
 
-        AppInstallHelper sharedApp2("sm_test_85_shared2", OWNER_UID, verComb.second);
+        AppInstallHelper sharedApp2("sm_test_85_shared2", ownerUid, verComb.second);
         sharedApp2.createSharedRODir();
         ScopedInstaller sharedAppInstall2(sharedApp2);
 
-        AppInstallHelper nonSharedApp("sm_test_85_nonshared", OWNER_UID, verComb.second);
+        AppInstallHelper nonSharedApp("sm_test_85_nonshared", owner.getUid(), verComb.second);
         ScopedInstaller nonSharedAppInstall(nonSharedApp);
 
         sharedAppInstall1.uninstallApp();
         sharedApp1.removePaths();
 
+        runAccessTest(nonSharedApp, owner, sharedApp1.getSharedRODir(), 0);
+        runAccessTest(nonSharedApp, owner, sharedApp2.getSharedRODir(), R_OK|X_OK);
 
-        runAccessTest(nonSharedApp, sharedApp1.getSharedRODir(), OWNER_UID, OWNER_GID, 0);
-        runAccessTest(nonSharedApp, sharedApp2.getSharedRODir(), OWNER_UID, OWNER_GID, R_OK|X_OK);
-
-        runAccessTest(sharedApp2, sharedApp1.getSharedRODir(), OWNER_UID, OWNER_GID, 0);
-        runAccessTest(sharedApp2, sharedApp2.getSharedRODir(), OWNER_UID, OWNER_GID, R_OK|W_OK|X_OK);
+        runAccessTest(sharedApp2, owner, sharedApp1.getSharedRODir(), 0);
+        runAccessTest(sharedApp2, owner, sharedApp2.getSharedRODir(), R_OK|W_OK|X_OK);
     }
 }
 
@@ -320,24 +338,25 @@ RUNNER_CHILD_TEST(security_manager_83_install_uninstall_shared_ro_app_and_check_
 RUNNER_CHILD_TEST(security_manager_84_install_uninstall_shared_ro_two_apps_in_one_pkg)
 {
     std::string sharedPkgName = "sm_test_86";
+    auto &owner = ownerUser();
+    auto ownerUid = owner.getUid();
 
     for (const auto &version : versionCombinations) {
-        AppInstallHelper nonSharedApp("sm_test_86_nonshared", OWNER_UID, version.first);
+        AppInstallHelper nonSharedApp("sm_test_86_nonshared", ownerUid, version.first);
         ScopedInstaller nonSharedAppInstall(nonSharedApp);
 
         // Apps from the same package
-        AppInstallHelper sharedApp1("sm_test_86_shared1", sharedPkgName, OWNER_UID, version.second);
+        AppInstallHelper sharedApp1("sm_test_86_shared1", sharedPkgName, ownerUid, version.second);
         sharedApp1.createSharedRODir(1);
         ScopedInstaller sharedAppInstall1(sharedApp1);
 
-        AppInstallHelper sharedApp2("sm_test_86_shared2", sharedPkgName, OWNER_UID, version.second);
+        AppInstallHelper sharedApp2("sm_test_86_shared2", sharedPkgName, ownerUid, version.second);
         sharedApp2.createSharedRODir(2);
         ScopedInstaller sharedAppInstall2(sharedApp2);
 
         sharedAppInstall1.uninstallApp();
 
-        runAccessTest(nonSharedApp, sharedApp2.getSharedRODir(2), OWNER_UID, OWNER_GID, R_OK|X_OK);
-        runAccessTest(sharedApp2, sharedApp2.getSharedRODir(2),
-                      OWNER_UID, OWNER_GID, R_OK|W_OK|X_OK);
+        runAccessTest(nonSharedApp, owner, sharedApp2.getSharedRODir(2), R_OK|X_OK);
+        runAccessTest(sharedApp2, owner, sharedApp2.getSharedRODir(2), R_OK|W_OK|X_OK);
     }
 }
index df0c8e61d1b58368b1b74f6661aea830ea59437f..94d627b727d0a3ae01077f9ba4a9f17537f2b151 100644 (file)
@@ -22,7 +22,7 @@
 #include <scoped_installer.h>
 #include <sm_api.h>
 #include <sm_commons.h>
-#include <temp_test_user.h>
+#include <test_user.h>
 #include <tests_common.h>
 #include <tzplatform.h>
 
@@ -32,8 +32,8 @@ RUNNER_TEST_GROUP_INIT(SECURITY_MANAGER_REGISTER_PATH)
 
 RUNNER_TEST(security_manager_54_path_req_no_pkg)
 {
-    TemporaryTestUser user("sm_test_54_user_name", GUM_USERTYPE_NORMAL, false);
-    user.create();
+    TestUser user =
+        TestUser::createTemporary("sm_test_54_user_name", GUM_USERTYPE_NORMAL, false);
 
     AppInstallHelper app("sm_test_54", user.getUid());
     app.createPrivateDir();
@@ -48,8 +48,8 @@ RUNNER_TEST(security_manager_54_path_req_no_pkg)
 
 RUNNER_TEST(security_manager_55_path_req_empty_pkg)
 {
-    TemporaryTestUser user("sm_test_55_user_name", GUM_USERTYPE_NORMAL, false);
-    user.create();
+    TestUser user =
+        TestUser::createTemporary("sm_test_55_user_name", GUM_USERTYPE_NORMAL, false);
     AppInstallHelper app("sm_test_55", user.getUid());
     app.createPrivateDir();
 
@@ -72,8 +72,8 @@ RUNNER_TEST(security_manager_56_path_req_wrong_type)
 
 RUNNER_TEST(security_manager_57_path_req_wrong_uid)
 {
-    TemporaryTestUser user("sm_test_57_user_name", GUM_USERTYPE_NORMAL, false);
-    user.create();
+    TestUser user =
+        TestUser::createTemporary("sm_test_57_user_name", GUM_USERTYPE_NORMAL, false);
 
     AppInstallHelper app("sm_test_57", user.getUid());
     ScopedInstaller appInstall(app);
@@ -91,8 +91,8 @@ RUNNER_TEST(security_manager_57_path_req_wrong_uid)
 
 RUNNER_TEST(security_manager_58_path_req_empty_paths)
 {
-    TemporaryTestUser user("sm_test_58_user_name", GUM_USERTYPE_NORMAL, false);
-    user.create();
+    TestUser user =
+        TestUser::createTemporary("sm_test_58_user_name", GUM_USERTYPE_NORMAL, false);
     AppInstallHelper app("sm_test_58", user.getUid());
 
     PathsRequest req;
@@ -103,8 +103,8 @@ RUNNER_TEST(security_manager_58_path_req_empty_paths)
 
 RUNNER_TEST(security_manager_59_path_req_as_root_positive)
 {
-    TemporaryTestUser user("sm_test_59_user_name", GUM_USERTYPE_NORMAL, false);
-    user.create();
+    TestUser user =
+        TestUser::createTemporary("sm_test_59_user_name", GUM_USERTYPE_NORMAL, false);
 
     AppInstallHelper app("sm_test_59", user.getUid());
     ScopedInstaller appInstall(app);
@@ -120,8 +120,8 @@ RUNNER_TEST(security_manager_59_path_req_as_root_positive)
 
 RUNNER_TEST(security_manager_59a_path_req_as_root_positive_realpath_check)
 {
-    TemporaryTestUser user("sm_test_59a_user_name", GUM_USERTYPE_NORMAL);
-    user.create();
+    TestUser user =
+        TestUser::createTemporary("sm_test_59a_user_name", GUM_USERTYPE_NORMAL);
 
     AppInstallHelper app("sm_test_59a", user.getUid());
     ScopedInstaller appInstall(app);
@@ -141,8 +141,8 @@ RUNNER_TEST(security_manager_59a_path_req_as_root_positive_realpath_check)
 
 RUNNER_CHILD_TEST(security_manager_60_path_req_as_user_positive)
 {
-    TemporaryTestUser user("sm_test_60_user_name", GUM_USERTYPE_NORMAL, false);
-    user.create();
+    TestUser user =
+        TestUser::createTemporary("sm_test_60_user_name", GUM_USERTYPE_NORMAL, false);
 
     AppInstallHelper app("sm_test_60", user.getUid());
     ScopedInstaller appInstall(app);
@@ -162,8 +162,8 @@ RUNNER_CHILD_TEST(security_manager_60_path_req_as_user_positive)
 
 RUNNER_CHILD_TEST(security_manager_60a_path_req_as_user_positive_realpath_check)
 {
-    TemporaryTestUser user("sm_test_60a_user_name", GUM_USERTYPE_NORMAL);
-    user.create();
+    TestUser user =
+        TestUser::createTemporary("sm_test_60a_user_name", GUM_USERTYPE_NORMAL);
 
     AppInstallHelper app("sm_test_60a", user.getUid());
     ScopedInstaller appInstall(app);
@@ -188,10 +188,10 @@ RUNNER_CHILD_TEST(security_manager_60a_path_req_as_user_positive_realpath_check)
 
 RUNNER_CHILD_TEST(security_manager_61_path_req_different_user)
 {
-    TemporaryTestUser user1("sm_test_61_1_user_name", GUM_USERTYPE_NORMAL, false);
-    user1.create();
-    TemporaryTestUser user2("sm_test_61_2_user_name", GUM_USERTYPE_NORMAL, false);
-    user2.create();
+    TestUser user1 =
+        TestUser::createTemporary("sm_test_61_1_user_name", GUM_USERTYPE_NORMAL, false);
+    TestUser user2 =
+        TestUser::createTemporary("sm_test_61_2_user_name", GUM_USERTYPE_NORMAL, false);
 
     AppInstallHelper app("sm_test_61", user2.getUid());
     ScopedInstaller appInstall(app);
@@ -223,10 +223,10 @@ static void checkOutsidePath(const std::string& pkgId, uid_t uid, const std::str
 
 RUNNER_TEST(security_manager_62_path_req_path_outside)
 {
-    TemporaryTestUser user1("sm_test_62_1_user_name", GUM_USERTYPE_NORMAL, false);
-    user1.create();
-    TemporaryTestUser user2("sm_test_62_2_user_name", GUM_USERTYPE_NORMAL, false);
-    user2.create();
+    TestUser user1 =
+        TestUser::createTemporary("sm_test_62_1_user_name", GUM_USERTYPE_NORMAL, false);
+    TestUser user2 =
+        TestUser::createTemporary("sm_test_62_2_user_name", GUM_USERTYPE_NORMAL, false);
 
     AppInstallHelper app("sm_test_62", user1.getUid());
     AppInstallHelper differentUserApp("sm_test_62", user2.getUid());
@@ -241,8 +241,8 @@ RUNNER_TEST(security_manager_62_path_req_path_outside)
 
 RUNNER_CHILD_TEST(security_manager_63a_path_req_as_user)
 {
-    TemporaryTestUser user("sm_test_63_user_name", GUM_USERTYPE_NORMAL, false);
-    user.create();
+    TestUser user =
+        TestUser::createTemporary("sm_test_63_user_name", GUM_USERTYPE_NORMAL, false);
 
     AppInstallHelper app("sm_test_63", user.getUid());
     ScopedInstaller appInstall(app);
@@ -263,8 +263,8 @@ RUNNER_CHILD_TEST(security_manager_63a_path_req_as_user)
 
 RUNNER_CHILD_TEST(security_manager_63b_path_req_preloaded_as_user)
 {
-    TemporaryTestUser user("sm_test_63_user_name", GUM_USERTYPE_NORMAL, false);
-    user.create();
+    TestUser user =
+        TestUser::createTemporary("sm_test_63_user_name", GUM_USERTYPE_NORMAL, false);
 
     AppInstallHelper app("sm_test_63", user.getUid());
     ScopedInstaller appInstall(app);
@@ -285,8 +285,8 @@ RUNNER_CHILD_TEST(security_manager_63b_path_req_preloaded_as_user)
 
 RUNNER_TEST(security_manager_64a_path_req_as_local_as_root)
 {
-    TemporaryTestUser user("sm_test_64_user_name", GUM_USERTYPE_NORMAL, false);
-    user.create();
+    TestUser user =
+        TestUser::createTemporary("sm_test_64_user_name", GUM_USERTYPE_NORMAL, false);
 
     AppInstallHelper app("sm_test_64", user.getUid());
     ScopedInstaller appInstall(app);
@@ -304,8 +304,8 @@ RUNNER_TEST(security_manager_64a_path_req_as_local_as_root)
 
 RUNNER_CHILD_TEST(security_manager_64b_path_req_as_local_as_global_user)
 {
-    TemporaryTestUser user("sm_test_64_user_name", GUM_USERTYPE_NORMAL, false);
-    user.create();
+    TestUser user =
+        TestUser::createTemporary("sm_test_64_user_name", GUM_USERTYPE_NORMAL, false);
 
     AppInstallHelper app("sm_test_64", user.getUid());
     ScopedInstaller appInstall(app);
@@ -354,8 +354,8 @@ RUNNER_TEST(security_manager_66_path_req_check_labels)
 
 RUNNER_TEST(security_manager_67_path_req_shared_ro_3_0)
 {
-    TemporaryTestUser user("sm_test_67_user_name", GUM_USERTYPE_NORMAL, false);
-    user.create();
+    TestUser user =
+        TestUser::createTemporary("sm_test_67_user_name", GUM_USERTYPE_NORMAL, false);
 
     AppInstallHelper app("sm_test_67", user.getUid());
     app.setVersion("3.0");
@@ -374,8 +374,8 @@ RUNNER_TEST(security_manager_67_path_req_shared_ro_3_0)
 
 RUNNER_TEST(security_manager_68_path_req_shared_ro_2_X)
 {
-    TemporaryTestUser user("sm_test_68_user_name", GUM_USERTYPE_NORMAL, false);
-    user.create();
+    TestUser user =
+        TestUser::createTemporary("sm_test_68_user_name", GUM_USERTYPE_NORMAL, false);
 
     AppInstallHelper app("sm_test_68", user.getUid());
     app.setVersion("2.4");
@@ -394,8 +394,8 @@ RUNNER_TEST(security_manager_68_path_req_shared_ro_2_X)
 
 RUNNER_TEST(security_manager_69_path_req_trusted_rw_no_author)
 {
-    TemporaryTestUser user("sm_test_69_user_name", GUM_USERTYPE_NORMAL, false);
-    user.create();
+    TestUser user =
+        TestUser::createTemporary("sm_test_69_user_name", GUM_USERTYPE_NORMAL, false);
 
     AppInstallHelper app("sm_test_69", user.getUid());
     ScopedInstaller appInstall(app);
@@ -412,8 +412,8 @@ RUNNER_TEST(security_manager_69_path_req_trusted_rw_no_author)
 
 RUNNER_TEST(security_manager_70_path_req_trusted_rw_positive)
 {
-    TemporaryTestUser user("sm_test_70_user_name", GUM_USERTYPE_NORMAL, false);
-    user.create();
+    TestUser user =
+        TestUser::createTemporary("sm_test_70_user_name", GUM_USERTYPE_NORMAL, false);
 
     AppInstallHelper app("sm_test_70", user.getUid());
     app.setAuthor("sm_test_70_author");
index 0aba4f7a1ebfc2928eddcce8d5eb38af27e0273b..71fee0de15a2863ebfbbaea29b63b93a149569cc 100644 (file)
@@ -27,7 +27,7 @@
 
 #include <scoped_installer.h>
 #include <scoped_app_launcher.h>
-#include <temp_test_user.h>
+#include <test_user.h>
 #include <app_install_helper_ext.h>
 #include <sm_policy_request.h>
 #include <privilege_names.h>
@@ -270,8 +270,8 @@ RUNNER_CHILD_TEST(smack_privileges_30_one_after_another, InternetOnlySetup)
 
 RUNNER_CHILD_TEST(smack_privileges_40_different_users_one_after_another, InternetOnlySetup)
 {
-    TemporaryTestUser testUser("sm_test_40_user_name", GUM_USERTYPE_NORMAL, true);
-    testUser.create();
+    TestUser testUser =
+        TestUser::createTemporary("sm_test_40_user_name", GUM_USERTYPE_NORMAL, true);
 
     AppInstallHelperExt app("sm_test_sp_40_app");
     app.addPrivileges({PRIV_INTERNET});
@@ -363,8 +363,8 @@ RUNNER_CHILD_TEST(smack_privileges_60_same_user_interchangeably, InternetOnlySet
 
 RUNNER_CHILD_TEST(smack_privileges_70_different_users_simultaneously, InternetOnlySetup)
 {
-    TemporaryTestUser testUser("sm_test_70_user_name", GUM_USERTYPE_NORMAL, true);
-    testUser.create();
+    TestUser testUser =
+        TestUser::createTemporary("sm_test_70_user_name", GUM_USERTYPE_NORMAL, true);
 
     AppInstallHelperExt app("sm_test_sp_70_app");
     app.addPrivileges({PRIV_INTERNET});
@@ -437,8 +437,8 @@ RUNNER_CHILD_TEST(smack_privileges_80_uninstall_local_while_running, InternetOnl
 
 RUNNER_CHILD_TEST(smack_privileges_90_user_removal, InternetOnlySetup)
 {
-    TemporaryTestUser testUser("sm_test_90_user_name", GUM_USERTYPE_NORMAL, true);
-    testUser.create();
+    TestUser testUser =
+        TestUser::createTemporary("sm_test_90_user_name", GUM_USERTYPE_NORMAL, true);
 
     AppInstallHelperExt app("sm_test_sp_90_app", testUser.getUid());
     app.addPrivileges({PRIV_INTERNET});
@@ -535,8 +535,8 @@ RUNNER_CHILD_TEST(smack_privileges_110_hybridity_change, InternetOnlySetup)
 
 RUNNER_CHILD_TEST(smack_privileges_120_policy_change_while_running, InternetOnlySetup)
 {
-    TemporaryTestUser testUser("sm_test_120_user_name", GUM_USERTYPE_NORMAL, true);
-    testUser.create();
+    TestUser testUser =
+        TestUser::createTemporary("sm_test_120_user_name", GUM_USERTYPE_NORMAL, true);
 
     AppInstallHelperExt app("sm_test_sp_120_app", testUser.getUid());
     app.addPrivileges({PRIV_INTERNET});
@@ -569,8 +569,8 @@ RUNNER_CHILD_TEST(smack_privileges_120_policy_change_while_running, InternetOnly
 
 RUNNER_CHILD_TEST(smack_privileges_130_different_users_and_policies, InternetOnlySetup)
 {
-    TemporaryTestUser testUser("sm_test_130_user_name", GUM_USERTYPE_NORMAL, true);
-    testUser.create();
+    TestUser testUser =
+        TestUser::createTemporary("sm_test_130_user_name", GUM_USERTYPE_NORMAL, true);
 
     AppInstallHelperExt app("sm_test_sp_130_app");
     app.addPrivileges({PRIV_INTERNET});
@@ -606,8 +606,8 @@ RUNNER_CHILD_TEST(smack_privileges_130_different_users_and_policies, InternetOnl
 
 RUNNER_CHILD_TEST(smack_privileges_140_two_users_sequence, InternetOnlySetup)
 {
-    TemporaryTestUser testUser("sm_test_140_user_name", GUM_USERTYPE_NORMAL, true);
-    testUser.create();
+    TestUser testUser =
+        TestUser::createTemporary("sm_test_140_user_name", GUM_USERTYPE_NORMAL, true);
 
     AppInstallHelperExt app("sm_test_sp_140_app");
     app.addPrivileges({PRIV_INTERNET});
@@ -649,8 +649,8 @@ RUNNER_CHILD_TEST(smack_privileges_140_two_users_sequence, InternetOnlySetup)
 
 RUNNER_CHILD_TEST(smack_privileges_150_independent_apps, InternetOnlySetup)
 {
-    TemporaryTestUser testUser("sm_test_150_user_name", GUM_USERTYPE_NORMAL, true);
-    testUser.create();
+    TestUser testUser =
+        TestUser::createTemporary("sm_test_150_user_name", GUM_USERTYPE_NORMAL, true);
 
     AppInstallHelperExt app1("sm_test_sp_150_app1", testUser.getUid());
     AppInstallHelperExt app2("sm_test_sp_150_app2", testUser.getUid());
@@ -682,8 +682,8 @@ RUNNER_CHILD_TEST(smack_privileges_150_independent_apps, InternetOnlySetup)
 
 RUNNER_CHILD_TEST(smack_privileges_160_nonhybrid_package, InternetOnlySetup)
 {
-    TemporaryTestUser testUser("sm_test_160_user_name", GUM_USERTYPE_NORMAL, true);
-    testUser.create();
+    TestUser testUser =
+        TestUser::createTemporary("sm_test_160_user_name", GUM_USERTYPE_NORMAL, true);
 
     constexpr char pkgPrefix[] = "sm_test_sp_160_pkg";
 
@@ -733,8 +733,8 @@ RUNNER_CHILD_TEST(smack_privileges_160_nonhybrid_package, InternetOnlySetup)
 
 RUNNER_CHILD_TEST(smack_privileges_170_hybrid_package, InternetOnlySetup)
 {
-    TemporaryTestUser testUser("sm_test_170_user_name", GUM_USERTYPE_NORMAL, true);
-    testUser.create();
+    TestUser testUser =
+        TestUser::createTemporary("sm_test_170_user_name", GUM_USERTYPE_NORMAL, true);
 
     constexpr char pkgPrefix[] = "sm_test_sp_170_pkg";
 
@@ -784,8 +784,8 @@ RUNNER_CHILD_TEST(smack_privileges_170_hybrid_package, InternetOnlySetup)
 
 RUNNER_CHILD_TEST(smack_privileges_180_hybrid_package_both_apps_privileged, InternetOnlySetup)
 {
-    TemporaryTestUser testUser("sm_test_180_user_name", GUM_USERTYPE_NORMAL, true);
-    testUser.create();
+    TestUser testUser =
+        TestUser::createTemporary("sm_test_180_user_name", GUM_USERTYPE_NORMAL, true);
 
     constexpr char pkgPrefix[] = "sm_test_sp_180_pkg";
 
@@ -901,8 +901,8 @@ RUNNER_CHILD_TEST(smack_privileges_310_multi_policy_single_priv, MultiplePrivsSe
 
 RUNNER_CHILD_TEST(smack_privileges_320_multi_policy_all_privs, MultiplePrivsSetup)
 {
-    TemporaryTestUser testUser("sm_test_320_user_name", GUM_USERTYPE_NORMAL, true);
-    testUser.create();
+    TestUser testUser =
+        TestUser::createTemporary("sm_test_320_user_name", GUM_USERTYPE_NORMAL, true);
 
     AppInstallHelperExt app("sm_test_sp_320_app", testUser.getUid());
     app.addPrivileges({PRIV_CAMERA, PRIV_INTERNET});
index 9c6cb935c1bcae3ec6ef521af6cb282fc9038c39..0d664f08b3162f45875fd317fe9c82df6100469b 100644 (file)
@@ -30,7 +30,7 @@
 #include <sm_api.h>
 #include <sm_commons.h>
 #include <sm_request.h>
-#include <temp_test_user.h>
+#include <test_user.h>
 #include <tests_common.h>
 #include <tzplatform.h>
 
@@ -61,8 +61,8 @@ RUNNER_TEST(security_manager_41_set_author_id_multiple_times)
 
 RUNNER_CHILD_TEST(security_manager_43_app_install_with_trusted_path)
 {
-    TemporaryTestUser user("sm_test_43_user_name", GUM_USERTYPE_NORMAL);
-    user.create();
+    TestUser user =
+        TestUser::createTemporary("sm_test_43_user_name", GUM_USERTYPE_NORMAL);
 
     const std::string authorId = "sm_test_43_author_id";
 
@@ -166,8 +166,8 @@ RUNNER_CHILD_TEST(security_manager_45_test_authorId_identificator_creation)
  * Deinstalation of app1 must not remove access from system processes to trusted paths
  */
 void test_46_pkgId_deinstallation(bool isFirstOneHybrid, bool isSecondOneHybrid) {
-    TemporaryTestUser user("sm_test_46_user_name", GUM_USERTYPE_NORMAL);
-    user.create();
+    TestUser user =
+        TestUser::createTemporary("sm_test_46_user_name", GUM_USERTYPE_NORMAL);
 
     const std::string authorId = "sm_test_46_author_id";