TestLibrary.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import os
  2. import hashlib
  3. from definitions import ROOT_DIR
  4. test_resource_dir = ROOT_DIR + "/../resources/test"
  5. test_pcap = ROOT_DIR + "/../resources/test/reference_1998.pcap"
  6. test_pcap_ips = ["10.0.2.15", "52.85.173.182"]
  7. test_pcap_empty = []
  8. """
  9. helper functions for generic_test
  10. """
  11. def get_sha256(file):
  12. """
  13. Generates a sha256 checksum from file
  14. :param file: absolute path to file
  15. :return: sha256 checksum
  16. """
  17. sha = hashlib.sha256()
  18. with open(file, 'rb') as f:
  19. while True:
  20. data = f.read(0x100000)
  21. if not data:
  22. break
  23. sha.update(data)
  24. f.close()
  25. return sha.hexdigest()
  26. def clean_up(controller):
  27. """
  28. Removes the output files from a given controller
  29. :param controller: controller which created output files
  30. """
  31. os.remove(controller.pcap_dest_path)
  32. os.remove(controller.label_manager.label_file_path)
  33. """
  34. function patches for unittests
  35. """
  36. def get_bytes(count, ignore):
  37. """
  38. unittest patch for get_rnd_bytes (ID2TLib.Utility.py)
  39. :param count: count of requested bytes
  40. :param ignore: <not used>
  41. :return: a count of As
  42. """
  43. return b'A' * count
  44. def get_x86_nop(count, side_effect_free, char_filter):
  45. """
  46. unittest patch for get_rnd_x86_nop (ID2TLib.Utility.py)
  47. :param count: count of requested nops
  48. :param side_effect_free: <not used>
  49. :param char_filter: <not used>
  50. :return: a count of \x90
  51. """
  52. return b'\x90' * count