1
0

test_net.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # -*- coding: utf-8 -*-
  2. # Import python libs
  3. from __future__ import absolute_import, print_function, unicode_literals
  4. # Import Salt Libs
  5. from salt.utils.validate import net
  6. # Import Salt Testing Libs
  7. from tests.support.unit import TestCase, skipIf
  8. from tests.support.mock import NO_MOCK, NO_MOCK_REASON
  9. @skipIf(NO_MOCK, NO_MOCK_REASON)
  10. class ValidateNetTestCase(TestCase):
  11. '''
  12. TestCase for salt.utils.validate.net module
  13. '''
  14. def test_ipv4_addr(self):
  15. '''
  16. Test IPv4 address validation
  17. '''
  18. true_addrs = [
  19. '127.0.0.1',
  20. '127.0.0.1',
  21. '127.0.0.19',
  22. '1.1.1.1/28',
  23. '127.0.0.11/32',
  24. ]
  25. false_addrs = [
  26. '127.0.0.911',
  27. '127.0.0911',
  28. '127.0.011',
  29. '127.0.011/32',
  30. '::1',
  31. '::1/128',
  32. '::1/28',
  33. ]
  34. for addr in true_addrs:
  35. self.assertTrue(net.ipv4_addr(addr))
  36. for addr in false_addrs:
  37. self.assertFalse(net.ipv4_addr(addr))
  38. def test_ipv6_addr(self):
  39. '''
  40. Test IPv6 address validation
  41. '''
  42. true_addrs = [
  43. '::',
  44. '::1',
  45. '::1/32',
  46. '::1/32',
  47. '::1/128',
  48. '2a03:4000:c:10aa:1017:f00d:aaaa:a',
  49. ]
  50. false_addrs = [
  51. '1.1.1.1',
  52. '::1/0',
  53. '::1/32d',
  54. '::1/129',
  55. '2a03:4000:c:10aa:1017:f00d:aaaa:a:4506',
  56. '2a03::1::2',
  57. ]
  58. for addr in true_addrs:
  59. self.assertTrue(net.ipv6_addr(addr))
  60. for addr in false_addrs:
  61. self.assertFalse(net.ipv6_addr(addr))