mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-17 00:07:37 +02:00
add ufw tests
This commit is contained in:
1
tests/fixtures/generic/ufw-inactive.json
vendored
Normal file
1
tests/fixtures/generic/ufw-inactive.json
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"status":"inactive","rules":[]}
|
1
tests/fixtures/generic/ufw-inactive.out
vendored
Normal file
1
tests/fixtures/generic/ufw-inactive.out
vendored
Normal file
@ -0,0 +1 @@
|
||||
Status: inactive
|
1
tests/fixtures/generic/ufw-numbered.json
vendored
Normal file
1
tests/fixtures/generic/ufw-numbered.json
vendored
Normal file
File diff suppressed because one or more lines are too long
23
tests/fixtures/generic/ufw-numbered.out
vendored
Normal file
23
tests/fixtures/generic/ufw-numbered.out
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
Status: active
|
||||
Logging: on (low)
|
||||
Default: deny (incoming), allow (outgoing), deny (routed)
|
||||
New profiles: skip
|
||||
|
||||
To Action From
|
||||
-- ------ ----
|
||||
[ 1] 22/tcp ALLOW IN Anywhere
|
||||
[ 2] 22/tcp (v6) ALLOW OUT Anywhere (v6)
|
||||
[ 3] 443/tcp DENY 192.168.0.1
|
||||
[ 4] 443/udp DENY OUT 192.168.0.7 8080:8081
|
||||
[ 5] 22/tcp ALLOW 192.168.0.0/24
|
||||
[ 6] 22/udp ALLOW 192.168.0.0/24 8080:8081 on en0
|
||||
[ 7] 22/tcp (v6) ALLOW IN 2405:204:7449:49fc:f09a:6f4a:bc93:1955/64 on en1
|
||||
[ 8] 80 ALLOW IN Anywhere
|
||||
[ 9] 8080 (v6) ALLOW IN Anywhere (v6)
|
||||
[10] Apache Full ALLOW IN Anywhere
|
||||
[11] Apache Full (v6) ALLOW IN Anywhere (v6)
|
||||
[12] OpenSSH (v6) DENY IN Anywhere (v6)
|
||||
[13] 10.10.10.10 8080 on enp34s0 ALLOW 127.0.0.1 8000
|
||||
[14] 50200:50300/tcp (v6) ALLOW Anywhere (v6)
|
||||
[15] Anywhere (v6) ALLOW IN 2405:204:7449:49fc:f09a:6f4a:bc93:1955
|
||||
|
1
tests/fixtures/generic/ufw.json
vendored
Normal file
1
tests/fixtures/generic/ufw.json
vendored
Normal file
File diff suppressed because one or more lines are too long
22
tests/fixtures/generic/ufw.out
vendored
Normal file
22
tests/fixtures/generic/ufw.out
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
Status: active
|
||||
Logging: on (low)
|
||||
Default: deny (incoming), allow (outgoing), deny (routed)
|
||||
New profiles: skip
|
||||
|
||||
To Action From
|
||||
-- ------ ----
|
||||
22/tcp ALLOW IN Anywhere
|
||||
22/tcp (v6) ALLOW OUT Anywhere (v6)
|
||||
443/tcp DENY 192.168.0.1
|
||||
443/udp DENY OUT 192.168.0.7 8080:8081
|
||||
22/tcp ALLOW 192.168.0.0/24
|
||||
22/udp ALLOW 192.168.0.0/24 8080:8081 on en0
|
||||
22/tcp (v6) ALLOW IN 2405:204:7449:49fc:f09a:6f4a:bc93:1955/64 on en1
|
||||
80 ALLOW IN Anywhere
|
||||
8080 (v6) ALLOW IN Anywhere (v6)
|
||||
Apache Full ALLOW IN Anywhere
|
||||
Apache Full (v6) ALLOW IN Anywhere (v6)
|
||||
OpenSSH (v6) DENY IN Anywhere (v6)
|
||||
10.10.10.10 8080 on enp34s0 ALLOW 127.0.0.1 8000
|
||||
50200:50300/tcp (v6) ALLOW Anywhere (v6)
|
||||
Anywhere (v6) ALLOW IN 2405:204:7449:49fc:f09a:6f4a:bc93:1955
|
58
tests/test_ufw.py
Normal file
58
tests/test_ufw.py
Normal file
@ -0,0 +1,58 @@
|
||||
import os
|
||||
import json
|
||||
import unittest
|
||||
import jc.parsers.ufw
|
||||
|
||||
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.out'), 'r', encoding='utf-8') as f:
|
||||
self.generic_ufw = f.read()
|
||||
|
||||
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-inactive.out'), 'r', encoding='utf-8') as f:
|
||||
self.generic_ufw_inactive = f.read()
|
||||
|
||||
# output
|
||||
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())
|
||||
|
||||
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-inactive.json'), 'r', encoding='utf-8') as f:
|
||||
self.generic_ufw_inactive_json = json.loads(f.read())
|
||||
|
||||
def test_ufw_nodata(self):
|
||||
"""
|
||||
Test 'ufw' with no data
|
||||
"""
|
||||
self.assertEqual(jc.parsers.ufw.parse('', quiet=True), {})
|
||||
|
||||
def test_ufw_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):
|
||||
"""
|
||||
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):
|
||||
"""
|
||||
Test 'ufw status' when firewall is inactive
|
||||
"""
|
||||
self.assertEqual(jc.parsers.ufw.parse(self.generic_ufw_inactive, quiet=True), self.generic_ufw_inactive_json)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Reference in New Issue
Block a user