summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNate Jiang <qiangjiang@google.com>2020-03-03 20:31:52 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2020-03-03 20:31:52 +0000
commit15d889dc2c5f8b7ce539407c2e8e13359dea70f6 (patch)
treea23d9f9caccec8dcab3a74cafbb25a7818f8d860 /tests
parente194bea0c7191a6df4edd17bf91d1948c1fbe687 (diff)
parent356b551b797db1cdbf52a867a8c8dd6f8041892d (diff)
Merge "Enterprise suggestion's certificate share same lifecycle as suggestion" into rvc-dev
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/NetworkSuggestionNominatorTest.java3
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java6
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiKeyStoreTest.java44
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java36
4 files changed, 87 insertions, 2 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionNominatorTest.java b/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionNominatorTest.java
index 77d3f7ab8..1ce8d6eae 100644
--- a/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionNominatorTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionNominatorTest.java
@@ -953,6 +953,9 @@ public class NetworkSuggestionNominatorTest extends WifiBaseTest {
configs[i].meteredOverride = meteredness[i]
? WifiConfiguration.METERED_OVERRIDE_METERED
: WifiConfiguration.METERED_OVERRIDE_NONE;
+ configs[i].creatorName = packageNames[i];
+ configs[i].ephemeral = true;
+ configs[i].fromWifiNetworkSuggestion = true;
PerAppInfo perAppInfo = new PerAppInfo(uids[i], packageNames[i], null);
WifiNetworkSuggestion suggestion =
new WifiNetworkSuggestion(configs[i], null, appInteractions[i], false,
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
index 3ff4aa239..08c4eac9a 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
@@ -732,7 +732,7 @@ public class WifiConfigManagerTest extends WifiBaseTest {
*/
@Test
public void testAddSingleSuggestionNetwork() throws Exception {
- WifiConfiguration suggestionNetwork = WifiConfigurationTestUtil.createOpenNetwork();
+ WifiConfiguration suggestionNetwork = WifiConfigurationTestUtil.createEapNetwork();
ArgumentCaptor<WifiConfiguration> wifiConfigCaptor =
ArgumentCaptor.forClass(WifiConfiguration.class);
suggestionNetwork.ephemeral = true;
@@ -741,6 +741,7 @@ public class WifiConfigManagerTest extends WifiBaseTest {
networks.add(suggestionNetwork);
verifyAddSuggestionOrRequestNetworkToWifiConfigManager(suggestionNetwork);
+ verify(mWifiKeyStore, never()).updateNetworkKeys(any(), any());
List<WifiConfiguration> retrievedNetworks =
mWifiConfigManager.getConfiguredNetworksWithPasswords();
@@ -751,6 +752,9 @@ public class WifiConfigManagerTest extends WifiBaseTest {
assertTrue(mWifiConfigManager.getSavedNetworks(Process.WIFI_UID).isEmpty());
verify(mWcmListener).onNetworkAdded(wifiConfigCaptor.capture());
assertEquals(suggestionNetwork.networkId, wifiConfigCaptor.getValue().networkId);
+ assertTrue(mWifiConfigManager
+ .removeNetwork(suggestionNetwork.networkId, TEST_CREATOR_UID, TEST_CREATOR_NAME));
+ 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 4fc156518..49232b485 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiKeyStoreTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiKeyStoreTest.java
@@ -16,6 +16,7 @@
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;
@@ -51,6 +52,7 @@ public class WifiKeyStoreTest extends WifiBaseTest {
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.
@@ -159,4 +161,46 @@ public class WifiKeyStoreTest extends WifiBaseTest {
verify(mWifiEnterpriseConfig).setCaCertificateAliases(
aryEq(new String[] {expectedCaAlias}));
}
+
+ /**
+ * 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 testAddRemoveFromBothSavedAndSuggestionNetwork() 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 + "_0";
+
+ String suggestionNetworkAlias = suggestionNetwork.getKeyIdForCredentials(null);
+ String suggestionNetworkCaAlias = suggestionNetworkAlias + "_0";
+
+ assertNotEquals(savedNetworkAlias, suggestionNetworkAlias);
+
+ verify(mKeyStore).setKeyEntry(
+ eq(savedNetworkAlias), eq(FakeKeys.RSA_KEY1), eq(null),
+ aryEq(new X509Certificate[] {FakeKeys.CLIENT_CERT}));
+ verify(mKeyStore).setCertificateEntry(eq(savedNetworkCaAlias), eq(FakeKeys.CA_CERT0));
+ verify(mWifiEnterpriseConfig).setClientCertificateAlias(eq(savedNetworkAlias));
+ verify(mWifiEnterpriseConfig).setCaCertificateAliases(
+ aryEq(new String[] {savedNetworkCaAlias}));
+
+ verify(mKeyStore).setKeyEntry(
+ eq(suggestionNetworkAlias), eq(FakeKeys.RSA_KEY1), eq(null),
+ aryEq(new X509Certificate[] {FakeKeys.CLIENT_CERT}));
+ verify(mKeyStore).setCertificateEntry(eq(suggestionNetworkCaAlias), eq(FakeKeys.CA_CERT0));
+ 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 fe9ef7ac3..9a8454431 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
@@ -136,6 +136,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
private @Mock IBinder mBinder;
private @Mock ActivityManager mActivityManager;
private @Mock WifiScoreCard mWifiScoreCard;
+ private @Mock WifiKeyStore mWifiKeyStore;
private TestLooper mLooper;
private ArgumentCaptor<AppOpsManager.OnOpChangedListener> mAppOpChangedListenerCaptor =
ArgumentCaptor.forClass(AppOpsManager.OnOpChangedListener.class);
@@ -212,10 +213,12 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
when(mTelephonyUtil.getCarrierIdForPackageWithCarrierPrivileges(any())).thenReturn(
TelephonyManager.UNKNOWN_CARRIER_ID);
+ when(mWifiKeyStore.updateNetworkKeys(any(), any())).thenReturn(true);
+
mWifiNetworkSuggestionsManager =
new WifiNetworkSuggestionsManager(mContext, new Handler(mLooper.getLooper()),
mWifiInjector, mWifiPermissionsUtil, mWifiConfigManager, mWifiConfigStore,
- mWifiMetrics, mTelephonyUtil);
+ mWifiMetrics, mTelephonyUtil, mWifiKeyStore);
verify(mContext).getResources();
verify(mContext).getSystemService(Context.APP_OPS_SERVICE);
verify(mContext).getSystemService(Context.NOTIFICATION_SERVICE);
@@ -344,6 +347,37 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
assertEquals(maxSizesCaptor.getValue(), new ArrayList<Integer>() {{ add(1); add(1); }});
}
+ @Test
+ public void testAddRemoveEnterpriseNetworkSuggestion() {
+ WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion(
+ WifiConfigurationTestUtil.createEapNetwork(), null, false, false, true, true,
+ false);
+ WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion(
+ WifiConfigurationTestUtil.createEapNetwork(), null, false, false, true, true,
+ false);
+
+ List<WifiNetworkSuggestion> networkSuggestionList =
+ new ArrayList<WifiNetworkSuggestion>() {{
+ add(networkSuggestion1);
+ add(networkSuggestion2);
+ }};
+ when(mWifiKeyStore.updateNetworkKeys(eq(networkSuggestion1.wifiConfiguration), any()))
+ .thenReturn(true);
+ when(mWifiKeyStore.updateNetworkKeys(eq(networkSuggestion1.wifiConfiguration), any()))
+ .thenReturn(false);
+ assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS,
+ mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1,
+ TEST_PACKAGE_1, TEST_FEATURE));
+
+ 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 removal of all network suggestions.
*/