From: Lukasz Wojciechowski Date: Mon, 12 Jan 2015 16:13:17 +0000 (+0100) Subject: Introduce CynaraMask - a scoped cynara.service masker X-Git-Tag: security-manager_5.5_testing~152 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F26%2F33526%2F3;p=platform%2Fcore%2Ftest%2Fsecurity-tests.git Introduce CynaraMask - a scoped cynara.service masker Creation of CynaraMask object causes cynara.service to be masked and stopped. Its removal causes cynara to be unmasked and run again. Change-Id: Id7c20093fbd4ec19cdba783b20225ece04be5dfb --- diff --git a/tests/cynara-tests/CMakeLists.txt b/tests/cynara-tests/CMakeLists.txt index bfbc659..94aeb6e 100644 --- a/tests/cynara-tests/CMakeLists.txt +++ b/tests/cynara-tests/CMakeLists.txt @@ -36,6 +36,7 @@ SET(CYNARA_TARGET_TEST_SOURCES ${PROJECT_SOURCE_DIR}/tests/cynara-tests/common/cynara_test_client_async_request_monitor.cpp ${PROJECT_SOURCE_DIR}/tests/cynara-tests/common/cynara_test_client_async_status_monitor.cpp ${PROJECT_SOURCE_DIR}/tests/cynara-tests/common/cynara_test_commons.cpp + ${PROJECT_SOURCE_DIR}/tests/cynara-tests/common/cynara_test_cynara_mask.cpp ${PROJECT_SOURCE_DIR}/tests/cynara-tests/common/cynara_test_env.cpp ${PROJECT_SOURCE_DIR}/tests/cynara-tests/common/cynara_test_file_operations.cpp ${PROJECT_SOURCE_DIR}/tests/cynara-tests/cynara-test.cpp diff --git a/tests/cynara-tests/common/cynara_test_cynara_mask.cpp b/tests/cynara-tests/common/cynara_test_cynara_mask.cpp new file mode 100644 index 0000000..afd63d2 --- /dev/null +++ b/tests/cynara-tests/common/cynara_test_cynara_mask.cpp @@ -0,0 +1,47 @@ +/* + * 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 cynara_test_cynara_mask.cpp + * @author Lukasz Wojciechowski + * @version 1.0 + * @brief Implementation of scoped cynara service masker + */ + +#include + +#include +#include + +#include + +CynaraMask::CynaraMask() : m_dbusAccess(CynaraTestConsts::SERVICE.c_str()) +{ + m_dbusAccess.maskService(); + m_dbusAccess.stopService(); +} + +CynaraMask::~CynaraMask() noexcept(false) +{ + bool oops = std::uncaught_exception(); + try { + m_dbusAccess.unmaskService(); + m_dbusAccess.startService(); + } catch (...) { + if (!oops) + throw; + RUNNER_ERROR_MSG("Error: more exceptions thrown while releasing CynaraMask."); + } +} diff --git a/tests/cynara-tests/common/cynara_test_cynara_mask.h b/tests/cynara-tests/common/cynara_test_cynara_mask.h new file mode 100644 index 0000000..1da7754 --- /dev/null +++ b/tests/cynara-tests/common/cynara_test_cynara_mask.h @@ -0,0 +1,38 @@ +/* + * 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 cynara_test_cynara_mask.h + * @author Lukasz Wojciechowski + * @version 1.0 + * @brief Definition of scoped cynara service masker + */ + +#ifndef CYNARA_TEST_CYNARA_MASK_H_ +#define CYNARA_TEST_CYNARA_MASK_H_ + +#include + +class CynaraMask +{ +public: + CynaraMask(); + ~CynaraMask() noexcept(false); + +private: + DBusAccess m_dbusAccess; +}; + +#endif // CYNARA_TEST_CYNARA_MASK_H_ diff --git a/tests/cynara-tests/common/cynara_test_env.cpp b/tests/cynara-tests/common/cynara_test_env.cpp index 8f98d71..d855c69 100644 --- a/tests/cynara-tests/common/cynara_test_env.cpp +++ b/tests/cynara-tests/common/cynara_test_env.cpp @@ -15,6 +15,7 @@ */ #include +#include #include #include #include @@ -35,28 +36,21 @@ CynaraTestEnv::~CynaraTestEnv() void CynaraTestEnv::save() { + CynaraMask mask; + clear(m_dir); removeDirIfExists(m_dir); - DBusAccess dbusAccess(CynaraTestConsts::SERVICE.c_str()); - dbusAccess.maskService(); - dbusAccess.stopService(); - m_dbPresent = dirExists(CynaraTestConsts::DB_DIR); if (m_dbPresent) { makeDir(m_dir); copyDir(CynaraTestConsts::DB_DIR, m_dir); } - - dbusAccess.unmaskService(); - dbusAccess.startService(); } void CynaraTestEnv::restore() { - DBusAccess dbusAccess(CynaraTestConsts::SERVICE.c_str()); - dbusAccess.maskService(); - dbusAccess.stopService(); + CynaraMask mask; clear(CynaraTestConsts::DB_DIR); if (m_dbPresent) @@ -64,9 +58,6 @@ void CynaraTestEnv::restore() else removeDirIfExists(CynaraTestConsts::DB_DIR); - dbusAccess.unmaskService(); - dbusAccess.startService(); - clear(m_dir); removeDirIfExists(m_dir); }