test_SMBLib.py 2.2 KB

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