From 9d4041c39f54f33610ac810d033a5444d309d390 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D8=B3=D9=84=D9=8A=D9=85=20=D8=B9=D8=A8=D8=AF=20=D8=A7?= =?UTF-8?q?=D9=84=D8=AD=D9=85=D9=8A=D8=AF?= Date: Mon, 5 Jul 2021 12:44:20 -0400 Subject: [PATCH 1/3] Added failing test for trailing space in wifi ssid --- test/wpa_cli.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/wpa_cli.js b/test/wpa_cli.js index fe004dc..947598c 100644 --- a/test/wpa_cli.js +++ b/test/wpa_cli.js @@ -72,6 +72,13 @@ var WPA_CLI_SCAN_RESULTS = [ '2c:f5:d3:02:ea:d9 2472 -31 [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][ESS] FakeWifi2' ].join('\n'); +var WPA_CLI_SCAN_RESULTS_SPACE = [ + 'bssid / frequency / signal level / flags / ssid', + '2c:f5:d3:02:ea:d9 2472 -31 [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][ESS] FakeWifi ', + '2c:f5:d3:02:ea:d9 2472 -31 [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][ESS] FakeWifi2', + '2c:f5:d3:02:ea:d9 2472 -31 [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][ESS] FakeWifi3 ' +].join('\n'); + var WPA_CLI_SCAN_NORESULTS = [ '' ].join('\n'); @@ -605,6 +612,37 @@ describe('wpa_cli', function() { }); }); + it('scan_results SPACE', function(done) { + this.OUTPUT = WPA_CLI_SCAN_RESULTS_SPACE; + wpa_cli.scan_results('wlan0', function(err, results) { + should(results).eql([ + { + bssid: '2c:f5:d3:02:ea:d9', + frequency: 2472, + signalLevel: -31, + flags: '[WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][ESS]', + ssid: 'FakeWifi ' + }, + { + bssid: '2c:f5:d3:02:ea:d9', + frequency: 2472, + signalLevel: -31, + flags: '[WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][ESS]', + ssid: 'FakeWifi2' + }, + { + bssid: '2c:f5:d3:02:ea:d9', + frequency: 2472, + signalLevel: -31, + flags: '[WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][ESS]', + ssid: 'FakeWifi3 ' + } + ]); + + done(); + }); + }); + it('should handle errors', function(done) { wpa_cli.exec = function(command, callback) { callback('error'); From db47fdd32466b2369038a0d02440a1ca40e3c3c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D8=B3=D9=84=D9=8A=D9=85=20=D8=B9=D8=A8=D8=AF=20=D8=A7?= =?UTF-8?q?=D9=84=D8=AD=D9=85=D9=8A=D8=AF?= Date: Mon, 5 Jul 2021 12:57:31 -0400 Subject: [PATCH 2/3] Fixed trailing space in ssid name getting dropped --- wpa_cli.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpa_cli.js b/wpa_cli.js index f4fa8fb..dfdd7a2 100644 --- a/wpa_cli.js +++ b/wpa_cli.js @@ -238,7 +238,7 @@ function parse_scan_results_interface(callback) { if (error) { callback(error); } else { - callback(error, parse_scan_results(stdout.trim())); + callback(error, parse_scan_results(stdout)); } }; } From c24a1f2d59beef47e8fff192c572d01d471ebdf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D8=B3=D9=84=D9=8A=D9=85=20=D8=B9=D8=A8=D8=AF=20=D8=A7?= =?UTF-8?q?=D9=84=D8=AD=D9=85=D9=8A=D8=AF?= Date: Mon, 5 Jul 2021 15:30:14 -0400 Subject: [PATCH 3/3] Added more realistic newlines at end of test data\n Fixed failing tests --- test/wpa_cli.js | 15 ++++++++++----- wpa_cli.js | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/test/wpa_cli.js b/test/wpa_cli.js index 947598c..fe09a6a 100644 --- a/test/wpa_cli.js +++ b/test/wpa_cli.js @@ -39,7 +39,8 @@ var WPA_CLI_STATUS_COMPLETED = [ 'ip_address=10.34.141.168', 'p2p_device_address=e4:28:9c:a8:53:72', 'address=e4:28:9c:a8:53:72', - 'uuid=e1cda789-8c88-53e8-ffff-31c304580c1e' + 'uuid=e1cda789-8c88-53e8-ffff-31c304580c1e', + '' ].join('\n'); var WPA_CLI_STATUS_4WAY_HANDSHAKE = [ @@ -55,7 +56,8 @@ var WPA_CLI_STATUS_4WAY_HANDSHAKE = [ 'ip_address=10.34.141.168', 'p2p_device_address=e4:28:9c:a8:53:72', 'address=e4:28:9c:a8:53:72', - 'uuid=e1cda789-8c88-53e8-ffff-31c304580c1e' + 'uuid=e1cda789-8c88-53e8-ffff-31c304580c1e', + '' ].join('\n'); var WPA_CLI_STATUS_SCANNING = [ @@ -63,20 +65,23 @@ var WPA_CLI_STATUS_SCANNING = [ 'ip_address=10.34.141.168', 'p2p_device_address=e4:28:9c:a8:53:72', 'address=e4:28:9c:a8:53:72', - 'uuid=e1cda789-8c88-53e8-ffff-31c304580c1e' + 'uuid=e1cda789-8c88-53e8-ffff-31c304580c1e', + '' ].join('\n'); var WPA_CLI_SCAN_RESULTS = [ 'bssid / frequency / signal level / flags / ssid', '2c:f5:d3:02:ea:d9 2472 -31 [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][ESS] FakeWifi', - '2c:f5:d3:02:ea:d9 2472 -31 [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][ESS] FakeWifi2' + '2c:f5:d3:02:ea:d9 2472 -31 [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][ESS] FakeWifi2', + '' ].join('\n'); var WPA_CLI_SCAN_RESULTS_SPACE = [ 'bssid / frequency / signal level / flags / ssid', '2c:f5:d3:02:ea:d9 2472 -31 [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][ESS] FakeWifi ', '2c:f5:d3:02:ea:d9 2472 -31 [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][ESS] FakeWifi2', - '2c:f5:d3:02:ea:d9 2472 -31 [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][ESS] FakeWifi3 ' + '2c:f5:d3:02:ea:d9 2472 -31 [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][ESS] FakeWifi3 ', + '' ].join('\n'); var WPA_CLI_SCAN_NORESULTS = [ diff --git a/wpa_cli.js b/wpa_cli.js index dfdd7a2..ed76551 100644 --- a/wpa_cli.js +++ b/wpa_cli.js @@ -238,7 +238,7 @@ function parse_scan_results_interface(callback) { if (error) { callback(error); } else { - callback(error, parse_scan_results(stdout)); + callback(error, parse_scan_results(stdout.replace(/\n$/, ''))); } }; }