diff --git a/tests/fixtures/generic/ufw-appinfo-msn.json b/tests/fixtures/generic/ufw-appinfo-msn.json new file mode 100644 index 00000000..3532d142 --- /dev/null +++ b/tests/fixtures/generic/ufw-appinfo-msn.json @@ -0,0 +1 @@ +{"profile":"MSN","title":"MSN Chat","description":"MSN chat protocol (with file transfer and voice)","tcp_list":[1863,6901],"udp_list":[1863,6901],"tcp_ranges":[{"start":6891,"end":6900}],"normalized_tcp_list":[1863,6901],"normalized_tcp_ranges":[{"start":6891,"end":6900}],"normalized_udp_list":[1863,6901]} diff --git a/tests/fixtures/generic/ufw-appinfo-msn.out b/tests/fixtures/generic/ufw-appinfo-msn.out new file mode 100644 index 00000000..a08c18c5 --- /dev/null +++ b/tests/fixtures/generic/ufw-appinfo-msn.out @@ -0,0 +1,9 @@ +Profile: MSN +Title: MSN Chat +Description: MSN chat protocol (with file transfer and voice) + +Ports: + 1863 + 6891:6900/tcp + 6901 + diff --git a/tests/fixtures/generic/ufw-appinfo-test.json b/tests/fixtures/generic/ufw-appinfo-test.json new file mode 100644 index 00000000..64eb243e --- /dev/null +++ b/tests/fixtures/generic/ufw-appinfo-test.json @@ -0,0 +1 @@ +{"profile":"TEST","title":"My test app","description":"a longer description of the test app here.","tcp_list":[1,2,3,4,5,6,7,8,9,10,9,8,7,30,53],"tcp_ranges":[{"start":80,"end":90},{"start":8080,"end":8090}],"udp_ranges":[{"start":50,"end":51},{"start":40,"end":60}],"udp_list":[53],"normalized_tcp_list":[1,2,3,4,5,6,7,8,9,10,30,53],"normalized_tcp_ranges":[{"start":80,"end":90},{"start":8080,"end":8090}],"normalized_udp_ranges":[{"start":40,"end":60}]} diff --git a/tests/fixtures/generic/ufw-appinfo-test.out b/tests/fixtures/generic/ufw-appinfo-test.out new file mode 100644 index 00000000..f8e3d73a --- /dev/null +++ b/tests/fixtures/generic/ufw-appinfo-test.out @@ -0,0 +1,9 @@ +Profile: TEST +Title: My test app +Description: a longer description of the test app here. + +Ports: + 1,2,3,4,5,6,7,8,9,10,9,8,7,30,80:90,8080:8090/tcp + 50:51,40:60/udp + 53 + diff --git a/tests/fixtures/generic/ufw-appinfo-test2.json b/tests/fixtures/generic/ufw-appinfo-test2.json new file mode 100644 index 00000000..b48fb46a --- /dev/null +++ b/tests/fixtures/generic/ufw-appinfo-test2.json @@ -0,0 +1 @@ +{"profile":"TEST2","title":"My test app2","description":"a longer description of the test app here.","tcp_ranges":[{"start":0,"end":65535}],"udp_ranges":[{"start":50,"end":51}],"tcp_list":[53],"udp_list":[53],"normalized_tcp_ranges":[{"start":0,"end":65535}],"normalized_udp_list":[53],"normalized_udp_ranges":[{"start":50,"end":51}]} diff --git a/tests/fixtures/generic/ufw-appinfo-test2.out b/tests/fixtures/generic/ufw-appinfo-test2.out new file mode 100644 index 00000000..6b3bf5d5 --- /dev/null +++ b/tests/fixtures/generic/ufw-appinfo-test2.out @@ -0,0 +1,9 @@ +Profile: TEST2 +Title: My test app2 +Description: a longer description of the test app here. + +Ports: + any/tcp + 50:51/udp + 53 + diff --git a/tests/fixtures/generic/ufw-appinfo-test3.json b/tests/fixtures/generic/ufw-appinfo-test3.json new file mode 100644 index 00000000..20eb606c --- /dev/null +++ b/tests/fixtures/generic/ufw-appinfo-test3.json @@ -0,0 +1 @@ +{"profile":"TEST3","title":"My test app3","description":"test overlapping ports","tcp_list":[80,83,80,53],"tcp_ranges":[{"start":70,"end":90}],"udp_ranges":[{"start":50,"end":51}],"udp_list":[53],"normalized_tcp_list":[53],"normalized_tcp_ranges":[{"start":70,"end":90}],"normalized_udp_list":[53],"normalized_udp_ranges":[{"start":50,"end":51}]} diff --git a/tests/fixtures/generic/ufw-appinfo-test3.out b/tests/fixtures/generic/ufw-appinfo-test3.out new file mode 100644 index 00000000..45a8f1fb --- /dev/null +++ b/tests/fixtures/generic/ufw-appinfo-test3.out @@ -0,0 +1,9 @@ +Profile: TEST3 +Title: My test app3 +Description: test overlapping ports + +Ports: + 80,83,80,70:90/tcp + 50:51/udp + 53 + diff --git a/tests/test_ufw_appinfo.py b/tests/test_ufw_appinfo.py new file mode 100644 index 00000000..ae5acb88 --- /dev/null +++ b/tests/test_ufw_appinfo.py @@ -0,0 +1,70 @@ +import os +import json +import unittest +import jc.parsers.ufw_appinfo + +THIS_DIR = os.path.dirname(os.path.abspath(__file__)) + + +class MyTests(unittest.TestCase): + + def setUp(self): + # input + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/ufw-appinfo-test.out'), 'r', encoding='utf-8') as f: + self.generic_ufw_appinfo_test = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/ufw-appinfo-test2.out'), 'r', encoding='utf-8') as f: + self.generic_ufw_appinfo_test2 = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/ufw-appinfo-test3.out'), 'r', encoding='utf-8') as f: + self.generic_ufw_appinfo_test3 = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/ufw-appinfo-msn.out'), 'r', encoding='utf-8') as f: + self.generic_ufw_appinfo_msn = f.read() + + # output + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/ufw-appinfo-test.json'), 'r', encoding='utf-8') as f: + self.generic_ufw_appinfo_test_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/ufw-appinfo-test2.json'), 'r', encoding='utf-8') as f: + self.generic_ufw_appinfo_test2_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/ufw-appinfo-test3.json'), 'r', encoding='utf-8') as f: + self.generic_ufw_appinfo_test3_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/ufw-appinfo-msn.json'), 'r', encoding='utf-8') as f: + self.generic_ufw_appinfo_msn_json = json.loads(f.read()) + + def test_ufw_appinfo_nodata(self): + """ + Test 'ufw_appinfo' with no data + """ + self.assertEqual(jc.parsers.ufw_appinfo.parse('', quiet=True), {}) + + def test_ufw_appinfo_generic_test(self): + """ + Test 'ufw app info [application]' sample + """ + self.assertEqual(jc.parsers.ufw_appinfo.parse(self.generic_ufw_appinfo_test, quiet=True), self.generic_ufw_appinfo_test_json) + + def test_ufw_appinfo_generic_test2(self): + """ + Test 'ufw app info [application]' sample + """ + self.assertEqual(jc.parsers.ufw_appinfo.parse(self.generic_ufw_appinfo_test2, quiet=True), self.generic_ufw_appinfo_test2_json) + + def test_ufw_appinfo_generic_test3(self): + """ + Test 'ufw app info [application]' sample + """ + self.assertEqual(jc.parsers.ufw_appinfo.parse(self.generic_ufw_appinfo_test3, quiet=True), self.generic_ufw_appinfo_test3_json) + + def test_ufw_appinfo_generic_msn(self): + """ + Test 'ufw app info MSN' sample + """ + self.assertEqual(jc.parsers.ufw_appinfo.parse(self.generic_ufw_appinfo_msn, quiet=True), self.generic_ufw_appinfo_msn_json) + + +if __name__ == '__main__': + unittest.main()