Add testIP.py and testdata folder

Adds unit tests that cover all of the code-paths used
by the integrationCommon.py shared functionality.
Adds a directory containing test data, so as to not
require a specific ispConfig.py file or pollute the
ispConfig.example.py with test data.

Signed-off-by: Herbert Wolverson <herberticus@gmail.com>
This commit is contained in:
Herbert Wolverson
2022-10-27 09:41:39 -05:00
parent 532be33d64
commit 448d731b1d
2 changed files with 56 additions and 0 deletions

54
v1.3/testIP.py Normal file
View File

@@ -0,0 +1,54 @@
import unittest
import sys
class TestIP(unittest.TestCase):
def test_ignore(self):
"""
Test that we are correctly ignoring an IP address
"""
sys.path.append('testdata/')
from integrationCommon import isInIgnoredSubnets
self.assertEqual(isInIgnoredSubnets("192.168.1.1"),True)
def test_not_ignore(self):
"""
Test that we are not ignoring an IP address
"""
sys.path.append('testdata/')
from integrationCommon import isInIgnoredSubnets
self.assertEqual(isInIgnoredSubnets("10.0.0.1"),False)
def test_allowed(self):
"""
Test that we are correctly permitting an IP address
"""
sys.path.append('testdata/')
from integrationCommon import isInAllowedSubnets
self.assertEqual(isInAllowedSubnets("100.64.1.1"),True)
def test_not_allowed(self):
"""
Test that we are correctly not permitting an IP address
"""
sys.path.append('testdata/')
from integrationCommon import isInAllowedSubnets
self.assertEqual(isInAllowedSubnets("101.64.1.1"),False)
def test_is_permitted(self):
"""
Test the combined isIpv4Permitted function for true
"""
sys.path.append('testdata/')
from integrationCommon import isIpv4Permitted
self.assertEqual(isIpv4Permitted("100.64.1.1"),True)
def test_is_not_permitted(self):
"""
Test the combined isIpv4Permitted function for false
"""
sys.path.append('testdata/')
from integrationCommon import isIpv4Permitted
self.assertEqual(isIpv4Permitted("101.64.1.1"),False)
if __name__ == '__main__':
unittest.main()

2
v1.3/testdata/ispConfig.py vendored Normal file
View File

@@ -0,0 +1,2 @@
ignoreSubnets = ['192.168.0.0/16']
allowedSubnets = ['100.64.0.0/10']