summaryrefslogtreecommitdiff
path: root/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
diff options
context:
space:
mode:
authorNate Jiang <qiangjiang@google.com>2020-12-03 14:31:30 -0800
committermosimchah <mosimchah@gmail.com>2021-03-04 18:56:02 -0500
commitd683bd717017644f520a9365a9f56c837b6c284c (patch)
tree4932148b62a9c4e4941ae6e6c8f8529e9d471081 /tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
parent07ee233512c631e2a434bb371c9bd8c8158adaf6 (diff)
[Suggestion] Check foreground user for API callHEADq10.0
Also, squashes the follow up commit to create a single CL for backporting: ======= PasspointManager: Don't allow bg user to modify passpoint profiles Also, add safety net logging for this bug. ======= Bug: 174749461 Test: atest com.android.server.wifi Change-Id: Ifc79ffeb04a7be99a9c60d9414b72e88275c0514 Merged-In: Ifc79ffeb04a7be99a9c60d9414b72e88275c0514 (cherry picked from commit e799efba85cbe52044a067869af71d9c15b573bb) (cherry picked from commit 23685b8604571ec623e539f4f9c66db65c9dde81) (cherry picked from commit 95673e85133c78773870fb5161bb300b7f2ee51e)
Diffstat (limited to 'tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java18
1 files changed, 16 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 0f48af9cc..f5ad049dd 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
@@ -227,6 +227,7 @@ public class WifiConfigManagerTest {
when(mWifiInjector.getMacAddressUtil()).thenReturn(mMacAddressUtil);
when(mMacAddressUtil.calculatePersistentMacForConfiguration(any(), any()))
.thenReturn(TEST_RANDOMIZED_MAC);
+ when(mWifiPermissionsUtil.doesUidBelongToCurrentUser(anyInt())).thenReturn(true);
createWifiConfigManager();
mWifiConfigManager.setOnSavedNetworkUpdateListener(mWcmListener);
@@ -3020,6 +3021,8 @@ public class WifiConfigManagerTest {
setupStoreDataForUserRead(user2Networks, new HashMap<>());
// Now switch the user to user 2 and ensure that user 1's private network has been removed.
when(mUserManager.isUserUnlockingOrUnlocked(user2)).thenReturn(true);
+ when(mWifiPermissionsUtil.doesUidBelongToCurrentUser(user1Network.creatorUid))
+ .thenReturn(false);
Set<Integer> removedNetworks = mWifiConfigManager.handleUserSwitch(user2);
verify(mWifiConfigStore).switchUserStoresAndRead(any(List.class));
assertTrue((removedNetworks.size() == 1) && (removedNetworks.contains(user1NetworkId)));
@@ -3099,7 +3102,7 @@ public class WifiConfigManagerTest {
public void testHandleUserSwitchPushesOtherPrivateNetworksToSharedStore() throws Exception {
int user1 = TEST_DEFAULT_USER;
int user2 = TEST_DEFAULT_USER + 1;
- setupUserProfiles(user2);
+ setupUserProfiles(user1);
int appId = 674;
@@ -3131,6 +3134,8 @@ public class WifiConfigManagerTest {
}
};
setupStoreDataForUserRead(userNetworks, new HashMap<>());
+ when(mWifiPermissionsUtil.doesUidBelongToCurrentUser(user2Network.creatorUid))
+ .thenReturn(false);
mWifiConfigManager.handleUserUnlock(user1);
verify(mWifiConfigStore).switchUserStoresAndRead(any(List.class));
// Capture the written data for the user 1 and ensure that it corresponds to what was
@@ -3145,6 +3150,10 @@ public class WifiConfigManagerTest {
// Now switch the user to user2 and ensure that user 2's private network has been moved to
// the user store.
when(mUserManager.isUserUnlockingOrUnlocked(user2)).thenReturn(true);
+ when(mWifiPermissionsUtil.doesUidBelongToCurrentUser(user1Network.creatorUid))
+ .thenReturn(true).thenReturn(false);
+ when(mWifiPermissionsUtil.doesUidBelongToCurrentUser(user2Network.creatorUid))
+ .thenReturn(false).thenReturn(true);
mWifiConfigManager.handleUserSwitch(user2);
// Set the expected network list before comparing. user1Network should be in shared data.
// Note: In the real world, user1Network will no longer be visible now because it should
@@ -3209,6 +3218,8 @@ public class WifiConfigManagerTest {
// Unlock the owner of the legacy Passpoint configuration, verify it is removed from
// the configured networks (migrated to PasspointManager).
setupStoreDataForUserRead(new ArrayList<WifiConfiguration>(), new HashMap<>());
+ when(mWifiPermissionsUtil.doesUidBelongToCurrentUser(passpointConfig.creatorUid))
+ .thenReturn(false);
mWifiConfigManager.handleUserUnlock(user1);
verify(mWifiConfigStore).switchUserStoresAndRead(any(List.class));
Pair<List<WifiConfiguration>, List<WifiConfiguration>> writtenNetworkList =
@@ -3336,7 +3347,8 @@ public class WifiConfigManagerTest {
// Ensure that we have 2 networks in the database before the stop.
assertEquals(2, mWifiConfigManager.getConfiguredNetworks().size());
-
+ when(mWifiPermissionsUtil.doesUidBelongToCurrentUser(user1Network.creatorUid))
+ .thenReturn(false);
mWifiConfigManager.handleUserStop(user1);
// Ensure that we only have 1 shared network in the database after the stop.
@@ -3537,6 +3549,8 @@ public class WifiConfigManagerTest {
int creatorUid = UserHandle.getUid(user2, 674);
+ when(mWifiPermissionsUtil.doesUidBelongToCurrentUser(creatorUid)).thenReturn(false);
+
// Create a network for user2 try adding it. This should be rejected.
final WifiConfiguration user2Network = WifiConfigurationTestUtil.createPskNetwork();
NetworkUpdateResult result = addNetworkToWifiConfigManager(user2Network, creatorUid);