Implement class for user management with libgum 92/32892/14
authorJan Cybulski <j.cybulski@samsung.com>
Thu, 8 Jan 2015 10:31:54 +0000 (11:31 +0100)
committerJan Cybulski <j.cybulski@samsung.com>
Mon, 12 Jan 2015 11:04:32 +0000 (12:04 +0100)
This will be needed in future tests.

Change-Id: Ic55aa4cb1ab55b726d3032a7b59f02a648685f6b
Signed-off-by: Jan Cybulski <j.cybulski@samsung.com>
packaging/security-tests.spec
tests/common/CMakeLists.txt
tests/common/temp_test_user.cpp [new file with mode: 0644]
tests/common/temp_test_user.h [new file with mode: 0644]

index 78e840c..dca203f 100644 (file)
@@ -25,6 +25,7 @@ BuildRequires: pkgconfig(sqlite3)
 BuildRequires: cynara-devel
 BuildRequires: pkgconfig(libtzplatform-config)
 BuildRequires: boost-devel
+BuildRequires: pkgconfig(libgum)
 Requires(post): gum-utils
 Requires(postun): gum-utils
 Requires(postun): %{_bindir}/id
index 35d987d..a8cb8cc 100644 (file)
@@ -6,6 +6,8 @@ PKG_CHECK_MODULES(COMMON_TARGET_DEP
     libsmack
     dbus-1
     sqlite3
+    libgum
+    glib-2.0
     REQUIRED
     )
 
@@ -18,6 +20,7 @@ SET(COMMON_TARGET_TEST_SOURCES
     ${PROJECT_SOURCE_DIR}/tests/common/memory.cpp
     ${PROJECT_SOURCE_DIR}/tests/common/db_sqlite.cpp
     ${PROJECT_SOURCE_DIR}/tests/common/fs_label_manager.cpp
+    ${PROJECT_SOURCE_DIR}/tests/common/temp_test_user.cpp
     )
 
 #system and local includes
diff --git a/tests/common/temp_test_user.cpp b/tests/common/temp_test_user.cpp
new file mode 100644 (file)
index 0000000..672bae4
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2015 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)
+ * @version     1.0
+ * @brief       File with class for users management
+ */
+
+
+#include <temp_test_user.h>
+#include <glib-object.h>
+#include <dpl/test/test_runner.h>
+
+TemporaryTestUser::TemporaryTestUser(std::string userName, GumUserType userType, bool offline) {
+    m_userName =  userName;
+    m_id = 0;
+    m_userType = userType;
+    m_guser = gum_user_create_sync (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);
+    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_id, NULL);
+    RUNNER_ASSERT_MSG(m_id != 0, "Something strange happened during user creation");
+}
+
+void TemporaryTestUser::remove(void) {
+    if(m_guser){
+        gum_user_delete_sync(m_guser, TRUE);
+        g_object_unref(m_guser);
+        m_guser = nullptr;
+    }
+}
+
+TemporaryTestUser::~TemporaryTestUser() {
+    this->remove();
+}
diff --git a/tests/common/temp_test_user.h b/tests/common/temp_test_user.h
new file mode 100644 (file)
index 0000000..8f90bf3
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2015 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>
+
+class TemporaryTestUser {
+public:
+    TemporaryTestUser(std::string userName, GumUserType userType, bool offline);
+    ~TemporaryTestUser();
+    void remove(void);
+    uid_t getUid() const {return m_id;}
+    const std::string& getUserName() const {return m_userName;}
+    GumUserType getUserType() const {return m_userType;}
+private:
+    uid_t m_id;
+    std::string m_userName;
+    GumUserType m_userType;
+    GumUser *m_guser;
+
+};
+
+#endif