summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2017-03-08 21:25:00 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2017-03-08 21:25:01 +0000
commit1f5fa7821525dfaa5344a58f4d1efd0eb4e8c039 (patch)
treebf57cda79f72902c018f317eaf520c25b8010921 /tests
parent136c7ba4dc189068fb63457a60f642ca499ed63c (diff)
parenta63ab49c1d20d7a698537b5253d172a8dffc235f (diff)
Merge changes from topic 'raw_psk'
* changes: WifiConfigManager: Add quotes back for psk SupplicantStaNetworkHal: Add support for raw psk
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java46
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java41
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java2
3 files changed, 85 insertions, 4 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java b/tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java
index 3c8425a4f..b48d2b667 100644
--- a/tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java
@@ -18,7 +18,9 @@ package com.android.server.wifi;
import static org.junit.Assert.*;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -91,13 +93,35 @@ public class SupplicantStaNetworkHalTest {
}
/**
- * Tests the saving/loading of WifiConfiguration to wpa_supplicant.
+ * Tests the saving/loading of WifiConfiguration to wpa_supplicant with psk passphrase.
*/
@Test
- public void testPskNetworkWifiConfigurationSaveLoad() throws Exception {
+ public void testPskPassphraseNetworkWifiConfigurationSaveLoad() throws Exception {
WifiConfiguration config = WifiConfigurationTestUtil.createPskNetwork();
config.requirePMF = true;
testWifiConfigurationSaveLoad(config);
+ verify(mISupplicantStaNetworkMock).setPskPassphrase(anyString());
+ verify(mISupplicantStaNetworkMock)
+ .getPskPassphrase(any(ISupplicantStaNetwork.getPskPassphraseCallback.class));
+ verify(mISupplicantStaNetworkMock, never()).setPsk(any(byte[].class));
+ verify(mISupplicantStaNetworkMock, never())
+ .getPsk(any(ISupplicantStaNetwork.getPskCallback.class));
+ }
+
+ /**
+ * Tests the saving/loading of WifiConfiguration to wpa_supplicant with raw psk.
+ */
+ @Test
+ public void testPskNetworkWifiConfigurationSaveLoad() throws Exception {
+ WifiConfiguration config = WifiConfigurationTestUtil.createPskNetwork();
+ config.preSharedKey = "945ef00c463c2a7c2496376b13263d1531366b46377179a4b17b393687450779";
+ testWifiConfigurationSaveLoad(config);
+ verify(mISupplicantStaNetworkMock).setPsk(any(byte[].class));
+ verify(mISupplicantStaNetworkMock)
+ .getPsk(any(ISupplicantStaNetwork.getPskCallback.class));
+ verify(mISupplicantStaNetworkMock, never()).setPskPassphrase(anyString());
+ verify(mISupplicantStaNetworkMock)
+ .getPskPassphrase(any(ISupplicantStaNetwork.getPskPassphraseCallback.class));
}
/**
@@ -824,7 +848,7 @@ public class SupplicantStaNetworkHalTest {
}).when(mISupplicantStaNetworkMock)
.getRequirePmf(any(ISupplicantStaNetwork.getRequirePmfCallback.class));
- /** PSK pass phrase*/
+ /** PSK passphrase */
doAnswer(new AnswerWithArguments() {
public SupplicantStatus answer(String pskPassphrase) throws RemoteException {
mSupplicantVariables.pskPassphrase = pskPassphrase;
@@ -839,6 +863,21 @@ public class SupplicantStaNetworkHalTest {
}).when(mISupplicantStaNetworkMock)
.getPskPassphrase(any(ISupplicantStaNetwork.getPskPassphraseCallback.class));
+ /** PSK */
+ doAnswer(new AnswerWithArguments() {
+ public SupplicantStatus answer(byte[] psk) throws RemoteException {
+ mSupplicantVariables.psk = psk;
+ return mStatusSuccess;
+ }
+ }).when(mISupplicantStaNetworkMock).setPsk(any(byte[].class));
+ doAnswer(new AnswerWithArguments() {
+ public void answer(ISupplicantStaNetwork.getPskCallback cb)
+ throws RemoteException {
+ cb.onValues(mStatusSuccess, mSupplicantVariables.psk);
+ }
+ }).when(mISupplicantStaNetworkMock)
+ .getPsk(any(ISupplicantStaNetwork.getPskCallback.class));
+
/** WEP keys **/
doAnswer(new AnswerWithArguments() {
public SupplicantStatus answer(int keyIdx, ArrayList<Byte> key) throws RemoteException {
@@ -1234,6 +1273,7 @@ public class SupplicantStaNetworkHalTest {
public String idStr;
public int updateIdentifier;
public String pskPassphrase;
+ public byte[] psk;
public ArrayList<Byte>[] wepKey = new ArrayList[4];
public int wepTxKeyIdx;
public int eapMethod = -1;
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
index 4a2c4c288..a00458726 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
@@ -2497,6 +2497,47 @@ public class WifiConfigManagerTest {
}
/**
+ * Verifies the loading of networks using {@link WifiConfigManager#loadFromStore()}:
+ * - Adds quotes around unquoted ascii PSKs when loading form store.
+ * - Loads asciis quoted PSKs as they are.
+ * - Loads base64 encoded as they are.
+ */
+ @Test
+ public void testUnquotedAsciiPassphraseLoadFromStore() throws Exception {
+ WifiConfiguration pskNetworkWithNoQuotes = WifiConfigurationTestUtil.createPskNetwork();
+ pskNetworkWithNoQuotes.preSharedKey = "pskWithNoQuotes";
+ WifiConfiguration pskNetworkWithQuotes = WifiConfigurationTestUtil.createPskNetwork();
+ pskNetworkWithQuotes.preSharedKey = "\"pskWithQuotes\"";
+ WifiConfiguration pskNetworkWithHexString = WifiConfigurationTestUtil.createPskNetwork();
+ pskNetworkWithHexString.preSharedKey =
+ "945ef00c463c2a7c2496376b13263d1531366b46377179a4b17b393687450779";
+
+ List<WifiConfiguration> sharedNetworks = new ArrayList<WifiConfiguration>() {{
+ add(new WifiConfiguration(pskNetworkWithQuotes));
+ add(new WifiConfiguration(pskNetworkWithNoQuotes));
+ add(new WifiConfiguration(pskNetworkWithHexString));
+ }};
+ setupStoreDataForRead(sharedNetworks, new ArrayList<>(), new HashSet<String>());
+ assertTrue(mWifiConfigManager.loadFromStore());
+
+ verify(mWifiConfigStore).read();
+ verify(mWifiConfigStoreLegacy, never()).read();
+
+ List<WifiConfiguration> retrievedNetworks =
+ mWifiConfigManager.getConfiguredNetworksWithPasswords();
+
+ // The network with no quotes should now have quotes, the others should remain the same.
+ pskNetworkWithNoQuotes.preSharedKey = "\"pskWithNoQuotes\"";
+ List<WifiConfiguration> expectedNetworks = new ArrayList<WifiConfiguration>() {{
+ add(pskNetworkWithQuotes);
+ add(pskNetworkWithNoQuotes);
+ add(pskNetworkWithHexString);
+ }};
+ WifiConfigurationTestUtil.assertConfigurationsEqualForConfigStore(
+ expectedNetworks, retrievedNetworks);
+ }
+
+ /**
* Verifies that the last user selected network parameter is set when
* {@link WifiConfigManager#enableNetwork(int, boolean, int)} with disableOthers flag is set
* to true and cleared when either {@link WifiConfigManager#disableNetwork(int, int)} or
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java
index dba4d2f00..6b411dad5 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java
@@ -61,7 +61,7 @@ public class WifiConfigurationTestUtil {
public static final int TEST_NETWORK_ID = -1;
public static final int TEST_UID = 5;
public static final String TEST_SSID = "WifiConfigurationTestUtilSSID";
- public static final String TEST_PSK = "WifiConfigurationTestUtilPsk";
+ public static final String TEST_PSK = "\"WifiConfigurationTestUtilPsk\"";
public static final String[] TEST_WEP_KEYS =
{"\"WifiConfigurationTestUtilWep1\"", "\"WifiConfigurationTestUtilWep2\"",
"45342312ab", "45342312ab45342312ab34ac12"};