mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-08-06 22:32:54 +02:00
make blank target null
This commit is contained in:
@ -25,7 +25,7 @@ Schema:
|
|||||||
"num" integer,
|
"num" integer,
|
||||||
"pkts": integer,
|
"pkts": integer,
|
||||||
"bytes": integer, # converted based on suffix
|
"bytes": integer, # converted based on suffix
|
||||||
"target": string,
|
"target": string, # Null if blank
|
||||||
"prot": string,
|
"prot": string,
|
||||||
"opt": string, # "--" = Null
|
"opt": string, # "--" = Null
|
||||||
"in": string,
|
"in": string,
|
||||||
@ -222,6 +222,10 @@ def _process(proc_data):
|
|||||||
if rule['opt'] == '--':
|
if rule['opt'] == '--':
|
||||||
rule['opt'] = None
|
rule['opt'] = None
|
||||||
|
|
||||||
|
if 'target' in rule:
|
||||||
|
if rule['target'] == '':
|
||||||
|
rule['target'] = None
|
||||||
|
|
||||||
return proc_data
|
return proc_data
|
||||||
|
|
||||||
|
|
||||||
@ -278,6 +282,8 @@ def parse(data, raw=False, quiet=False):
|
|||||||
rule = line.split(maxsplit=len(headers) - 1)
|
rule = line.split(maxsplit=len(headers) - 1)
|
||||||
temp_rule = dict(zip(headers, rule))
|
temp_rule = dict(zip(headers, rule))
|
||||||
if temp_rule:
|
if temp_rule:
|
||||||
|
if temp_rule.get('target') == '\u2063':
|
||||||
|
temp_rule['target'] = ''
|
||||||
chain['rules'].append(temp_rule)
|
chain['rules'].append(temp_rule)
|
||||||
|
|
||||||
if chain:
|
if chain:
|
||||||
|
1
tests/fixtures/generic/iptables-no-jump.json
vendored
Normal file
1
tests/fixtures/generic/iptables-no-jump.json
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
[{"chain":"INPUT","rules":[{"target":null,"prot":"udp","opt":null,"source":"anywhere","destination":"anywhere"}]}]
|
4
tests/fixtures/generic/iptables-no-jump.out
vendored
Normal file
4
tests/fixtures/generic/iptables-no-jump.out
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
Chain INPUT (policy ACCEPT)
|
||||||
|
target prot opt source destination
|
||||||
|
udp -- anywhere anywhere
|
||||||
|
|
@ -45,6 +45,9 @@ class MyTests(unittest.TestCase):
|
|||||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/iptables-raw.out'), 'r', encoding='utf-8') as f:
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/iptables-raw.out'), 'r', encoding='utf-8') as f:
|
||||||
ubuntu_18_4_iptables_raw = f.read()
|
ubuntu_18_4_iptables_raw = f.read()
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/iptables-no-jump.out'), 'r', encoding='utf-8') as f:
|
||||||
|
generic_iptables_no_jump = f.read()
|
||||||
|
|
||||||
# output
|
# output
|
||||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/iptables-filter.json'), 'r', encoding='utf-8') as f:
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/iptables-filter.json'), 'r', encoding='utf-8') as f:
|
||||||
centos_7_7_iptables_filter_json = json.loads(f.read())
|
centos_7_7_iptables_filter_json = json.loads(f.read())
|
||||||
@ -82,6 +85,9 @@ class MyTests(unittest.TestCase):
|
|||||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/iptables-raw.json'), 'r', encoding='utf-8') as f:
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/iptables-raw.json'), 'r', encoding='utf-8') as f:
|
||||||
ubuntu_18_4_iptables_raw_json = json.loads(f.read())
|
ubuntu_18_4_iptables_raw_json = json.loads(f.read())
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/iptables-no-jump.json'), 'r', encoding='utf-8') as f:
|
||||||
|
generic_iptables_no_jump_json = json.loads(f.read())
|
||||||
|
|
||||||
|
|
||||||
def test_iptables_nodata(self):
|
def test_iptables_nodata(self):
|
||||||
"""
|
"""
|
||||||
@ -161,6 +167,12 @@ class MyTests(unittest.TestCase):
|
|||||||
"""
|
"""
|
||||||
self.assertEqual(jc.parsers.iptables.parse(self.ubuntu_18_4_iptables_raw, quiet=True), self.ubuntu_18_4_iptables_raw_json)
|
self.assertEqual(jc.parsers.iptables.parse(self.ubuntu_18_4_iptables_raw, quiet=True), self.ubuntu_18_4_iptables_raw_json)
|
||||||
|
|
||||||
|
def test_iptables_no_jump_generic(self):
|
||||||
|
"""
|
||||||
|
Test 'sudo iptables' with no jump target
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.iptables.parse(self.generic_iptables_no_jump, quiet=True), self.generic_iptables_no_jump_json)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Reference in New Issue
Block a user