summaryrefslogtreecommitdiff
path: root/tests
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-18 03:21:08 +0000
commit6853a19f2da130483fbe4082b457f1cf6a21e542 (patch)
treebeef7242624bd9169f847c2255b95da487666e2a /tests
parentb4486b2a1bce042384b6da156aced9c8ff76b5ec (diff)
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: Icbe49911d7ca93b03dfdf728ad88057c31aa5974 Change-Id: Icbe49911d7ca93b03dfdf728ad88057c31aa5974 (cherry picked from commit e6813a5870911b10561db2c259c072123c1c513a)
Diffstat (limited to 'tests')
-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.java38
3 files changed, 98 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 ce1c6b2ee..fdcd948f9 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
@@ -670,13 +670,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();
@@ -686,6 +687,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 ade54bd14..ed3e6d07f 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
@@ -67,6 +67,7 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -101,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);
@@ -158,7 +160,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);
@@ -301,6 +303,40 @@ 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());
+ WifiNetworkSuggestion removingSuggestion = new WifiNetworkSuggestion(
+ WifiConfigurationTestUtil.createEapNetwork(), false, false, TEST_UID_1,
+ TEST_PACKAGE_1);
+ removingSuggestion.wifiConfiguration.SSID = networkSuggestion1.wifiConfiguration.SSID;
+ assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS,
+ mWifiNetworkSuggestionsManager.remove(Arrays.asList(removingSuggestion),
+ TEST_PACKAGE_1));
+ verify(mWifiKeyStore).removeKeys(any());
+ }
/**
* Verify successful replace (add,remove, add) of network suggestions.
*/