From 0d8a013d23accff7c30b700e9c388f01e7c38359 Mon Sep 17 00:00:00 2001 From: Jan Cybulski Date: Thu, 8 Jan 2015 11:31:54 +0100 Subject: [PATCH] Implement class for user management with libgum This will be needed in future tests. Change-Id: Ic55aa4cb1ab55b726d3032a7b59f02a648685f6b Signed-off-by: Jan Cybulski --- packaging/security-tests.spec | 1 + tests/common/CMakeLists.txt | 3 ++ tests/common/temp_test_user.cpp | 53 +++++++++++++++++++++++++++++++++ tests/common/temp_test_user.h | 41 +++++++++++++++++++++++++ 4 files changed, 98 insertions(+) create mode 100644 tests/common/temp_test_user.cpp create mode 100644 tests/common/temp_test_user.h diff --git a/packaging/security-tests.spec b/packaging/security-tests.spec index 78e840cd..dca203ff 100644 --- a/packaging/security-tests.spec +++ b/packaging/security-tests.spec @@ -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 diff --git a/tests/common/CMakeLists.txt b/tests/common/CMakeLists.txt index 35d987d6..a8cb8cc7 100644 --- a/tests/common/CMakeLists.txt +++ b/tests/common/CMakeLists.txt @@ -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 index 00000000..672bae49 --- /dev/null +++ b/tests/common/temp_test_user.cpp @@ -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 +#include +#include + +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 index 00000000..8f90bf3d --- /dev/null +++ b/tests/common/temp_test_user.h @@ -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 +#include +#include +#include + +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 -- 2.34.1