Пример #1
0
 def test_commit(self):
     with factory.session_manager().database_session() as s:
         self.assertEqual(s.query(App).count(), 0)
         app = App(name='testapp')
         s.add(app)
     with factory.session_manager().database_session() as s:
         self.assertEqual(s.query(App).count(), 1)
Пример #2
0
 def test_rollback(self):
     with self.assertRaises(Exception):
         with factory.session_manager().database_session() as s:
             self.assertEqual(s.query(App).count(), 0)
             app = App(name='testapp')
             s.add(app)
             raise Exception
     with factory.session_manager().database_session() as s:
         self.assertEqual(s.query(App).count(), 0)
Пример #3
0
 def test_saving_port_data2(self):
     with self.assertRaises(Exception):
         with factory.session_manager().database_session():
             port_data = [{TRANSPORT_PROTOCOL: TransportProtocol.TCP, NETWORK_PROTOCOL: NetworkProtocol.IPv6,
                           PORT_NUMBER: 1, EXECUTABLE_NAME: 'testapp_helper.exe'}]
             self.pm.save_port_data(port_data, commit=True)
             raise Exception
     with factory.session_manager().database_session() as s:
         self.assertEqual(s.query(Port).count(), 1)
         self.assertEqual(s.query(Port).filter(Port.app_id == self.app_id, Port.number == 1,
                                               Port.network_protocol == NetworkProtocol.IPv6,
                                               Port.transport_protocol == TransportProtocol.TCP).count(), 1)
Пример #4
0
 def verify_state(self):
     with factory.session_manager().database_session() as s:
         self.assertEqual(s.query(App).count(), 1)
         app = s.query(App).filter(App.name == 'testapp1').one()
         self.assertEqual(s.query(Executable).count(), 1)
         self.assertEqual(s.query(Executable).filter(Executable.name == 'testapp.exe',
                                                     Executable.app == app).count(), 1)
Пример #5
0
 def setUp(self):
     super().setUp()
     with factory.session_manager().database_session() as s:
         app = App(name='testapp')
         app.executables = [Executable(name='testapp.exe'), Executable(name='testapp_helper.exe')]
         s.add(app)
         s.flush()
         self.app_id = app.id
Пример #6
0
 def test_removing(self):
     self.core.remove_executable('test1_helper.exe')
     with factory.session_manager().database_session() as s:
         self.assertEqual(s.query(App).count(), 2)
         self.assertEqual(s.query(Executable).count(), 3)
         self.assertEqual(s.query(Port).count(), 4)
         app = s.query(App).filter(App.name == 'test1').one()
         self.assertEqual(s.query(Executable).filter(Executable.app == app).count(), 1)
         self.assertEqual(s.query(Executable).filter(Executable.name == 'test1.exe',
                                                     Executable.app == app).count(), 1)
Пример #7
0
 def setUp(self):
     super().setUp()
     with factory.session_manager().database_session() as s:
         app1 = App(name='app1')
         app1.executables = [Executable(name='app1.exe')]
         app2 = App(name='app2')
         app2.executables = [Executable(name='app2.exe')]
         app3 = App(name='app3')
         app3.executables = [Executable(name='app3.exe')]
         s.add_all([app1, app2, app3])
     self.core = KiosCore()
Пример #8
0
 def test_addition3(self):
     self.core.add('testapp1', 'testapp.exe', False)
     self.verify_state()
     self.core.add('testapp2', 'testapp.exe', True)
     with factory.session_manager().database_session() as s:
         self.assertEqual(s.query(App).count(), 2)
         self.assertEqual(s.query(App).filter(App.name == 'testapp1').count(), 1)
         app2 = s.query(App).filter(App.name == 'testapp2').one()
         self.assertEqual(s.query(Executable).count(), 1)
         self.assertEqual(s.query(Executable).filter(Executable.name == 'testapp.exe',
                                                     Executable.app == app2).count(), 1)
Пример #9
0
 def test_purging(self):
     self.core.purge('test1')
     with factory.session_manager().database_session() as s:
         self.assertEqual(s.query(App).count(), 1)
         self.assertEqual(s.query(Executable).count(), 2)
         self.assertEqual(s.query(Port).count(), 2)
         app2 = s.query(App).filter(App.name == 'test2').one()
         self.assertEqual(s.query(Executable).filter(Executable.name == 'test2.exe',
                                                     Executable.app == app2).count(), 1)
         self.assertEqual(s.query(Executable).filter(Executable.name == 'test2_helper.exe',
                                                     Executable.app == app2).count(), 1)
         self.assertEqual(s.query(Port).filter(Port.network_protocol == NetworkProtocol.IPv6,
                                               Port.transport_protocol == TransportProtocol.UDP,
                                               Port.number == 3, Port.app == app2).count(), 1)
         self.assertEqual(s.query(Port).filter(Port.network_protocol == NetworkProtocol.IPv4,
                                               Port.transport_protocol == TransportProtocol.TCP,
                                               Port.number == 4, Port.app == app2).count(), 1)
Пример #10
0
 def setUp(self):
     super().setUp()
     with factory.session_manager().database_session() as s:
         app = App(name='test1')
         app2 = App(name='test2')
         app.ports = [Port(network_protocol=NetworkProtocol.IPv4, transport_protocol=TransportProtocol.UDP,
                           number=1),
                      Port(network_protocol=NetworkProtocol.IPv6, transport_protocol=TransportProtocol.TCP,
                           number=2)]
         app.executables = [Executable(name='test1.exe'), Executable(name='test1_helper.exe')]
         s.add(app)
         app2.ports = [Port(network_protocol=NetworkProtocol.IPv6, transport_protocol=TransportProtocol.UDP,
                            number=3),
                       Port(network_protocol=NetworkProtocol.IPv4, transport_protocol=TransportProtocol.TCP,
                            number=4)]
         app2.executables = [Executable(name='test2.exe'), Executable(name='test2_helper.exe')]
         s.add(app2)
     self.core = KiosCore()
Пример #11
0
 def test_existing_session(self):
     with factory.session_manager().database_session():
         with self.assertRaises(RuntimeError):
             with factory.session_manager().database_session():
                 pass
Пример #12
0
 def verify_state(self):
     with factory.session_manager().database_session() as s:
         self.assertEqual(s.query(Port).join(App).join(Executable)
                          .filter(Executable.name == 'app3.exe', Port.network_protocol == NetworkProtocol.IPv6,
                                  Port.transport_protocol == TransportProtocol.UDP, Port.number == 3).count(), 1)
Пример #13
0
 def test_importing3(self):
     with self.assertRaises(DoRollback):
         self.core.import_(TestOperationControl(1))
     with factory.session_manager().database_session() as s:
         self.assertEqual(s.query(Port).count(), 0)
Пример #14
0
 def test_importing2(self):
     self.core.import_(TestOperationControl())
     with factory.session_manager().database_session() as s:
         self.assertEqual(s.query(Port).count(), 4)