diff options
author | Jimmy Chen <jimmycmchen@google.com> | 2020-04-24 08:24:43 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-04-24 08:24:43 +0000 |
commit | 4564b7cda120fee09a01bc6ce3982cb2c5149931 (patch) | |
tree | ceeeaaf14e140add8de4eef2197a2f831376221f /tests | |
parent | 65d9ad5fd183f58dd2a962913148fef1bb612d08 (diff) | |
parent | 88033a33dcead214184dd0c368ba69e0452a39f8 (diff) |
Merge changes Ia4c555de,I22fe4d31 into rvc-dev
* changes:
Wifi: remove PMK cache if MAC is changed
Wifi: clear cached data if a connection attempt fails
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java | 77 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java | 57 |
2 files changed, 130 insertions, 4 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java index 0c48521e1..8f36770e6 100644 --- a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java @@ -4997,4 +4997,81 @@ public class ClientModeImplTest extends WifiBaseTest { verifyNoMoreInteractions(mNetworkAgentHandler); } + + /* + * Verify that network cached data is cleared correctly in + * disconnected state. + */ + @Test + public void testNetworkCachedDataIsClearedCorrectlyInDisconnectedState() throws Exception { + // Setup CONNECT_MODE & a WifiConfiguration + initializeAndAddNetworkAndVerifySuccess(); + mCmi.sendMessage(ClientModeImpl.CMD_START_CONNECT, 0, 0, sBSSID); + mLooper.dispatchAll(); + + // got UNSPECIFIED during this connection attempt + mCmi.sendMessage(WifiMonitor.NETWORK_DISCONNECTION_EVENT, 0, 1, sBSSID); + mLooper.dispatchAll(); + + assertEquals("DisconnectedState", getCurrentState().getName()); + verify(mWifiNative, never()).removeNetworkCachedData(anyInt()); + + // got 4WAY_HANDSHAKE_TIMEOUT during this connection attempt + mCmi.sendMessage(WifiMonitor.NETWORK_DISCONNECTION_EVENT, 0, 15, sBSSID); + mLooper.dispatchAll(); + + assertEquals("DisconnectedState", getCurrentState().getName()); + verify(mWifiNative).removeNetworkCachedData(FRAMEWORK_NETWORK_ID); + } + + /* + * Verify that network cached data is cleared correctly in + * disconnected state. + */ + @Test + public void testNetworkCachedDataIsClearedCorrectlyInObtainingIpState() throws Exception { + initializeAndAddNetworkAndVerifySuccess(); + + verify(mWifiNative).removeAllNetworks(WIFI_IFACE_NAME); + + IActionListener connectActionListener = mock(IActionListener.class); + mCmi.connect(null, 0, mock(Binder.class), connectActionListener, 0, Binder.getCallingUid()); + mLooper.dispatchAll(); + verify(connectActionListener).onSuccess(); + + verify(mWifiConfigManager).enableNetwork(eq(0), eq(true), anyInt(), any()); + + mCmi.sendMessage(WifiMonitor.NETWORK_CONNECTION_EVENT, 0, 0, sBSSID); + mLooper.dispatchAll(); + + mCmi.sendMessage(WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT, 0, 0, + new StateChangeResult(0, sWifiSsid, sBSSID, SupplicantState.COMPLETED)); + mLooper.dispatchAll(); + + assertEquals("ObtainingIpState", getCurrentState().getName()); + + // got 4WAY_HANDSHAKE_TIMEOUT during this connection attempt + mCmi.sendMessage(WifiMonitor.NETWORK_DISCONNECTION_EVENT, 0, 15, sBSSID); + mLooper.dispatchAll(); + + verify(mWifiNative).removeNetworkCachedData(FRAMEWORK_NETWORK_ID); + } + + /* + * Verify that network cached data is NOT cleared in ConnectedState. + */ + @Test + public void testNetworkCachedDataIsClearedIf4WayHandshakeFailure() throws Exception { + when(mWifiScoreCard.detectAbnormalDisconnection()) + .thenReturn(WifiHealthMonitor.REASON_SHORT_CONNECTION_NONLOCAL); + InOrder inOrderWifiLockManager = inOrder(mWifiLockManager); + connect(); + inOrderWifiLockManager.verify(mWifiLockManager).updateWifiClientConnected(true); + + // got 4WAY_HANDSHAKE_TIMEOUT + mCmi.sendMessage(WifiMonitor.NETWORK_DISCONNECTION_EVENT, 0, 15, sBSSID); + mLooper.dispatchAll(); + verify(mWifiNative, never()).removeNetworkCachedData(anyInt()); + } + } diff --git a/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java b/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java index facb7f9ad..95f88bbf1 100644 --- a/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java +++ b/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java @@ -52,6 +52,7 @@ import static org.mockito.Mockito.when; import android.annotation.NonNull; import android.app.test.MockAnswerUtil; +import android.app.test.MockAnswerUtil.AnswerWithArguments; import android.content.Context; import android.hardware.wifi.V1_0.WifiChannelWidthInMhz; import android.hardware.wifi.supplicant.V1_0.ISupplicant; @@ -69,6 +70,7 @@ import android.hardware.wifi.supplicant.V1_3.ISupplicantStaIfaceCallback.BssTmDa import android.hardware.wifi.supplicant.V1_3.WifiTechnology; import android.hidl.manager.V1_0.IServiceManager; import android.hidl.manager.V1_0.IServiceNotification; +import android.net.MacAddress; import android.net.wifi.ScanResult; import android.net.wifi.SupplicantState; import android.net.wifi.WifiConfiguration; @@ -126,6 +128,8 @@ public class SupplicantStaIfaceHalTest extends WifiBaseTest { private static final int ICON_FILE_SIZE = 72; private static final String HS20_URL = "http://blahblah"; private static final long PMK_CACHE_EXPIRATION_IN_SEC = 1024; + private static final byte[] CONNECTED_MAC_ADDRESS_BYTES = + {0x00, 0x01, 0x02, 0x03, 0x04, 0x05}; private @Mock IServiceManager mServiceManagerMock; private @Mock ISupplicant mISupplicantMock; @@ -251,6 +255,13 @@ public class SupplicantStaIfaceHalTest extends WifiBaseTest { any(IServiceNotification.Stub.class))).thenReturn(true); when(mISupplicantMock.linkToDeath(any(IHwBinder.DeathRecipient.class), anyLong())).thenReturn(true); + doAnswer(new AnswerWithArguments() { + public void answer(ISupplicantStaIface.getMacAddressCallback cb) { + cb.onValues(mStatusSuccess, CONNECTED_MAC_ADDRESS_BYTES); + } + }) + .when(mISupplicantStaIfaceMock) + .getMacAddress(any(ISupplicantStaIface.getMacAddressCallback.class)); mHandler = spy(new Handler(mLooper.getLooper())); mDut = new SupplicantStaIfaceHalSpy(); } @@ -1759,7 +1770,8 @@ public class SupplicantStaIfaceHalTest extends WifiBaseTest { config.networkId = testFrameworkNetworkId; config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP); PmkCacheStoreData pmkCacheData = - new PmkCacheStoreData(PMK_CACHE_EXPIRATION_IN_SEC, new ArrayList<Byte>()); + new PmkCacheStoreData(PMK_CACHE_EXPIRATION_IN_SEC, new ArrayList<Byte>(), + MacAddress.fromBytes(CONNECTED_MAC_ADDRESS_BYTES)); mDut.mPmkCacheEntries.put(testFrameworkNetworkId, pmkCacheData); when(mClock.getElapsedSinceBootMillis()).thenReturn(testStartSeconds * 1000L); @@ -1820,7 +1832,8 @@ public class SupplicantStaIfaceHalTest extends WifiBaseTest { config.networkId = testFrameworkNetworkId; config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK); PmkCacheStoreData pmkCacheData = - new PmkCacheStoreData(PMK_CACHE_EXPIRATION_IN_SEC, new ArrayList<Byte>()); + new PmkCacheStoreData(PMK_CACHE_EXPIRATION_IN_SEC, new ArrayList<Byte>(), + MacAddress.fromBytes(CONNECTED_MAC_ADDRESS_BYTES)); mDut.mPmkCacheEntries.put(testFrameworkNetworkId, pmkCacheData); when(mClock.getElapsedSinceBootMillis()).thenReturn(testStartSeconds * 1000L); @@ -1850,7 +1863,8 @@ public class SupplicantStaIfaceHalTest extends WifiBaseTest { config.networkId = testFrameworkNetworkId; config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP); PmkCacheStoreData pmkCacheData = - new PmkCacheStoreData(PMK_CACHE_EXPIRATION_IN_SEC, new ArrayList<Byte>()); + new PmkCacheStoreData(PMK_CACHE_EXPIRATION_IN_SEC, new ArrayList<Byte>(), + MacAddress.fromBytes(CONNECTED_MAC_ADDRESS_BYTES)); mDut.mPmkCacheEntries.put(testFrameworkNetworkId, pmkCacheData); when(mClock.getElapsedSinceBootMillis()).thenReturn(testStartSeconds * 1000L); @@ -1877,7 +1891,8 @@ public class SupplicantStaIfaceHalTest extends WifiBaseTest { config.networkId = testFrameworkNetworkId; config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP); PmkCacheStoreData pmkCacheData = - new PmkCacheStoreData(PMK_CACHE_EXPIRATION_IN_SEC, new ArrayList<Byte>()); + new PmkCacheStoreData(PMK_CACHE_EXPIRATION_IN_SEC, new ArrayList<Byte>(), + MacAddress.fromBytes(CONNECTED_MAC_ADDRESS_BYTES)); mDut.mPmkCacheEntries.put(testFrameworkNetworkId, pmkCacheData); when(mClock.getElapsedSinceBootMillis()).thenReturn(testStartSeconds * 1000L); @@ -1896,6 +1911,40 @@ public class SupplicantStaIfaceHalTest extends WifiBaseTest { } /** + * Tests the PMK cache is removed and not set if MAC address is changed. + */ + @Test + public void testRemovePmkEntryOnMacAddressChanged() throws Exception { + int testFrameworkNetworkId = 9; + long testStartSeconds = PMK_CACHE_EXPIRATION_IN_SEC / 2; + WifiConfiguration config = new WifiConfiguration(); + config.networkId = testFrameworkNetworkId; + config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP); + // Assume we have a PMK cache with a different MAC address. + final byte[] previouisConnectedMacAddressBytes = + {0x00, 0x01, 0x02, 0x03, 0x04, 0x09}; + PmkCacheStoreData pmkCacheData = + new PmkCacheStoreData(PMK_CACHE_EXPIRATION_IN_SEC, new ArrayList<Byte>(), + MacAddress.fromBytes(previouisConnectedMacAddressBytes)); + mDut.mPmkCacheEntries.put(testFrameworkNetworkId, pmkCacheData); + when(mClock.getElapsedSinceBootMillis()).thenReturn(testStartSeconds * 1000L); + + setupMocksForHalV1_3(); + setupMocksForPmkCache(); + setupMocksForConnectSequence(false); + + // When MAC is not changed, PMK cache should NOT be removed. + mDut.removeNetworkCachedDataIfNeeded(testFrameworkNetworkId, + MacAddress.fromBytes(previouisConnectedMacAddressBytes)); + assertEquals(pmkCacheData, mDut.mPmkCacheEntries.get(testFrameworkNetworkId)); + + // When MAC is changed, PMK cache should be removed. + mDut.removeNetworkCachedDataIfNeeded(testFrameworkNetworkId, + MacAddress.fromBytes(CONNECTED_MAC_ADDRESS_BYTES)); + assertNull(mDut.mPmkCacheEntries.get(testFrameworkNetworkId)); + } + + /** * Test getConnectionCapabilities * Should fail if running HAL lower than V1_3 */ |