From 56259d5605cdfbc1df0f6e40ac10bd42292d5923 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Sun, 2 Apr 2023 12:57:50 -0700 Subject: [PATCH] fix for dashes in name --- CHANGELOG | 3 +++ docs/parsers/iwconfig.md | 2 +- jc/parsers/iwconfig.py | 4 ++-- .../fixtures/generic/iwconfig-space-dash-ssid.json | 1 + .../fixtures/generic/iwconfig-space-dash-ssid.out | 9 +++++++++ tests/test_iwconfig.py | 14 +++++++++++++- 6 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 tests/fixtures/generic/iwconfig-space-dash-ssid.json create mode 100644 tests/fixtures/generic/iwconfig-space-dash-ssid.out diff --git a/CHANGELOG b/CHANGELOG index 417c1596..879ab077 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,8 @@ jc changelog +20230402 v1.23.2 +- Fix `iwconfig` command parser for SSIDs with dashes in the name + 20230323 v1.23.1 - Fix `zpool-status` command parser for lines that start with tab - Fix `timedatectl` command parser when RTC set to local diff --git a/docs/parsers/iwconfig.md b/docs/parsers/iwconfig.md index c182991f..14da8731 100644 --- a/docs/parsers/iwconfig.md +++ b/docs/parsers/iwconfig.md @@ -108,4 +108,4 @@ Returns: ### Parser Information Compatibility: linux -Version 1.0 by Thomas Vincent (vrince@gmail.com) +Version 1.1 by Thomas Vincent (vrince@gmail.com) diff --git a/jc/parsers/iwconfig.py b/jc/parsers/iwconfig.py index 260ab61f..d4b7d46c 100644 --- a/jc/parsers/iwconfig.py +++ b/jc/parsers/iwconfig.py @@ -85,7 +85,7 @@ import jc.utils class info(): """Provides parser metadata (version, author, etc.)""" - version = '1.0' + version = '1.1' description = '`iwconfig` command parser' author = 'Thomas Vincent' author_email = 'vrince@gmail.com' @@ -146,7 +146,7 @@ def parse( raw_output: List[Dict] = [] - re_interface = re.compile(r'^(?P[a-zA-Z0-9:._-]+)\s+(?P([a-zA-Z0-9]+\s)*[a-zA-Z0-9.]+)\s+ESSID:\"(?P[a-zA-Z0-9:._\s\-]+)\"') + re_interface = re.compile(r'^(?P[a-zA-Z0-9:._\-]+)\s+(?P([a-zA-Z0-9]+\s)*[a-zA-Z0-9.]+)\s+ESSID:\"(?P[a-zA-Z0-9:._\s\-]+)\"') re_mode = re.compile(r'Mode:(?P\w+)') re_frequency = re.compile(r'Frequency:(?P[0-9.]+)\s(?P\w+)') re_access_point = re.compile(r'Access Point:\s*(?P[0-9A-F:]+)') diff --git a/tests/fixtures/generic/iwconfig-space-dash-ssid.json b/tests/fixtures/generic/iwconfig-space-dash-ssid.json new file mode 100644 index 00000000..47dfb4a5 --- /dev/null +++ b/tests/fixtures/generic/iwconfig-space-dash-ssid.json @@ -0,0 +1 @@ +[{"name":"wlp-50","protocol":"IEEE 802.11","essid":"BLABLABLA-bla bla bla","mode":"Managed","frequency":5.18,"frequency_unit":"GHz","access_point":"E6:63:DA:16:50:BF","bit_rate":6.0,"bit_rate_unit":"Mb/s","tx_power":30,"tx_power_unit":"dBm","retry_short_limit":7,"rts_threshold":false,"fragment_threshold":false,"power_management":true,"link_quality":"58/70","signal_level":-52,"signal_level_unit":"dBm","rx_invalid_nwid":0,"rx_invalid_crypt":0,"rx_invalid_frag":0,"tx_excessive_retries":0,"invalid_misc":1766,"missed_beacon":0}] diff --git a/tests/fixtures/generic/iwconfig-space-dash-ssid.out b/tests/fixtures/generic/iwconfig-space-dash-ssid.out new file mode 100644 index 00000000..3c486715 --- /dev/null +++ b/tests/fixtures/generic/iwconfig-space-dash-ssid.out @@ -0,0 +1,9 @@ +wlp-50 IEEE 802.11 ESSID:"BLABLABLA-bla bla bla" + Mode:Managed Frequency:5.18 GHz Access Point: E6:63:DA:16:50:BF + Bit Rate=6 Mb/s Tx-Power=30 dBm + Retry short limit:7 RTS thr:off Fragment thr:off + Power Management:on + Link Quality=58/70 Signal level=-52 dBm + Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0 + Tx excessive retries:0 Invalid misc:1766 Missed beacon:0 + diff --git a/tests/test_iwconfig.py b/tests/test_iwconfig.py index b3b9fee0..ab161905 100644 --- a/tests/test_iwconfig.py +++ b/tests/test_iwconfig.py @@ -15,6 +15,9 @@ class iwconfigTests(unittest.TestCase): with open(os.path.join(THIS_DIR, 'fixtures/generic/iwconfig-many.out'), 'r', encoding='utf-8') as f: iwconfig_many_output = f.read() + with open(os.path.join(THIS_DIR, 'fixtures/generic/iwconfig-space-dash-ssid.out'), 'r', encoding='utf-8') as f: + iwconfig_space_dash_ssid = f.read() + # output with open(os.path.join(THIS_DIR, 'fixtures/generic/iwconfig.json'), 'r', encoding='utf-8') as f: iwconfig_json = json.loads(f.read()) @@ -23,7 +26,10 @@ class iwconfigTests(unittest.TestCase): iwconfig_raw_json = json.loads(f.read()) with open(os.path.join(THIS_DIR, 'fixtures/generic/iwconfig-many.json'), 'r', encoding='utf-8') as f: - iwconfig_many_json = json.loads(f.read()) + iwconfig_many_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, 'fixtures/generic/iwconfig-space-dash-ssid.json'), 'r', encoding='utf-8') as f: + iwconfig_space_dash_ssid_json = json.loads(f.read()) def test_iwconfig_nodata(self): @@ -50,5 +56,11 @@ class iwconfigTests(unittest.TestCase): """ self.assertEqual(jc.parsers.iwconfig.parse(self.iwconfig_many_output, quiet=True), self.iwconfig_many_json) + def test_iwconfig_space_dash_ssid(self): + """ + Test 'iwconfig' many spaces and dashes in the SSID + """ + self.assertEqual(jc.parsers.iwconfig.parse(self.iwconfig_space_dash_ssid, quiet=True), self.iwconfig_space_dash_ssid_json) + if __name__ == '__main__': unittest.main()