diff options
author | Hai Shalom <haishalom@google.com> | 2019-06-10 19:57:30 -0700 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2019-06-10 19:57:30 -0700 |
commit | 38eef6c26ed317447eacf0d2256c87c707a28cba (patch) | |
tree | a2b51e68bd55a29a45481e51cdd56ca2e0b8cf24 /tests | |
parent | 9e66cb3d40fc59ff70c1c552d911cbd5795e7211 (diff) | |
parent | d204d6018ee3275ba2241281ff930463da7d8ccd (diff) |
[Encrypted IMSI] Use the pseudonym if available am: 724f5ef108
am: d204d6018e
Change-Id: I5636cab4613a89abfa4adf7ff0db59a4cab08cdd
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java | 65 |
1 files changed, 60 insertions, 5 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java index b64bf3de5..a26582c5c 100644 --- a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java @@ -1033,10 +1033,10 @@ public class ClientModeImplTest { /** * Tests anonymous identity is set again whenever a connection is established for the carrier - * that supports encrypted IMSI and anonymous identity. + * that supports encrypted IMSI and anonymous identity and no real pseudonym was provided. */ @Test - public void testSetAnonymousIdentityWhenConnectionIsEstablished() throws Exception { + public void testSetAnonymousIdentityWhenConnectionIsEstablishedNoPseudonym() throws Exception { mConnectedNetwork = spy(WifiConfigurationTestUtil.createEapNetwork( WifiEnterpriseConfig.Eap.SIM, WifiEnterpriseConfig.Phase2.NONE)); when(mDataTelephonyManager.getSimOperator()).thenReturn("123456"); @@ -1059,16 +1059,71 @@ public class ClientModeImplTest { getGoogleGuestScanDetail(TEST_RSSI, sBSSID, sFreq)); when(mScanDetailCache.getScanResult(sBSSID)).thenReturn( getGoogleGuestScanDetail(TEST_RSSI, sBSSID, sFreq).getScanResult()); + when(mWifiNative.getEapAnonymousIdentity(anyString())) + .thenReturn(expectedAnonymousIdentity); mCmi.sendMessage(WifiMonitor.NETWORK_CONNECTION_EVENT, 0, 0, sBSSID); mLooper.dispatchAll(); - // verify that WifiNative#getEapAnonymousIdentity() was never called since we are using - // encrypted IMSI full authentication and not using pseudonym identity. - verify(mWifiNative, never()).getEapAnonymousIdentity(any()); + verify(mWifiNative).getEapAnonymousIdentity(any()); // check that the anonymous identity remains anonymous@<realm> for subsequent connections. assertEquals(expectedAnonymousIdentity, mConnectedNetwork.enterpriseConfig.getAnonymousIdentity()); + // verify that WifiConfigManager#addOrUpdateNetwork() was never called if there is no + // real pseudonym to be stored. i.e. Encrypted IMSI will be always used + // Note: This test will fail if future logic will have additional conditions that would + // trigger "add or update network" operation. The test needs to be updated to account for + // this change. + verify(mWifiConfigManager, never()).addOrUpdateNetwork(any(), anyInt()); + } + + /** + * Tests anonymous identity is set again whenever a connection is established for the carrier + * that supports encrypted IMSI and anonymous identity but real pseudonym was provided for + * subsequent connections. + */ + @Test + public void testSetAnonymousIdentityWhenConnectionIsEstablishedWithPseudonym() + throws Exception { + mConnectedNetwork = spy(WifiConfigurationTestUtil.createEapNetwork( + WifiEnterpriseConfig.Eap.SIM, WifiEnterpriseConfig.Phase2.NONE)); + when(mDataTelephonyManager.getSimOperator()).thenReturn("123456"); + when(mDataTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY); + mConnectedNetwork.enterpriseConfig.setAnonymousIdentity(""); + + String expectedAnonymousIdentity = "anonymous@wlan.mnc456.mcc123.3gppnetwork.org"; + String pseudonym = "83bcca9384fca@wlan.mnc456.mcc123.3gppnetwork.org"; + + when(mCarrierNetworkConfig.isCarrierEncryptionInfoAvailable()).thenReturn(true); + + triggerConnect(); + + // CMD_START_CONNECT should have set anonymousIdentity to anonymous@<realm> + assertEquals(expectedAnonymousIdentity, + mConnectedNetwork.enterpriseConfig.getAnonymousIdentity()); + + when(mWifiConfigManager.getScanDetailCacheForNetwork(FRAMEWORK_NETWORK_ID)) + .thenReturn(mScanDetailCache); + when(mScanDetailCache.getScanDetail(sBSSID)).thenReturn( + getGoogleGuestScanDetail(TEST_RSSI, sBSSID, sFreq)); + when(mScanDetailCache.getScanResult(sBSSID)).thenReturn( + getGoogleGuestScanDetail(TEST_RSSI, sBSSID, sFreq).getScanResult()); + when(mWifiNative.getEapAnonymousIdentity(anyString())) + .thenReturn(pseudonym); + + mCmi.sendMessage(WifiMonitor.NETWORK_CONNECTION_EVENT, 0, 0, sBSSID); + mLooper.dispatchAll(); + + verify(mWifiNative).getEapAnonymousIdentity(any()); + assertEquals(pseudonym, + mConnectedNetwork.enterpriseConfig.getAnonymousIdentity()); + // Verify that WifiConfigManager#addOrUpdateNetwork() was called if there we received a + // real pseudonym to be stored. i.e. Encrypted IMSI will be used once, followed by + // pseudonym usage in all subsequent connections. + // Note: This test will fail if future logic will have additional conditions that would + // trigger "add or update network" operation. The test needs to be updated to account for + // this change. + verify(mWifiConfigManager).addOrUpdateNetwork(any(), anyInt()); } /** |