From 473d919c1350a8dc34d233033a5a7d12c928e42d Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Sat, 24 Apr 2021 10:58:31 -0700 Subject: [PATCH] add another ufw test sample --- runtests.sh | 1 + tests/fixtures/generic/ufw-numbered2.json | 1 + tests/fixtures/generic/ufw-numbered2.out | 18 ++++++++++++++++++ tests/test_ufw.py | 12 ++++++++++++ 4 files changed, 32 insertions(+) create mode 100644 tests/fixtures/generic/ufw-numbered2.json create mode 100644 tests/fixtures/generic/ufw-numbered2.out diff --git a/runtests.sh b/runtests.sh index 2f592d3e..d0a7ab96 100755 --- a/runtests.sh +++ b/runtests.sh @@ -1,3 +1,4 @@ #!/bin/bash +# system should be in "America/Los_Angeles" timezone for all tests to pass python3 -m unittest -v diff --git a/tests/fixtures/generic/ufw-numbered2.json b/tests/fixtures/generic/ufw-numbered2.json new file mode 100644 index 00000000..bbcb1aa1 --- /dev/null +++ b/tests/fixtures/generic/ufw-numbered2.json @@ -0,0 +1 @@ +{"status":"active","rules":[{"action":"ALLOW","action_direction":"IN","index":1,"network_protocol":"ipv4","to_interface":"any","to_ip":"224.0.0.251","to_ip_prefix":32,"to_transport":null,"to_service":"mDNS","to_start_port":null,"to_end_port":null,"comment":null,"from_ip":"0.0.0.0","from_ip_prefix":0,"from_interface":"any","from_transport":"any","from_start_port":0,"from_end_port":65535,"from_service":null},{"action":"ALLOW","action_direction":"IN","index":2,"network_protocol":"ipv4","to_ip":"0.0.0.0","to_ip_prefix":0,"to_interface":"any","to_transport":"any","to_start_port":0,"to_end_port":65535,"to_service":null,"comment":null,"from_interface":"any","from_ip":"123.123.123.123","from_ip_prefix":32,"from_transport":"any","from_start_port":0,"from_end_port":65535,"from_service":null},{"action":"ALLOW","action_direction":"IN","index":3,"network_protocol":"ipv4","to_interface":"any","to_transport":"any","to_start_port":25,"to_end_port":25,"to_service":null,"to_ip":"0.0.0.0","to_ip_prefix":0,"comment":null,"from_ip":"0.0.0.0","from_ip_prefix":0,"from_interface":"any","from_transport":"any","from_start_port":0,"from_end_port":65535,"from_service":null},{"action":"ALLOW","action_direction":"IN","index":4,"network_protocol":"ipv4","to_interface":"any","to_transport":"any","to_start_port":80,"to_end_port":80,"to_service":null,"to_ip":"0.0.0.0","to_ip_prefix":0,"comment":null,"from_ip":"0.0.0.0","from_ip_prefix":0,"from_interface":"any","from_transport":"any","from_start_port":0,"from_end_port":65535,"from_service":null},{"action":"ALLOW","action_direction":"IN","index":5,"network_protocol":"ipv4","to_interface":"any","to_transport":"any","to_start_port":443,"to_end_port":443,"to_service":null,"to_ip":"0.0.0.0","to_ip_prefix":0,"comment":null,"from_ip":"0.0.0.0","from_ip_prefix":0,"from_interface":"any","from_transport":"any","from_start_port":0,"from_end_port":65535,"from_service":null},{"action":"ALLOW","action_direction":"IN","index":6,"network_protocol":"ipv4","to_interface":"any","to_transport":"any","to_start_port":465,"to_end_port":465,"to_service":null,"to_ip":"0.0.0.0","to_ip_prefix":0,"comment":null,"from_ip":"0.0.0.0","from_ip_prefix":0,"from_interface":"any","from_transport":"any","from_start_port":0,"from_end_port":65535,"from_service":null},{"action":"ALLOW","action_direction":"IN","index":7,"network_protocol":"ipv4","to_interface":"any","to_transport":"any","to_start_port":993,"to_end_port":993,"to_service":null,"to_ip":"0.0.0.0","to_ip_prefix":0,"comment":null,"from_ip":"0.0.0.0","from_ip_prefix":0,"from_interface":"any","from_transport":"any","from_start_port":0,"from_end_port":65535,"from_service":null},{"action":"ALLOW","action_direction":"IN","index":8,"network_protocol":"ipv4","to_interface":"any","to_transport":"any","to_start_port":995,"to_end_port":995,"to_service":null,"to_ip":"0.0.0.0","to_ip_prefix":0,"comment":null,"from_ip":"0.0.0.0","from_ip_prefix":0,"from_interface":"any","from_transport":"any","from_start_port":0,"from_end_port":65535,"from_service":null},{"action":"ALLOW","action_direction":"IN","index":9,"network_protocol":"ipv6","to_interface":"any","to_ip":"ff02::fb","to_ip_prefix":128,"to_transport":null,"to_service":"mDNS","to_start_port":null,"to_end_port":null,"comment":null,"from_ip":"::","from_ip_prefix":0,"from_interface":"any","from_transport":"any","from_start_port":0,"from_end_port":65535,"from_service":null},{"action":"ALLOW","action_direction":"IN","index":10,"network_protocol":"ipv6","to_interface":"any","to_transport":"any","to_start_port":25,"to_end_port":25,"to_service":null,"to_ip":"::","to_ip_prefix":0,"comment":null,"from_ip":"::","from_ip_prefix":0,"from_interface":"any","from_transport":"any","from_start_port":0,"from_end_port":65535,"from_service":null},{"action":"ALLOW","action_direction":"IN","index":11,"network_protocol":"ipv6","to_interface":"any","to_transport":"any","to_start_port":80,"to_end_port":80,"to_service":null,"to_ip":"::","to_ip_prefix":0,"comment":null,"from_ip":"::","from_ip_prefix":0,"from_interface":"any","from_transport":"any","from_start_port":0,"from_end_port":65535,"from_service":null},{"action":"ALLOW","action_direction":"IN","index":12,"network_protocol":"ipv6","to_interface":"any","to_transport":"any","to_start_port":443,"to_end_port":443,"to_service":null,"to_ip":"::","to_ip_prefix":0,"comment":null,"from_ip":"::","from_ip_prefix":0,"from_interface":"any","from_transport":"any","from_start_port":0,"from_end_port":65535,"from_service":null},{"action":"ALLOW","action_direction":"IN","index":13,"network_protocol":"ipv6","to_interface":"any","to_transport":"any","to_start_port":465,"to_end_port":465,"to_service":null,"to_ip":"::","to_ip_prefix":0,"comment":null,"from_ip":"::","from_ip_prefix":0,"from_interface":"any","from_transport":"any","from_start_port":0,"from_end_port":65535,"from_service":null},{"action":"ALLOW","action_direction":"IN","index":14,"network_protocol":"ipv6","to_interface":"any","to_transport":"any","to_start_port":993,"to_end_port":993,"to_service":null,"to_ip":"::","to_ip_prefix":0,"comment":null,"from_ip":"::","from_ip_prefix":0,"from_interface":"any","from_transport":"any","from_start_port":0,"from_end_port":65535,"from_service":null},{"action":"ALLOW","action_direction":"IN","index":15,"network_protocol":"ipv6","to_interface":"any","to_transport":"any","to_start_port":995,"to_end_port":995,"to_service":null,"to_ip":"::","to_ip_prefix":0,"comment":null,"from_ip":"::","from_ip_prefix":0,"from_interface":"any","from_transport":"any","from_start_port":0,"from_end_port":65535,"from_service":null}]} diff --git a/tests/fixtures/generic/ufw-numbered2.out b/tests/fixtures/generic/ufw-numbered2.out new file mode 100644 index 00000000..6cd82010 --- /dev/null +++ b/tests/fixtures/generic/ufw-numbered2.out @@ -0,0 +1,18 @@ +Status: active + To Action From + -- ------ ---- +[ 1] 224.0.0.251 mDNS ALLOW IN Anywhere +[ 2] Anywhere ALLOW IN 123.123.123.123 +[ 3] 25 ALLOW IN Anywhere +[ 4] 80 ALLOW IN Anywhere +[ 5] 443 ALLOW IN Anywhere +[ 6] 465 ALLOW IN Anywhere +[ 7] 993 ALLOW IN Anywhere +[ 8] 995 ALLOW IN Anywhere +[ 9] ff02::fb mDNS ALLOW IN Anywhere (v6) +[10] 25 (v6) ALLOW IN Anywhere (v6) +[11] 80 (v6) ALLOW IN Anywhere (v6) +[12] 443 (v6) ALLOW IN Anywhere (v6) +[13] 465 (v6) ALLOW IN Anywhere (v6) +[14] 993 (v6) ALLOW IN Anywhere (v6) +[15] 995 (v6) ALLOW IN Anywhere (v6) diff --git a/tests/test_ufw.py b/tests/test_ufw.py index 3dbe8370..28fdcc69 100644 --- a/tests/test_ufw.py +++ b/tests/test_ufw.py @@ -22,6 +22,9 @@ class MyTests(unittest.TestCase): with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/ufw-numbered.out'), 'r', encoding='utf-8') as f: self.generic_ufw_numbered = f.read() + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/ufw-numbered2.out'), 'r', encoding='utf-8') as f: + self.generic_ufw_numbered2 = f.read() + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/ufw-inactive.out'), 'r', encoding='utf-8') as f: self.generic_ufw_inactive = f.read() @@ -38,6 +41,9 @@ class MyTests(unittest.TestCase): with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/ufw-numbered.json'), 'r', encoding='utf-8') as f: self.generic_ufw_numbered_json = json.loads(f.read()) + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/ufw-numbered2.json'), 'r', encoding='utf-8') as f: + self.generic_ufw_numbered2_json = json.loads(f.read()) + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/ufw-inactive.json'), 'r', encoding='utf-8') as f: self.generic_ufw_inactive_json = json.loads(f.read()) @@ -71,6 +77,12 @@ class MyTests(unittest.TestCase): """ self.assertEqual(jc.parsers.ufw.parse(self.generic_ufw_numbered, quiet=True), self.generic_ufw_numbered_json) + def test_ufw_generic_verbose_numbered2(self): + """ + Test 'ufw status verbose numbered' sample + """ + self.assertEqual(jc.parsers.ufw.parse(self.generic_ufw_numbered2, quiet=True), self.generic_ufw_numbered2_json) + def test_ufw_generic_inactive(self): """ Test 'ufw status' when firewall is inactive