2 * Copyright (c) 2014-2020 Samsung Electronics Co., Ltd. All rights reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <cynara_test_commons.h>
18 #include <cynara_test_cynara_mask.h>
19 #include <cynara_test_file_operations.h>
20 #include <tests_common.h>
22 #include <cynara_test_env.h>
24 #include <sys/mount.h>
26 using namespace FileOperations;
28 CynaraTestEnv::CynaraTestEnv()
33 CynaraTestEnv::~CynaraTestEnv()
37 void CynaraTestEnv::init(const std::string &testName)
39 m_saveDir = "/tmp/" + testName;
40 m_dbSaveDir = m_saveDir + "/db";
41 m_defaultDir = "/etc/security-tests/db_patterns/default";
42 m_pluginsToInstallDir = "/opt/plugins_to_install";
46 removeDirFiles(m_dbSaveDir);
47 removeDirIfExists(m_dbSaveDir);
48 removeDirIfExists(m_saveDir);
51 makeDir(m_pluginsToInstallDir);
53 int res = mount(m_pluginsToInstallDir.c_str(), CynaraTestConsts::SERVICE_PLUGINS_DIR.c_str(), NULL, MS_BIND, NULL);
54 RUNNER_ASSERT_ERRNO_MSG(res == 0, "Bind mount failed");
56 m_dbPresent = dirExists(CynaraTestConsts::DB_DIR);
59 copyCynaraFiles(CynaraTestConsts::DB_DIR, m_dbSaveDir);
61 unmaskedLoadDefaultDatabase();
64 void CynaraTestEnv::finish()
68 removeDirFiles(CynaraTestConsts::DB_DIR);
70 copyCynaraFiles(m_dbSaveDir, CynaraTestConsts::DB_DIR);
72 removeDirIfExists(CynaraTestConsts::DB_DIR);
74 int res = umount(CynaraTestConsts::SERVICE_PLUGINS_DIR.c_str());
75 RUNNER_ASSERT_ERRNO_MSG(res == 0, "Unmounting failed");
77 removeDirFiles(m_dbSaveDir);
78 removeDirIfExists(m_dbSaveDir);
79 removeDirIfExists(m_saveDir);
80 removeDirFiles(m_pluginsToInstallDir);
81 removeDirIfExists(m_pluginsToInstallDir);
84 void CynaraTestEnv::unmaskedLoadDefaultDatabase()
87 removeDirFiles(CynaraTestConsts::DB_DIR);
88 copyCynaraFiles(m_defaultDir, CynaraTestConsts::DB_DIR);
92 void CynaraTestEnv::loadDefaultDatabase()
95 unmaskedLoadDefaultDatabase();