Leosac  0.8.0
Open Source Access Control
RemoteControlSecurity.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2016 Leosac
3 
4  This file is part of Leosac.
5 
6  Leosac is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Affero General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Leosac is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Affero General Public License for more details.
15 
16  You should have received a copy of the GNU Affero General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
22 #include <gtest/gtest.h>
23 #include <string>
24 
29 static std::string gl_data_path;
30 
31 namespace Leosac
32 {
33 namespace Test
34 {
35 class RemoteControlSecurityTest : public ::testing::Test
36 {
37  public:
39  {
40 
41  auto cfg_tree = Tools::propertyTreeFromXmlFile(gl_data_path +
42  "RemoteControlSecurity1.xml");
43  sec1 = std::make_shared<RemoteControlSecurity>(
44  cfg_tree.get_child("kernel.remote"));
45 
46  cfg_tree = Tools::propertyTreeFromXmlFile(gl_data_path +
47  "RemoteControlSecurity2.xml");
48  sec2 = std::make_shared<RemoteControlSecurity>(
49  cfg_tree.get_child("kernel.remote"));
50  }
51 
52  protected:
53  std::shared_ptr<RemoteControlSecurity> sec1;
54  std::shared_ptr<RemoteControlSecurity> sec2;
55 };
56 
57 
59 {
60  ASSERT_TRUE(sec1->allow_request("Llama", "SYNC_FROM"));
61  ASSERT_TRUE(sec1->allow_request("Llama", "MODULE_CONFIG"));
62  // this doesn't exist, but security code doesn't care.
63  ASSERT_TRUE(sec1->allow_request("Llama", "HAHAHAHAHHA"));
64 
65  ASSERT_FALSE(sec1->allow_request("Worm", "SYNC_FROM"));
66  ASSERT_TRUE(sec1->allow_request("Worm", "MODULE_CONFIG"));
67  ASSERT_TRUE(sec1->allow_request("Worm", "MODULE_LIST"));
68  ASSERT_FALSE(sec1->allow_request("Worm", "HAHAHAHAHHA"));
69 
70  ASSERT_FALSE(sec1->allow_request("LlamaWorm", "SYNC_FROM"));
71  ASSERT_FALSE(sec1->allow_request("LlamaWorm", "MODULE_CONFIG"));
72  ASSERT_FALSE(sec1->allow_request("LlamaWorm", "HAHAHAHAHHA"));
73 }
74 
79 TEST_F(RemoteControlSecurityTest, TestNoSecurityInformation)
80 {
81  ASSERT_TRUE(sec2->allow_request("Llama", "SYNC_FROM"));
82  ASSERT_TRUE(sec2->allow_request("Llama", "MODULE_CONFIG"));
83  // this doesn't exist, but security code doesn't care.
84  ASSERT_TRUE(sec2->allow_request("Llama", "HAHAHAHAHHA"));
85 
86  ASSERT_TRUE(sec2->allow_request("Worm", "SYNC_FROM"));
87  ASSERT_TRUE(sec2->allow_request("Worm", "MODULE_CONFIG"));
88  ASSERT_TRUE(sec1->allow_request("Worm", "MODULE_LIST"));
89  ASSERT_TRUE(sec2->allow_request("Worm", "HAHAHAHAHHA"));
90 
91  ASSERT_TRUE(sec2->allow_request("LlamaWorm", "SYNC_FROM"));
92  ASSERT_TRUE(sec2->allow_request("LlamaWorm", "MODULE_CONFIG"));
93  ASSERT_TRUE(sec2->allow_request("LlamaWorm", "HAHAHAHAHHA"));
94 }
95 }
96 }
97 
98 int main(int argc, char **argv)
99 {
100  ::testing::InitGoogleTest(&argc, argv);
101 
102  // gtest shall leave us with our arguments.
103  // argv[1] shall be the path to test data file
104  assert(argc == 2);
105  gl_data_path = std::string(argv[1]) + '/';
106  return RUN_ALL_TESTS();
107 }
main
int main(int argc, char **argv)
Definition: RemoteControlSecurity.cpp:98
Leosac::Test::RemoteControlSecurityTest
Definition: RemoteControlSecurity.cpp:35
Leosac::Test::RemoteControlSecurityTest::sec2
std::shared_ptr< RemoteControlSecurity > sec2
Definition: RemoteControlSecurity.cpp:54
Leosac::Tools::propertyTreeFromXmlFile
boost::property_tree::ptree propertyTreeFromXmlFile(const std::string &path)
Build a property tree from a xml file.
Definition: XmlPropertyTree.cpp:39
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::Test::RemoteControlSecurityTest::sec1
std::shared_ptr< RemoteControlSecurity > sec1
Definition: RemoteControlSecurity.cpp:53
RemoteControlSecurity.hpp
XmlPropertyTree.hpp
Leosac::Test::RemoteControlSecurityTest::RemoteControlSecurityTest
RemoteControlSecurityTest()
Definition: RemoteControlSecurity.cpp:38
Leosac::Test::TEST_F
TEST_F(AuthFileMapperTest, SimpleMapping)
Successful mapping.
Definition: AuthFile.cpp:197