diff options
Diffstat (limited to 'tests')
3 files changed, 25 insertions, 8 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java index c99a1496a..8990f92c1 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java @@ -177,6 +177,7 @@ public class WifiConfigManagerTest { when(mWifiPermissionsUtil.checkNetworkSettingsPermission(anyInt())).thenReturn(true); when(mWifiPermissionsWrapper.getDevicePolicyManagerInternal()) .thenReturn(mDevicePolicyManagerInternal); + when(mWifiPermissionsUtil.doesUidBelongToCurrentUser(anyInt())).thenReturn(true); createWifiConfigManager(); mWifiConfigManager.setOnSavedNetworkUpdateListener(mWcmListener); } @@ -2148,6 +2149,8 @@ public class WifiConfigManagerTest { setupStoreDataForUserRead(user2Networks, new HashSet<String>()); // 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).switchUserStoreAndRead(any(WifiConfigStore.StoreFile.class)); assertTrue((removedNetworks.size() == 1) && (removedNetworks.contains(user1NetworkId))); @@ -2228,7 +2231,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; @@ -2261,6 +2264,8 @@ public class WifiConfigManagerTest { } }; setupStoreDataForUserRead(userNetworks, new HashSet<String>()); + when(mWifiPermissionsUtil.doesUidBelongToCurrentUser(user2Network.creatorUid)) + .thenReturn(false); mWifiConfigManager.handleUserUnlock(user1); verify(mWifiConfigStore).switchUserStoreAndRead(any(WifiConfigStore.StoreFile.class)); // Capture the written data for the user 1 and ensure that it corresponds to what was @@ -2275,6 +2280,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 @@ -2340,6 +2349,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 HashSet<String>()); + when(mWifiPermissionsUtil.doesUidBelongToCurrentUser(passpointConfig.creatorUid)) + .thenReturn(false); mWifiConfigManager.handleUserUnlock(user1); verify(mWifiConfigStore).switchUserStoreAndRead(any(WifiConfigStore.StoreFile.class)); Pair<List<WifiConfiguration>, List<WifiConfiguration>> writtenNetworkList = @@ -2463,7 +2474,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. @@ -2592,6 +2604,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); diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java index 69e6070ed..9bdea915c 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java @@ -1723,13 +1723,13 @@ public class WifiStateMachineTest { @Test public void syncRemovePasspointConfig() throws Exception { String fqdn = "test.com"; - when(mPasspointManager.removeProvider(fqdn)).thenReturn(true); + when(mPasspointManager.removeProvider(anyInt(), eq(fqdn))).thenReturn(true); mLooper.startAutoDispatch(); assertTrue(mWsm.syncRemovePasspointConfig(mWsmAsyncChannel, fqdn)); mLooper.stopAutoDispatch(); reset(mPasspointManager); - when(mPasspointManager.removeProvider(fqdn)).thenReturn(false); + when(mPasspointManager.removeProvider(anyInt(), eq(fqdn))).thenReturn(false); mLooper.startAutoDispatch(); assertFalse(mWsm.syncRemovePasspointConfig(mWsmAsyncChannel, fqdn)); mLooper.stopAutoDispatch(); diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java index 01566c203..abe593ce6 100644 --- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java @@ -78,6 +78,7 @@ import com.android.server.wifi.hotspot2.anqp.HSOsuProvidersElement; import com.android.server.wifi.hotspot2.anqp.I18Name; import com.android.server.wifi.hotspot2.anqp.OsuProviderInfo; import com.android.server.wifi.util.ScanResultUtil; +import com.android.server.wifi.util.WifiPermissionsUtil; import org.junit.Before; import org.junit.Test; @@ -130,6 +131,7 @@ public class PasspointManagerTest { @Mock WifiConfigStore mWifiConfigStore; @Mock PasspointConfigStoreData.DataSource mDataSource; @Mock WifiMetrics mWifiMetrics; + @Mock WifiPermissionsUtil mWifiPermissionsUtil; PasspointManager mManager; /** Sets up test. */ @@ -141,7 +143,8 @@ public class PasspointManagerTest { .thenReturn(mAnqpRequestManager); when(mObjectFactory.makeCertificateVerifier()).thenReturn(mCertVerifier); mManager = new PasspointManager(mContext, mWifiNative, mWifiKeyStore, mClock, - mSimAccessor, mObjectFactory, mWifiConfigManager, mWifiConfigStore, mWifiMetrics); + mSimAccessor, mObjectFactory, mWifiConfigManager, mWifiConfigStore, mWifiMetrics, + mWifiPermissionsUtil); ArgumentCaptor<PasspointEventHandler.Callbacks> callbacks = ArgumentCaptor.forClass(PasspointEventHandler.Callbacks.class); verify(mObjectFactory).makePasspointEventHandler(any(WifiNative.class), @@ -472,7 +475,7 @@ public class PasspointManagerTest { assertEquals(1, mDataSource.getProviderIndex()); // Remove the provider. - assertTrue(mManager.removeProvider(TEST_FQDN)); + assertTrue(mManager.removeProvider(TEST_CREATOR_UID, TEST_FQDN)); verify(provider).uninstallCertsAndKeys(); verify(mWifiConfigManager).saveToStore(true); verify(mWifiMetrics).incrementNumPasspointProviderUninstallation(); @@ -512,7 +515,7 @@ public class PasspointManagerTest { assertEquals(1, mDataSource.getProviderIndex()); // Remove the provider. - assertTrue(mManager.removeProvider(TEST_FQDN)); + assertTrue(mManager.removeProvider(TEST_CREATOR_UID, TEST_FQDN)); verify(provider).uninstallCertsAndKeys(); verify(mWifiConfigManager).saveToStore(true); verify(mWifiMetrics).incrementNumPasspointProviderUninstallation(); @@ -632,7 +635,7 @@ public class PasspointManagerTest { */ @Test public void removeNonExistingProvider() throws Exception { - assertFalse(mManager.removeProvider(TEST_FQDN)); + assertFalse(mManager.removeProvider(TEST_CREATOR_UID, TEST_FQDN)); verify(mWifiMetrics).incrementNumPasspointProviderUninstallation(); verify(mWifiMetrics, never()).incrementNumPasspointProviderUninstallSuccess(); } |