summaryrefslogtreecommitdiffstats
path: root/tests/wifitests/src/com
diff options
context:
space:
mode:
authorNate(Qiang) Jiang <qiangjiang@google.com>2020-03-02 17:56:31 -0800
committerNate Jiang <qiangjiang@google.com>2020-03-04 00:58:36 +0000
commite6813a5870911b10561db2c259c072123c1c513a (patch)
tree226887436c7506e50d4c6dab3a455996f21f0c9c /tests/wifitests/src/com
parentd7d14da8eafb570f00287ac715d31ebca6fca164 (diff)
downloadandroid_frameworks_opt_net_wifi-e6813a5870911b10561db2c259c072123c1c513a.tar.gz
android_frameworks_opt_net_wifi-e6813a5870911b10561db2c259c072123c1c513a.tar.bz2
android_frameworks_opt_net_wifi-e6813a5870911b10561db2c259c072123c1c513a.zip
Enterprise suggestion's catificate share same lifecycle as suggestion
Enterprise network suggestion's catificate will add to keystore immediately after add the suggestion, and will only remove after suggestion is removed. Bug: 150500247 Test: atest com.android.server.wifi Merged-In: I85fb81a98f16b6a343fb35ce31e1426e333773b0 Change-Id: Icbe49911d7ca93b03dfdf728ad88057c31aa5974
Diffstat (limited to 'tests/wifitests/src/com')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java6
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiKeyStoreTest.java56
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java33
3 files changed, 93 insertions, 2 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
index 6fa1868cb..6a7785e5e 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
@@ -683,13 +683,14 @@ public class WifiConfigManagerTest {
*/
@Test
public void testAddSingleSuggestionNetwork() throws Exception {
- WifiConfiguration suggestionNetwork = WifiConfigurationTestUtil.createOpenNetwork();
+ WifiConfiguration suggestionNetwork = WifiConfigurationTestUtil.createEapNetwork();
suggestionNetwork.ephemeral = true;
suggestionNetwork.fromWifiNetworkSuggestion = true;
List<WifiConfiguration> networks = new ArrayList<>();
networks.add(suggestionNetwork);
verifyAddSuggestionOrRequestNetworkToWifiConfigManager(suggestionNetwork);
+ verify(mWifiKeyStore, never()).updateNetworkKeys(any(), any());
List<WifiConfiguration> retrievedNetworks =
mWifiConfigManager.getConfiguredNetworksWithPasswords();
@@ -699,6 +700,9 @@ public class WifiConfigManagerTest {
// Ensure that this is not returned in the saved network list.
assertTrue(mWifiConfigManager.getSavedNetworks(Process.WIFI_UID).isEmpty());
verify(mWcmListener, never()).onSavedNetworkAdded(suggestionNetwork.networkId);
+ assertTrue(mWifiConfigManager
+ .removeNetwork(suggestionNetwork.networkId, TEST_CREATOR_UID));
+ verify(mWifiKeyStore, never()).removeKeys(any());
}
/**
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiKeyStoreTest.java b/tests/wifitests/src/com/android/server/wifi/WifiKeyStoreTest.java
index 7079a2d53..7649d1ba4 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiKeyStoreTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiKeyStoreTest.java
@@ -16,11 +16,19 @@
package com.android.server.wifi;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.AdditionalMatchers.aryEq;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.validateMockitoUsage;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
+import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiEnterpriseConfig;
import android.os.Process;
import android.security.Credentials;
@@ -34,6 +42,8 @@ import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import java.security.cert.X509Certificate;
+
/**
* Unit tests for {@link com.android.server.wifi.WifiConfigManager}.
*/
@@ -43,8 +53,10 @@ public class WifiKeyStoreTest {
@Mock private KeyStore mKeyStore;
private WifiKeyStore mWifiKeyStore;
+ private static final String TEST_KEY_ID = "blah";
private static final String USER_CERT_ALIAS = "aabbccddee";
private static final String [] USER_CA_CERT_ALIAS = {"aacccddd", "bbbqqqqmmm"};
+ private static final String TEST_PACKAGE_NAME = "TestApp";
/**
* Setup the mocks and an instance of WifiConfigManager before each test.
@@ -57,6 +69,16 @@ public class WifiKeyStoreTest {
when(mWifiEnterpriseConfig.getClientCertificateAlias()).thenReturn(USER_CERT_ALIAS);
when(mWifiEnterpriseConfig.getCaCertificateAliases())
.thenReturn(USER_CA_CERT_ALIAS);
+ when(mKeyStore.put(anyString(), any(), anyInt(), anyInt())).thenReturn(true);
+ when(mKeyStore.importKey(anyString(), any(), anyInt(), anyInt())).thenReturn(true);
+ when(mWifiEnterpriseConfig.getClientPrivateKey()).thenReturn(FakeKeys.RSA_KEY1);
+ when(mWifiEnterpriseConfig.getClientCertificate()).thenReturn(FakeKeys.CLIENT_CERT);
+ when(mWifiEnterpriseConfig.getCaCertificate()).thenReturn(FakeKeys.CA_CERT0);
+ when(mWifiEnterpriseConfig.getClientCertificateChain())
+ .thenReturn(new X509Certificate[] {FakeKeys.CLIENT_CERT});
+ when(mWifiEnterpriseConfig.getCaCertificates())
+ .thenReturn(new X509Certificate[] {FakeKeys.CA_CERT0});
+ when(mWifiEnterpriseConfig.getKeyId(any())).thenReturn(TEST_KEY_ID);
}
/**
@@ -129,4 +151,38 @@ public class WifiKeyStoreTest {
mWifiKeyStore.removeKeys(mWifiEnterpriseConfig);
verifyNoMoreInteractions(mKeyStore);
}
+
+ /**
+ * Add two same network credential one is from user saved, the other is from suggestion.
+ * Both oh them should be installed successfully and has different alias, and will not override
+ * each other.
+ */
+ @Test
+ public void testAddFromBothSavedAndSuggestionNetwork() throws Exception {
+ WifiConfiguration savedNetwork = WifiConfigurationTestUtil.createEapNetwork();
+ WifiConfiguration suggestionNetwork = new WifiConfiguration(savedNetwork);
+ savedNetwork.enterpriseConfig = mWifiEnterpriseConfig;
+ suggestionNetwork.enterpriseConfig = mWifiEnterpriseConfig;
+ suggestionNetwork.fromWifiNetworkSuggestion = true;
+ suggestionNetwork.creatorName = TEST_PACKAGE_NAME;
+
+ assertTrue(mWifiKeyStore.updateNetworkKeys(savedNetwork, null));
+ assertTrue(mWifiKeyStore.updateNetworkKeys(suggestionNetwork, null));
+
+ String savedNetworkAlias = savedNetwork.getKeyIdForCredentials(null);
+ String savedNetworkCaAlias = savedNetworkAlias;
+
+ String suggestionNetworkAlias = suggestionNetwork.getKeyIdForCredentials(null);
+ String suggestionNetworkCaAlias = suggestionNetworkAlias;
+
+ assertNotEquals(savedNetworkAlias, suggestionNetworkAlias);
+
+ verify(mWifiEnterpriseConfig).setClientCertificateAlias(eq(savedNetworkAlias));
+ verify(mWifiEnterpriseConfig).setCaCertificateAliases(
+ aryEq(new String[] {savedNetworkCaAlias}));
+
+ verify(mWifiEnterpriseConfig).setClientCertificateAlias(eq(suggestionNetworkAlias));
+ verify(mWifiEnterpriseConfig).setCaCertificateAliases(
+ aryEq(new String[] {suggestionNetworkCaAlias}));
+ }
}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
index 612fdf575..9e183e729 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
@@ -102,6 +102,7 @@ public class WifiNetworkSuggestionsManagerTest {
private @Mock NetworkSuggestionStoreData mNetworkSuggestionStoreData;
private @Mock ClientModeImpl mClientModeImpl;
private @Mock WifiMetrics mWifiMetrics;
+ private @Mock WifiKeyStore mWifiKeyStore;
private TestLooper mLooper;
private ArgumentCaptor<AppOpsManager.OnOpChangedListener> mAppOpChangedListenerCaptor =
ArgumentCaptor.forClass(AppOpsManager.OnOpChangedListener.class);
@@ -161,7 +162,7 @@ public class WifiNetworkSuggestionsManagerTest {
mWifiNetworkSuggestionsManager =
new WifiNetworkSuggestionsManager(mContext, new Handler(mLooper.getLooper()),
mWifiInjector, mWifiPermissionsUtil, mWifiConfigManager, mWifiConfigStore,
- mWifiMetrics);
+ mWifiMetrics, mWifiKeyStore);
verify(mContext).getResources();
verify(mContext).getSystemService(Context.APP_OPS_SERVICE);
verify(mContext).getSystemService(Context.NOTIFICATION_SERVICE);
@@ -308,6 +309,36 @@ public class WifiNetworkSuggestionsManagerTest {
assertTrue(mWifiNetworkSuggestionsManager.getAllNetworkSuggestions().isEmpty());
}
+ @Test
+ public void testAddRemoveEnterpriseNetworkSuggestion() {
+ WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion(
+ WifiConfigurationTestUtil.createEapNetwork(), false, false, TEST_UID_1,
+ TEST_PACKAGE_1);
+ WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion(
+ WifiConfigurationTestUtil.createEapNetwork(), false, false, TEST_UID_2,
+ TEST_PACKAGE_2);
+
+ List<WifiNetworkSuggestion> networkSuggestionList =
+ new ArrayList<WifiNetworkSuggestion>() {{
+ add(networkSuggestion1);
+ add(networkSuggestion2);
+ }};
+ when(mWifiKeyStore.updateNetworkKeys(eq(networkSuggestion1.wifiConfiguration), any()))
+ .thenReturn(true);
+ when(mWifiKeyStore.updateNetworkKeys(eq(networkSuggestion2.wifiConfiguration), any()))
+ .thenReturn(false);
+ assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS,
+ mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1,
+ TEST_PACKAGE_1));
+
+ Set<WifiNetworkSuggestion> allNetworkSuggestions =
+ mWifiNetworkSuggestionsManager.getAllNetworkSuggestions();
+ assertEquals(1, allNetworkSuggestions.size());
+ assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS,
+ mWifiNetworkSuggestionsManager.remove(new ArrayList<>(),
+ TEST_UID_1, TEST_PACKAGE_1));
+ verify(mWifiKeyStore).removeKeys(any());
+ }
/**
* Verify successful replace (add,remove, add) of network suggestions.
*/