mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-10-08 23:22:21 +02:00
fixup net_localgroup parser
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
jc changelog
|
||||
|
||||
20250904 v1.25.6
|
||||
- Add `x509-crl` file parser to support Certificate Revocation List PEM and DER files
|
||||
- Add `net-localgroup` Windows command parser
|
||||
- Add `net-user` Windows command parser
|
||||
- Add `route-print` Windows command parser
|
||||
- Add `x509-crl` file parser to support Certificate Revocation List PEM and DER files
|
||||
- Fix `bluetoothctl` command parser to support output with the `cable_pairing` attribute
|
||||
- Fix `nmcli` command parser to support blank `team.config` JSON value and `team-port.config` JSON value
|
||||
- Fix `top` command parsers to correct memory size field parsing. Several new unit
|
||||
|
@@ -1,12 +1,11 @@
|
||||
r"""jc - JSON Convert `net localgroup` command output parser
|
||||
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ net localgroup | jc --net-localgroup -p
|
||||
$ net localgroup /domain | jc --net-localgroup -p
|
||||
$ net localgroup Administrators | jc --net-localgroup -p
|
||||
$ net localgroup Administrators /domain | jc --net-localgroup -p
|
||||
$ net localgroup | jc --net-localgroup
|
||||
$ net localgroup /domain | jc --net-localgroup
|
||||
$ net localgroup Administrators | jc --net-localgroup
|
||||
$ net localgroup Administrators /domain | jc --net-localgroup
|
||||
|
||||
Usage (module):
|
||||
|
||||
@@ -29,15 +28,6 @@ Schema:
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
Notes:
|
||||
[0] - 'lease_expires' and 'lease_obtained' are parsed to ISO8601 format date strings. if the value was unable
|
||||
to be parsed by datetime, the fields will be in their raw form
|
||||
[1] - 'autoconfigured' under 'ipv4_address' is only providing indication if the ipv4 address was labeled as
|
||||
"Autoconfiguration IPv4 Address" vs "IPv4 Address". It does not infer any information from other fields
|
||||
[2] - Windows XP uses 'IP Address' instead of 'IPv4 Address'. Both values are parsed to the 'ipv4_address'
|
||||
object for consistency
|
||||
|
||||
Examples:
|
||||
|
||||
$ net localgroup | jc --net-localgroup -p
|
||||
@@ -57,12 +47,7 @@ Examples:
|
||||
}
|
||||
]
|
||||
}
|
||||
$ net localgroup Administrators | jc --net-localgroup -p
|
||||
$ net localgroup /domain | jc --net-localgroup -p
|
||||
|
||||
"""
|
||||
|
||||
from datetime import datetime
|
||||
import re
|
||||
import jc.utils
|
||||
|
||||
@@ -73,7 +58,7 @@ class info():
|
||||
description = '`net localgroup` command parser'
|
||||
author = 'joehacksalot'
|
||||
author_email = 'joehacksalot@gmail.com'
|
||||
compatible = ['windows']
|
||||
compatible = ['win32']
|
||||
magic_commands = ['net localgroup']
|
||||
tags = ['command']
|
||||
|
||||
@@ -117,7 +102,7 @@ def _process(proc_data):
|
||||
|
||||
Processed Dictionary. Structured data to conform to the schema.
|
||||
"""
|
||||
return proc_data # No further processing is needed
|
||||
return proc_data
|
||||
|
||||
|
||||
class _PushbackIterator:
|
||||
@@ -176,7 +161,7 @@ def _parse(data):
|
||||
# Skip empty lines
|
||||
if not line.strip():
|
||||
continue
|
||||
|
||||
|
||||
match_domain_processed = re.match(r"^The request will be processed at a domain controller for domain (.+)", line, re.IGNORECASE)
|
||||
match_localgroup_list = re.match(r"^Aliases for[\s]*([^:]+)", line, re.IGNORECASE) # "Aliases for \\DESKTOP-WIN11:"
|
||||
match_localgroup_members = re.match(r"^Alias name[\s]*([^:]+)", line, re.IGNORECASE) # "Alias name administrators:"
|
||||
@@ -205,4 +190,5 @@ def _parse(data):
|
||||
"name": group_name,
|
||||
"members": names_list
|
||||
}]
|
||||
|
||||
return result
|
179
tests/test_net_localgroup2.py
Normal file
179
tests/test_net_localgroup2.py
Normal file
@@ -0,0 +1,179 @@
|
||||
import os
|
||||
import unittest
|
||||
import json
|
||||
from typing import Dict
|
||||
from jc.parsers.net_localgroup import parse
|
||||
|
||||
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
|
||||
class MyTests(unittest.TestCase):
|
||||
f_in: Dict = {}
|
||||
f_json: Dict = {}
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
fixtures = {
|
||||
'windows_xp_net_localgroup': (
|
||||
'fixtures/windows/windows-xp/net_localgroup.out',
|
||||
'fixtures/windows/windows-xp/net_localgroup.json'),
|
||||
'windows_xp_net_localgroup_administrators': (
|
||||
'fixtures/windows/windows-xp/net_localgroup.administrators.out',
|
||||
'fixtures/windows/windows-xp/net_localgroup.administrators.json'),
|
||||
'windows_7_net_localgroup': (
|
||||
'fixtures/windows/windows-7/net_localgroup.out',
|
||||
'fixtures/windows/windows-7/net_localgroup.json'),
|
||||
'windows_7_net_localgroup_administrators': (
|
||||
'fixtures/windows/windows-7/net_localgroup.administrators.out',
|
||||
'fixtures/windows/windows-7/net_localgroup.administrators.json'),
|
||||
'windows_2008_net_localgroup': (
|
||||
'fixtures/windows/windows-2008/net_localgroup.out',
|
||||
'fixtures/windows/windows-2008/net_localgroup.json'),
|
||||
'windows_2008_net_localgroup_administrators': (
|
||||
'fixtures/windows/windows-2008/net_localgroup.administrators.out',
|
||||
'fixtures/windows/windows-2008/net_localgroup.administrators.json'),
|
||||
'windows_2016_net_localgroup': (
|
||||
'fixtures/windows/windows-2016/net_localgroup.out',
|
||||
'fixtures/windows/windows-2016/net_localgroup.json'),
|
||||
'windows_2016_net_localgroup_administrators': (
|
||||
'fixtures/windows/windows-2016/net_localgroup.administrators.out',
|
||||
'fixtures/windows/windows-2016/net_localgroup.administrators.json'),
|
||||
'windows_10_net_localgroup': (
|
||||
'fixtures/windows/windows-10/net_localgroup.out',
|
||||
'fixtures/windows/windows-10/net_localgroup.json'),
|
||||
'windows_10_net_localgroup_administrators': (
|
||||
'fixtures/windows/windows-10/net_localgroup.administrators.out',
|
||||
'fixtures/windows/windows-10/net_localgroup.administrators.json'),
|
||||
'windows_11_net_localgroup': (
|
||||
'fixtures/windows/windows-11/net_localgroup.out',
|
||||
'fixtures/windows/windows-11/net_localgroup.json'),
|
||||
'windows_11_net_localgroup_administrators': (
|
||||
'fixtures/windows/windows-11/net_localgroup.administrators.out',
|
||||
'fixtures/windows/windows-11/net_localgroup.administrators.json'),
|
||||
}
|
||||
|
||||
for file, filepaths in fixtures.items():
|
||||
with open(os.path.join(THIS_DIR, filepaths[0]), 'r', encoding='utf-8') as a, \
|
||||
open(os.path.join(THIS_DIR, filepaths[1]), 'r', encoding='utf-8') as b:
|
||||
cls.f_in[file] = a.read()
|
||||
cls.f_json[file] = json.loads(b.read())
|
||||
|
||||
|
||||
def test_net_localgroup_nodata(self):
|
||||
"""
|
||||
Test 'net_localgroup' with no data
|
||||
"""
|
||||
self.assertEqual(parse('', quiet=True), {})
|
||||
|
||||
|
||||
def test_net_localgroup_windows_xp(self):
|
||||
"""
|
||||
Test 'net_localgroup' on Windows XP
|
||||
"""
|
||||
self.assertEqual(
|
||||
parse(self.f_in['windows_xp_net_localgroup'], quiet=True),
|
||||
self.f_json['windows_xp_net_localgroup']
|
||||
)
|
||||
|
||||
def test_net_localgroup_administrators_windows_xp(self):
|
||||
"""
|
||||
Test 'net_localgroup' administrators on Windows XP
|
||||
"""
|
||||
self.assertEqual(
|
||||
parse(self.f_in['windows_xp_net_localgroup_administrators'], quiet=True),
|
||||
self.f_json['windows_xp_net_localgroup_administrators']
|
||||
)
|
||||
|
||||
def test_net_localgroup_windows_7(self):
|
||||
"""
|
||||
Test 'net_localgroup' on Windows 7
|
||||
"""
|
||||
self.assertEqual(
|
||||
parse(self.f_in['windows_7_net_localgroup'], quiet=True),
|
||||
self.f_json['windows_7_net_localgroup']
|
||||
)
|
||||
|
||||
def test_net_localgroup_administrators_windows_7(self):
|
||||
"""
|
||||
Test 'net_localgroup' administrators on Windows 7
|
||||
"""
|
||||
self.assertEqual(
|
||||
parse(self.f_in['windows_7_net_localgroup_administrators'], quiet=True),
|
||||
self.f_json['windows_7_net_localgroup_administrators']
|
||||
)
|
||||
|
||||
def test_net_localgroup_windows_2008(self):
|
||||
"""
|
||||
Test 'net_localgroup' on Windows 2008
|
||||
"""
|
||||
self.assertEqual(
|
||||
parse(self.f_in['windows_2008_net_localgroup'], quiet=True),
|
||||
self.f_json['windows_2008_net_localgroup']
|
||||
)
|
||||
|
||||
def test_net_localgroup_administrators_windows_2008(self):
|
||||
"""
|
||||
Test 'net_localgroup' administrators on Windows 2008
|
||||
"""
|
||||
self.assertEqual(
|
||||
parse(self.f_in['windows_2008_net_localgroup_administrators'], quiet=True),
|
||||
self.f_json['windows_2008_net_localgroup_administrators']
|
||||
)
|
||||
|
||||
def test_net_localgroup_windows_2016(self):
|
||||
"""
|
||||
Test 'net_localgroup' on Windows 2016
|
||||
"""
|
||||
self.assertEqual(
|
||||
parse(self.f_in['windows_2016_net_localgroup'], quiet=True),
|
||||
self.f_json['windows_2016_net_localgroup']
|
||||
)
|
||||
|
||||
def test_net_localgroup_administrators_windows_2016(self):
|
||||
"""
|
||||
Test 'net_localgroup' administrators on Windows 2016
|
||||
"""
|
||||
self.assertEqual(
|
||||
parse(self.f_in['windows_2016_net_localgroup_administrators'], quiet=True),
|
||||
self.f_json['windows_2016_net_localgroup_administrators']
|
||||
)
|
||||
|
||||
def test_net_localgroup_windows_10(self):
|
||||
"""
|
||||
Test 'net_localgroup' on Windows 10
|
||||
"""
|
||||
self.assertEqual(
|
||||
parse(self.f_in['windows_10_net_localgroup'], quiet=True),
|
||||
self.f_json['windows_10_net_localgroup']
|
||||
)
|
||||
|
||||
def test_net_localgroup_administrators_windows_10(self):
|
||||
"""
|
||||
Test 'net_localgroup' administrators on Windows 10
|
||||
"""
|
||||
self.assertEqual(
|
||||
parse(self.f_in['windows_10_net_localgroup_administrators'], quiet=True),
|
||||
self.f_json['windows_10_net_localgroup_administrators']
|
||||
)
|
||||
|
||||
def test_net_localgroup_windows_11(self):
|
||||
"""
|
||||
Test 'net_localgroup' on Windows 11
|
||||
"""
|
||||
self.assertEqual(
|
||||
parse(self.f_in['windows_11_net_localgroup'], quiet=True),
|
||||
self.f_json['windows_11_net_localgroup']
|
||||
)
|
||||
|
||||
def test_net_localgroup_administrators_windows_11(self):
|
||||
"""
|
||||
Test 'net_localgroup' administrators on Windows 11
|
||||
"""
|
||||
self.assertEqual(
|
||||
parse(self.f_in['windows_11_net_localgroup_administrators'], quiet=True),
|
||||
self.f_json['windows_11_net_localgroup_administrators']
|
||||
)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Reference in New Issue
Block a user