test_SMBLib.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. from unittest import TestCase
  2. from ID2TLib.SMBLib import *
  3. from ID2TLib.Utility import platforms, get_filetime_format
  4. class TestSMBLib(TestCase):
  5. def test_get_smb_version_all(self):
  6. for platform in platforms:
  7. with self.subTest(platform):
  8. result = get_smb_version(platform)
  9. self.assertTrue((result in smb_versions_per_win.values() or result in smb_versions_per_samba.values()))
  10. def test_get_smb_version_invalid(self):
  11. with self.assertRaises(SystemExit):
  12. get_smb_version("abc")
  13. def test_get_smb_version_mac(self):
  14. self.assertEqual(get_smb_version("macos"), "2.1")
  15. def test_get_smb_version_win(self):
  16. win_platforms = {'win7', 'win10', 'winxp', 'win8.1', 'win8', 'winvista', 'winnt', "win2000"}
  17. for platform in win_platforms:
  18. with self.subTest(platform):
  19. self.assertIn(get_smb_version(platform), smb_versions_per_win.values())
  20. def test_get_smb_version_linux(self):
  21. self.assertIn(get_smb_version("linux"), smb_versions_per_samba.values())
  22. def test_get_smb_platform_data_invalid(self):
  23. with self.assertRaises(SystemExit):
  24. get_smb_platform_data("abc", 0)
  25. def test_get_smb_platform_data_linux(self):
  26. self.assertEqual((get_smb_platform_data("linux", 0)), ("ubuntu", security_blob_ubuntu, 0x5, 0x800000, 0))
  27. def test_get_smb_platform_data_mac(self):
  28. guid, blob, cap, d_size, time = get_smb_platform_data("macos", 0)
  29. self.assertEqual((blob, cap, d_size, time), (security_blob_macos, 0x6, 0x400000, 0))
  30. self.assertTrue(isinstance(guid, str) and len(guid) > 0)
  31. def test_get_smb_platform_data_win(self):
  32. guid, blob, cap, d_size, time = get_smb_platform_data("win7", 100)
  33. self.assertEqual((blob, cap, d_size), (security_blob_windows, 0x7, 0x100000))
  34. self.assertTrue(isinstance(guid, str) and len(guid) > 0)
  35. self.assertTrue(time <= get_filetime_format(100))
  36. def test_invalid_smb_version(self):
  37. with self.assertRaises(SystemExit):
  38. invalid_smb_version("abc")