Spring cleaning
[platform/core/test/security-tests.git] / src / cynara-tests / common / cynara_test_commons.cpp
1 /*
2  * Copyright (c) 2014-2020 Samsung Electronics Co., Ltd. All rights reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <cynara_test_commons.h>
18 #include <cynara_test_file_operations.h>
19 #include <cynara_test_cynara_mask.h>
20 #include <service_manager.h>
21
22 namespace CynaraTestConsts
23 {
24
25 const std::string DB_DIR(CYNARA_DB_DIR);
26 const std::string USER("cynara");
27 const std::string LABEL("System");
28 const std::string SERVICE("cynara.service");
29 const std::string SOCKET_CLIENT("cynara.socket");
30 const std::string SOCKET_ADMIN("cynara-admin.socket");
31 const std::string SOCKET_AGENT("cynara-agent.socket");
32
33 const std::string SERVICE_PLUGINS_DIR("/usr/lib/cynara/plugin/service/");
34
35 }
36
37 void loadServicePlugins(const DirectoryPaths &pluginDirectories)
38 {
39     CynaraMask mask;
40
41     FileOperations::removeDirFiles(CynaraTestConsts::SERVICE_PLUGINS_DIR);
42     for (const auto &dir : pluginDirectories)
43         FileOperations::copyCynaraFiles(dir, CynaraTestConsts::SERVICE_PLUGINS_DIR);
44 }
45
46 void restartCynaraService()
47 {
48     ServiceManager service(CynaraTestConsts::SERVICE);
49     service.restartService();
50 }
51
52 void restartCynaraServiceAndSockets()
53 {
54     ServiceManager service(CynaraTestConsts::SERVICE, { CynaraTestConsts::SOCKET_CLIENT,
55                                                         CynaraTestConsts::SOCKET_ADMIN,
56                                                         CynaraTestConsts::SOCKET_AGENT });
57
58     service.restartService(true);
59 }