mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-07-15 01:24:29 +02:00
fix ufw tests
This commit is contained in:
2
tests/fixtures/generic/ufw-numbered.json
vendored
2
tests/fixtures/generic/ufw-numbered.json
vendored
File diff suppressed because one or more lines are too long
2
tests/fixtures/generic/ufw.json
vendored
2
tests/fixtures/generic/ufw.json
vendored
File diff suppressed because one or more lines are too long
1
tests/fixtures/ubuntu-18.04/ufw-numbered.json
vendored
Normal file
1
tests/fixtures/ubuntu-18.04/ufw-numbered.json
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"status":"active","rules":[{"action":"ALLOW","action_direction":"IN","index":1,"network_protocol":"ipv4","to_interface":"any","to_transport":"any","to_start_port":22,"to_end_port":22,"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":2,"network_protocol":"ipv4","to_interface":"any","to_transport":"tcp","to_service":"80,443","to_start_port":null,"to_end_port":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":3,"network_protocol":"ipv4","to_interface":"eth0","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":"test","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":"ipv6","to_interface":"any","to_transport":"any","to_start_port":22,"to_end_port":22,"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":5,"network_protocol":"ipv6","to_interface":"any","to_transport":"tcp","to_service":"80,443","to_start_port":null,"to_end_port":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":6,"network_protocol":"ipv6","to_interface":"eth0","to_transport":"any","to_start_port":80,"to_end_port":80,"to_service":null,"to_ip":"::","to_ip_prefix":0,"comment":"test","from_ip":"::","from_ip_prefix":0,"from_interface":"any","from_transport":"any","from_start_port":0,"from_end_port":65535,"from_service":null}]}
|
1
tests/fixtures/ubuntu-18.04/ufw-verbose.json
vendored
Normal file
1
tests/fixtures/ubuntu-18.04/ufw-verbose.json
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"status":"active","logging":"on","logging_level":"low","default":"deny (incoming), allow (outgoing), disabled (routed)","new_profiles":"skip","rules":[{"action":"ALLOW","action_direction":"IN","index":null,"network_protocol":"ipv4","to_interface":"any","to_transport":"any","to_start_port":22,"to_end_port":22,"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":null,"network_protocol":"ipv4","to_interface":"any","to_transport":"tcp","to_service":"80,443","to_start_port":null,"to_end_port":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":null,"network_protocol":"ipv4","to_interface":"eth0","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":"test","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":null,"network_protocol":"ipv6","to_interface":"any","to_transport":"any","to_start_port":22,"to_end_port":22,"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":null,"network_protocol":"ipv6","to_interface":"any","to_transport":"tcp","to_service":"80,443","to_start_port":null,"to_end_port":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":null,"network_protocol":"ipv6","to_interface":"eth0","to_transport":"any","to_start_port":80,"to_end_port":80,"to_service":null,"to_ip":"::","to_ip_prefix":0,"comment":"test","from_ip":"::","from_ip_prefix":0,"from_interface":"any","from_transport":"any","from_start_port":0,"from_end_port":65535,"from_service":null}]}
|
@ -10,6 +10,12 @@ class MyTests(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
# input
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/ufw-verbose.out'), 'r', encoding='utf-8') as f:
|
||||
self.ubuntu_18_04_ufw_verbose = f.read()
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/ufw-numbered.out'), 'r', encoding='utf-8') as f:
|
||||
self.ubuntu_18_04_ufw_numbered = f.read()
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/ufw.out'), 'r', encoding='utf-8') as f:
|
||||
self.generic_ufw = f.read()
|
||||
|
||||
@ -20,6 +26,12 @@ class MyTests(unittest.TestCase):
|
||||
self.generic_ufw_inactive = f.read()
|
||||
|
||||
# output
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/ufw-verbose.json'), 'r', encoding='utf-8') as f:
|
||||
self.ubuntu_18_04_ufw_verbose_json = json.loads(f.read())
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/ufw-numbered.json'), 'r', encoding='utf-8') as f:
|
||||
self.ubuntu_18_04_ufw_numbered_json = json.loads(f.read())
|
||||
|
||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/ufw.json'), 'r', encoding='utf-8') as f:
|
||||
self.generic_ufw_json = json.loads(f.read())
|
||||
|
||||
@ -35,19 +47,31 @@ class MyTests(unittest.TestCase):
|
||||
"""
|
||||
self.assertEqual(jc.parsers.ufw.parse('', quiet=True), {})
|
||||
|
||||
def test_ufw_verbose(self):
|
||||
def test_ufw_ubuntu_18_04_verbose(self):
|
||||
"""
|
||||
Test 'ufw status verbose' on Ubuntu 18.04
|
||||
"""
|
||||
self.assertEqual(jc.parsers.ufw.parse(self.ubuntu_18_04_ufw_verbose, quiet=True), self.ubuntu_18_04_ufw_verbose_json)
|
||||
|
||||
def test_ufw_ubuntu_18_04_numbered(self):
|
||||
"""
|
||||
Test 'ufw status numbered' on Ubuntu 18.04
|
||||
"""
|
||||
self.assertEqual(jc.parsers.ufw.parse(self.ubuntu_18_04_ufw_numbered, quiet=True), self.ubuntu_18_04_ufw_numbered_json)
|
||||
|
||||
def test_ufw_generic_verbose(self):
|
||||
"""
|
||||
Test 'ufw status verbose' sample
|
||||
"""
|
||||
self.assertEqual(jc.parsers.ufw.parse(self.generic_ufw, quiet=True), self.generic_ufw_json)
|
||||
|
||||
def test_ufw_verbose_numbered(self):
|
||||
def test_ufw_generic_verbose_numbered(self):
|
||||
"""
|
||||
Test 'ufw status verbose numbered' sample
|
||||
"""
|
||||
self.assertEqual(jc.parsers.ufw.parse(self.generic_ufw_numbered, quiet=True), self.generic_ufw_numbered_json)
|
||||
|
||||
def test_ufw_inactive(self):
|
||||
def test_ufw_generic_inactive(self):
|
||||
"""
|
||||
Test 'ufw status' when firewall is inactive
|
||||
"""
|
||||
|
Reference in New Issue
Block a user