mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-07-13 01:20:24 +02:00
add ufw-appinfo tests
This commit is contained in:
1
tests/fixtures/generic/ufw-appinfo-msn.json
vendored
Normal file
1
tests/fixtures/generic/ufw-appinfo-msn.json
vendored
Normal file
@ -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]}
|
9
tests/fixtures/generic/ufw-appinfo-msn.out
vendored
Normal file
9
tests/fixtures/generic/ufw-appinfo-msn.out
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
Profile: MSN
|
||||
Title: MSN Chat
|
||||
Description: MSN chat protocol (with file transfer and voice)
|
||||
|
||||
Ports:
|
||||
1863
|
||||
6891:6900/tcp
|
||||
6901
|
||||
|
1
tests/fixtures/generic/ufw-appinfo-test.json
vendored
Normal file
1
tests/fixtures/generic/ufw-appinfo-test.json
vendored
Normal file
@ -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}]}
|
9
tests/fixtures/generic/ufw-appinfo-test.out
vendored
Normal file
9
tests/fixtures/generic/ufw-appinfo-test.out
vendored
Normal file
@ -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
|
||||
|
1
tests/fixtures/generic/ufw-appinfo-test2.json
vendored
Normal file
1
tests/fixtures/generic/ufw-appinfo-test2.json
vendored
Normal file
@ -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}]}
|
9
tests/fixtures/generic/ufw-appinfo-test2.out
vendored
Normal file
9
tests/fixtures/generic/ufw-appinfo-test2.out
vendored
Normal file
@ -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
|
||||
|
1
tests/fixtures/generic/ufw-appinfo-test3.json
vendored
Normal file
1
tests/fixtures/generic/ufw-appinfo-test3.json
vendored
Normal file
@ -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}]}
|
9
tests/fixtures/generic/ufw-appinfo-test3.out
vendored
Normal file
9
tests/fixtures/generic/ufw-appinfo-test3.out
vendored
Normal file
@ -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
|
||||
|
70
tests/test_ufw_appinfo.py
Normal file
70
tests/test_ufw_appinfo.py
Normal file
@ -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()
|
Reference in New Issue
Block a user