test_NestedNamedQueries.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import unittest
  2. import sqlite3
  3. import pyparsing
  4. import ID2TLib.TestLibrary as Lib
  5. import Core.Controller as Ctrl
  6. controller = Ctrl.Controller(pcap_file_path=Lib.test_pcap, do_extra_tests=False, non_verbose=True)
  7. controller.load_pcap_statistics(flag_write_file=False, flag_recalculate_stats=True, flag_print_statistics=False,
  8. intervals=[], delete=True)
  9. class UnitTestNestedNamedQueries(unittest.TestCase):
  10. def test_nested_query(self):
  11. self.assertEqual(controller.statistics.process_db_query('macaddress(ipaddress in most_used(ipaddress))'),
  12. '08:00:27:a3:83:43')
  13. self.assertEqual(controller.statistics.process_db_query('macaddress(ipaddress in least_used(ipaddress))'),
  14. '52:54:00:12:35:02')
  15. self.assertEqual(controller.statistics.process_db_query('ipaddress(macaddress in least_used(macaddress))'),
  16. '10.0.2.15')
  17. self.assertEqual(controller.statistics.process_db_query('ipaddress(macaddress in 08:00:27:a3:83:43)'),
  18. '10.0.2.15')
  19. self.assertEqual(controller.statistics.process_db_query('ipaddress(macaddress in [08:00:27:a3:83:43])'),
  20. '10.0.2.15')
  21. self.assertEqual(controller.statistics.process_db_query('ipaddress(macaddress in most_used(macaddress))'),
  22. ['104.83.103.45', '13.107.21.200', '131.253.61.100', '172.217.23.142', '172.217.23.174',
  23. '192.168.33.254', '204.79.197.200', '23.51.123.27', '35.161.3.50', '52.11.17.245',
  24. '52.34.37.177', '52.39.210.199', '52.41.250.141', '52.85.173.182', '54.149.74.139',
  25. '54.187.98.195', '54.192.44.108', '54.192.44.177', '72.247.178.113', '72.247.178.67',
  26. '93.184.220.29'])
  27. # semantically incorrect query
  28. with self.assertRaises(sqlite3.OperationalError):
  29. controller.statistics.process_db_query('ipaddress(ipaddress in most_used(macaddress))')
  30. # syntactically incorrect query
  31. with self.assertRaises(pyparsing.ParseException):
  32. controller.statistics.process_db_query('ipaddress(macaddress in '
  33. 'most_used(macaddress(ipaddress in least_used(ipaddress))))')