summaryrefslogtreecommitdiff
path: root/wifi/tests
diff options
context:
space:
mode:
authorNate(Qiang) Jiang <qiangjiang@google.com>2020-03-02 17:09:44 -0800
committerNate Jiang <qiangjiang@google.com>2020-03-04 00:58:50 +0000
commit96a9e48520fc2359a3cdd6b3513bf158d6844365 (patch)
tree6d4fa33c6bd7ea155b7758f8df8db2cd6a2db325 /wifi/tests
parent97af8f1a55e06d429c073c5fd2ef6f6ec7a43494 (diff)
Create different KeyId for saved and suggestion network
Bug: 150500247 Test: atest android.net.wifi Merged-In: I31ee6f3a3295aca0bd7fcb83ce74327922977797 Change-Id: Ia416b2e986c86fe0a29641f6a20236802d72a233
Diffstat (limited to 'wifi/tests')
-rw-r--r--wifi/tests/src/android/net/wifi/WifiConfigurationTest.java61
1 files changed, 61 insertions, 0 deletions
diff --git a/wifi/tests/src/android/net/wifi/WifiConfigurationTest.java b/wifi/tests/src/android/net/wifi/WifiConfigurationTest.java
index ba9fc786afe7..f56cdc30af36 100644
--- a/wifi/tests/src/android/net/wifi/WifiConfigurationTest.java
+++ b/wifi/tests/src/android/net/wifi/WifiConfigurationTest.java
@@ -350,6 +350,67 @@ public class WifiConfigurationTest {
}
/**
+ * Verifies that getKeyIdForCredentials returns the expected string for Suggestion Enterprise
+ * networks
+ * @throws Exception
+ */
+ @Test
+ public void testGetKeyIdForCredentialsForSuggestion() throws Exception {
+ WifiConfiguration config = new WifiConfiguration();
+ final String mSsid = "TestAP";
+ final String packageName = "TestApp";
+ final String bSsid = MacAddress.createRandomUnicastAddress().toString();
+ String suggestionSuffix = "_" + bSsid + "_" + packageName;
+ config.SSID = mSsid;
+ config.fromWifiNetworkSuggestion = true;
+ config.creatorName = packageName;
+ config.BSSID = bSsid;
+
+ // Test various combinations
+ // EAP with TLS
+ config.allowedKeyManagement.set(KeyMgmt.WPA_EAP);
+ config.enterpriseConfig.setEapMethod(WifiEnterpriseConfig.Eap.TLS);
+ config.enterpriseConfig.setPhase2Method(WifiEnterpriseConfig.Phase2.NONE);
+ String keyId = config.getKeyIdForCredentials(config);
+ assertEquals(keyId, mSsid + "_WPA_EAP_TLS_NULL" + suggestionSuffix);
+
+ // EAP with TTLS & MSCHAPv2
+ config.allowedKeyManagement.set(KeyMgmt.WPA_EAP);
+ config.enterpriseConfig.setEapMethod(WifiEnterpriseConfig.Eap.TTLS);
+ config.enterpriseConfig.setPhase2Method(WifiEnterpriseConfig.Phase2.MSCHAPV2);
+ keyId = config.getKeyIdForCredentials(config);
+ assertEquals(keyId, mSsid + "_WPA_EAP_TTLS_MSCHAPV2" + suggestionSuffix);
+
+ // Suite-B 192 with PWD & GTC
+ config.allowedKeyManagement.clear();
+ config.allowedKeyManagement.set(KeyMgmt.SUITE_B_192);
+ config.enterpriseConfig.setEapMethod(WifiEnterpriseConfig.Eap.PWD);
+ config.enterpriseConfig.setPhase2Method(WifiEnterpriseConfig.Phase2.GTC);
+ keyId = config.getKeyIdForCredentials(config);
+ assertEquals(keyId, mSsid + "_SUITE_B_192_PWD_GTC" + suggestionSuffix);
+
+ // IEEE8021X with SIM
+ config.allowedKeyManagement.clear();
+ config.allowedKeyManagement.set(KeyMgmt.IEEE8021X);
+ config.enterpriseConfig.setEapMethod(WifiEnterpriseConfig.Eap.SIM);
+ config.enterpriseConfig.setPhase2Method(WifiEnterpriseConfig.Phase2.NONE);
+ keyId = config.getKeyIdForCredentials(config);
+ assertEquals(keyId, mSsid + "_IEEE8021X_SIM_NULL" + suggestionSuffix);
+
+ // Try calling this method with non-Enterprise network, expect an exception
+ boolean exceptionThrown = false;
+ try {
+ config.allowedKeyManagement.clear();
+ config.allowedKeyManagement.set(KeyMgmt.WPA2_PSK);
+ config.preSharedKey = "TestPsk";
+ keyId = config.getKeyIdForCredentials(config);
+ } catch (IllegalStateException e) {
+ exceptionThrown = true;
+ }
+ assertTrue(exceptionThrown);
+ }
+
+ /**
* Verifies that getSsidAndSecurityTypeString returns the correct String for networks of
* various different security types
*/