This repository has been archived by the owner on Dec 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for wpa_supplicant parser
Issue: #34
- Loading branch information
1 parent
97b55fc
commit 3470c92
Showing
3 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
app/src/test/java/be/brunoparmentier/wifikeyshare/utils/WpaSupplicantParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* WiFiKeyShare. Share Wi-Fi passwords with QR codes or NFC tags. | ||
* Copyright (C) 2018 Bruno Parmentier <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package be.brunoparmentier.wifikeyshare.utils; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.io.InputStream; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Scanner; | ||
|
||
import be.brunoparmentier.wifikeyshare.model.WifiAuthType; | ||
import be.brunoparmentier.wifikeyshare.model.WifiNetwork; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class WpaSupplicantParserTest { | ||
|
||
private static final String TAG = WpaSupplicantParserTest.class.getSimpleName(); | ||
|
||
private final List<WifiNetwork> expectedWifiNetworks = new ArrayList<>(); | ||
|
||
@Before | ||
public void setUp() { | ||
expectedWifiNetworks.add(new WifiNetwork( | ||
"test1", WifiAuthType.OPEN, "", false)); | ||
expectedWifiNetworks.add(new WifiNetwork( | ||
"test2", WifiAuthType.WEP, "test", false)); | ||
expectedWifiNetworks.add(new WifiNetwork( | ||
"test3", WifiAuthType.WPA2_PSK, "test1234", false)); | ||
expectedWifiNetworks.add(new WifiNetwork( | ||
"test4", WifiAuthType.WPA2_PSK, "ABCDEFGHI0123456789JKLMNOP", false)); | ||
expectedWifiNetworks.add(new WifiNetwork( | ||
"test5", WifiAuthType.WPA2_PSK, "\";/\\=#}`,\\\"$4<d)=%", false)); | ||
expectedWifiNetworks.add(new WifiNetwork( | ||
"test6", WifiAuthType.WPA2_EAP, "", false)); | ||
expectedWifiNetworks.add(new WifiNetwork( | ||
"test7", WifiAuthType.WPA2_EAP, "", false)); | ||
expectedWifiNetworks.add(new WifiNetwork( | ||
"a\"=$\\o(#=>™•,k8", WifiAuthType.OPEN, "", false)); | ||
} | ||
|
||
@Test | ||
public void parse() { | ||
InputStream wpaSupplicantFileStream = | ||
getClass().getClassLoader().getResourceAsStream("test_wpa_supplicant.conf"); | ||
Scanner s = new Scanner(wpaSupplicantFileStream).useDelimiter("\\A"); | ||
String wpaSupplicantString = s.hasNext() ? s.next() : ""; | ||
|
||
List<WifiNetwork> parsedWifiNetworks = WpaSupplicantParser.parse(wpaSupplicantString); | ||
assertEquals(expectedWifiNetworks.size(), parsedWifiNetworks.size()); | ||
for (int i = 0; i < expectedWifiNetworks.size(); i++) { | ||
assertEquals(expectedWifiNetworks.get(i), parsedWifiNetworks.get(i)); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
disable_scan_offload=1 | ||
driver_param=use_p2p_group_interface=1 | ||
update_config=1 | ||
device_name=testdev | ||
manufacturer=TestCo | ||
model_name=TestDevice | ||
model_number=TestDevice | ||
serial_number=ABCDEFGHI | ||
device_type=10-0050F204-5 | ||
config_methods=physical_display virtual_push_button | ||
p2p_disabled=1 | ||
pmf=1 | ||
external_sim=1 | ||
tdls_external_control=1 | ||
|
||
network={ | ||
ssid="test1" | ||
scan_ssid=1 | ||
key_mgmt=NONE | ||
} | ||
|
||
network={ | ||
ssid="test2" | ||
scan_ssid=1 | ||
key_mgmt=NONE | ||
auth_alg=OPEN SHARED | ||
wep_key0="test" | ||
} | ||
|
||
network={ | ||
ssid="test3" | ||
scan_ssid=1 | ||
psk="test1234" | ||
key_mgmt=WPA-PSK | ||
} | ||
|
||
network={ | ||
ssid="test4" | ||
psk="ABCDEFGHI0123456789JKLMNOP" | ||
key_mgmt=WPA-PSK | ||
priority=4289 | ||
} | ||
|
||
network={ | ||
ssid="test5" | ||
scan_ssid=1 | ||
psk="";/\=#}`,\"$4<d)=%" | ||
key_mgmt=WPA-PSK | ||
} | ||
|
||
network={ | ||
ssid="test6" | ||
scan_ssid=1 | ||
key_mgmt=WPA-EAP IEEE8021X | ||
eap=PEAP | ||
proactive_key_caching=1 | ||
} | ||
|
||
network={ | ||
ssid="test7" | ||
key_mgmt=WPA-EAP IEEE8021X | ||
eap=PEAP | ||
identity="abcdef" | ||
password="qwertyuiop" | ||
priority=24139 | ||
proactive_key_caching=1 | ||
disabled=1 | ||
} | ||
|
||
network={ | ||
ssid=61223d245c6f28233d3ee284a2e280a22c6b38 | ||
scan_ssid=1 | ||
key_mgmt=NONE | ||
} |