TemporaryTestUser class fix 23/35023/10
authorKrzysztof Sasiak <k.sasiak@samsung.com>
Fri, 6 Feb 2015 07:19:14 +0000 (08:19 +0100)
committerRafal Krypa <r.krypa@samsung.com>
Mon, 2 Mar 2015 14:49:11 +0000 (15:49 +0100)
Additional method create() has to be called in order for the user
to be created. This prevents a segfault in gumd when adding this class
to a vector.

Change-Id: Ifc20e2c67c9dda205a62f47108a349cf04d09569
Signed-off-by: Krzysztof Sasiak <k.sasiak@samsung.com>
Signed-off-by: Zbigniew Jasinski <z.jasinski@samsung.com>
tests/common/temp_test_user.cpp
tests/common/temp_test_user.h
tests/security-manager-tests/security_manager_tests.cpp

index c15c029..f6aa6c1 100644 (file)
 #include <glib-object.h>
 #include <dpl/test/test_runner.h>
 
-TemporaryTestUser::TemporaryTestUser(std::string userName, GumUserType userType, bool offline)
-    : m_uid(0)
-    , m_gid(0)
-    , m_userName(userName)
-    , m_userType(userType)
+void TemporaryTestUser::create(void)
 {
-    m_guser = gum_user_create_sync (offline);
+    if (m_guser) {
+        remove();
+    };
+
+    m_guser = gum_user_create_sync (m_offline);
     RUNNER_ASSERT_MSG(m_guser != nullptr, "Failed to create gumd user object");
-    g_object_set(G_OBJECT(m_guser), "usertype", userType, NULL);
-    g_object_set(G_OBJECT(m_guser), "username", userName.c_str(), NULL);
+    g_object_set(G_OBJECT(m_guser), "usertype", m_userType, NULL);
+    g_object_set(G_OBJECT(m_guser), "username", m_userName.c_str(), NULL);
     gboolean added = gum_user_add_sync(m_guser);
     RUNNER_ASSERT_MSG(added, "Failed to add user");
     g_object_get(G_OBJECT(m_guser), "uid", &m_uid, NULL);
index f56c30a..3e62c1f 100644 (file)
 
 class TemporaryTestUser {
 public:
-    TemporaryTestUser(std::string userName, GumUserType userType, bool offline);
+    TemporaryTestUser() = delete;
+    TemporaryTestUser(std::string userName, GumUserType userType, bool offline) :
+            m_uid(0),
+            m_gid(0),
+            m_userName(userName),
+            m_userType(userType),
+            m_guser(nullptr),
+            m_offline(offline)
+            {};
     ~TemporaryTestUser();
     void remove(void);
     uid_t getUid() const {return m_uid;}
     uid_t getGid() const {return m_gid;}
+    void create(void);
     const std::string& getUserName() const {return m_userName;}
     GumUserType getUserType() const {return m_userType;}
 private:
@@ -37,7 +46,7 @@ private:
     std::string m_userName;
     GumUserType m_userType;
     GumUser *m_guser;
-
+    bool m_offline;
 };
 
 #endif
index 7fb04cd..82953f0 100644 (file)
@@ -632,6 +632,7 @@ RUNNER_CHILD_TEST(security_manager_04a_app_install_uninstall_by_app_user_for_sel
     const std::string new_user_name = "sm_test_04a_user_name";
 
     TemporaryTestUser testUser(new_user_name, GUM_USERTYPE_NORMAL, false);
+    testUser.create();
 
     removeTestDirs(testUser);
     createTestDirs(testUser);
@@ -663,6 +664,7 @@ RUNNER_CHILD_TEST(security_manager_04b_app_install_by_root_for_app_user)
     const std::string new_user_name = "sm_test_04b_user_name";
 
     TemporaryTestUser testUser(new_user_name, GUM_USERTYPE_NORMAL, false);
+    testUser.create();
 
     removeTestDirs(testUser);
     createTestDirs(testUser);
@@ -731,6 +733,7 @@ RUNNER_CHILD_TEST(security_manager_07_user_add_app_install)
     const std::string new_user_name = "sm_test_07_user_name";
     std::string uid_string;
     TemporaryTestUser test_user(new_user_name, GUM_USERTYPE_NORMAL, false);
+    test_user.create();
     uid_string =  std::to_string(static_cast<unsigned int>(test_user.getUid()));
 
     install_app(sm_app_id, sm_pkg_id, test_user.getUid());
@@ -755,6 +758,7 @@ RUNNER_CHILD_TEST(security_manager_08_user_double_add_double_remove)
 
     // gumd user add
     TemporaryTestUser test_user(new_user_name, GUM_USERTYPE_NORMAL, false);
+    test_user.create();
     uid_string =  std::to_string(static_cast<unsigned int>(test_user.getUid()));
 
     addUserRequest.setUid(test_user.getUid());
@@ -789,6 +793,7 @@ RUNNER_CHILD_TEST(security_manager_09_add_user_offline)
     serviceManager.stopService();
 
     TemporaryTestUser user(username, GUM_USERTYPE_NORMAL, true);
+    user.create();
 
     install_app(app_id, pkg_id, user.getUid());