From 448d731b1dd00e878b4cdae16b04f724fe342336 Mon Sep 17 00:00:00 2001 From: Herbert Wolverson Date: Thu, 27 Oct 2022 09:41:39 -0500 Subject: [PATCH] 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 --- v1.3/testIP.py | 54 ++++++++++++++++++++++++++++++++++++++ v1.3/testdata/ispConfig.py | 2 ++ 2 files changed, 56 insertions(+) create mode 100644 v1.3/testIP.py create mode 100644 v1.3/testdata/ispConfig.py diff --git a/v1.3/testIP.py b/v1.3/testIP.py new file mode 100644 index 00000000..0f510593 --- /dev/null +++ b/v1.3/testIP.py @@ -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() diff --git a/v1.3/testdata/ispConfig.py b/v1.3/testdata/ispConfig.py new file mode 100644 index 00000000..cb2b439a --- /dev/null +++ b/v1.3/testdata/ispConfig.py @@ -0,0 +1,2 @@ +ignoreSubnets = ['192.168.0.0/16'] +allowedSubnets = ['100.64.0.0/10']