diff options
author | Roshan Pius <rpius@google.com> | 2017-05-31 02:25:49 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-05-31 02:25:49 +0000 |
commit | eaa885f034561ba8dd63623af84347858c8b290f (patch) | |
tree | 337241dfd62faee6a5d28cb097f2177fc7f58192 /tests | |
parent | fac257ab888ec2b491a0c891831341e6733adafe (diff) | |
parent | 6f41401a3847a08183e995d9d1a9c70b72e0c4f5 (diff) |
Merge changes I1c24c60d,I1e8998c9 into oc-dev am: ab73d041b3
am: 6f41401a38
Change-Id: I33e8eecbc8f7ab339f2f8089bd26f5cbe4f7e2b5
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java | 25 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/util/InformationElementUtilTest.java | 82 |
2 files changed, 103 insertions, 4 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java index a2194896d..be9b0c544 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java @@ -118,6 +118,8 @@ public class WifiStateMachineTest { (ActivityManager.isLowRamDeviceStatic() ? WifiStateMachine.NUM_LOG_RECS_VERBOSE_LOW_MEMORY : WifiStateMachine.NUM_LOG_RECS_VERBOSE); + private static final int WPS_SUPPLICANT_NETWORK_ID = 5; + private static final int WPS_FRAMEWORK_NETWORK_ID = 10; private static final String DEFAULT_TEST_SSID = "\"GoogleGuest\""; private long mBinderToken; @@ -1384,6 +1386,7 @@ public class WifiStateMachineTest { mLooper.dispatchAll(); assertEquals("DisconnectedState", getCurrentState().getName()); + verifyMocksForWpsNetworkMigration(); } /** @@ -1433,6 +1436,7 @@ public class WifiStateMachineTest { mLooper.dispatchAll(); assertEquals("DisconnectedState", getCurrentState().getName()); + verifyMocksForWpsNetworkMigration(); } /** @@ -1504,21 +1508,34 @@ public class WifiStateMachineTest { } private void setupMocksForWpsNetworkMigration() { - int newNetworkId = 5; // Now trigger the network connection event for adding the WPS network. doAnswer(new AnswerWithArguments() { public boolean answer(Map<String, WifiConfiguration> configs, SparseArray<Map<String, String>> networkExtras) throws Exception { - configs.put("dummy", new WifiConfiguration()); + WifiConfiguration config = new WifiConfiguration(); + config.networkId = WPS_SUPPLICANT_NETWORK_ID; + config.SSID = DEFAULT_TEST_SSID; + configs.put("dummy", config); return true; } }).when(mWifiNative).migrateNetworksFromSupplicant(any(Map.class), any(SparseArray.class)); when(mWifiConfigManager.addOrUpdateNetwork(any(WifiConfiguration.class), anyInt())) - .thenReturn(new NetworkUpdateResult(newNetworkId)); - when(mWifiConfigManager.enableNetwork(eq(newNetworkId), anyBoolean(), anyInt())) + .thenReturn(new NetworkUpdateResult(WPS_FRAMEWORK_NETWORK_ID)); + when(mWifiConfigManager.enableNetwork(eq(WPS_FRAMEWORK_NETWORK_ID), anyBoolean(), anyInt())) .thenReturn(true); } + private void verifyMocksForWpsNetworkMigration() { + // Network Ids should be reset so that it is treated as addition. + ArgumentCaptor<WifiConfiguration> wifiConfigCaptor = + ArgumentCaptor.forClass(WifiConfiguration.class); + verify(mWifiConfigManager).addOrUpdateNetwork(wifiConfigCaptor.capture(), anyInt()); + assertEquals(WifiConfiguration.INVALID_NETWORK_ID, wifiConfigCaptor.getValue().networkId); + assertEquals(DEFAULT_TEST_SSID, wifiConfigCaptor.getValue().SSID); + verify(mWifiConfigManager).enableNetwork(eq(WPS_FRAMEWORK_NETWORK_ID), anyBoolean(), + anyInt()); + } + /** * Verifies that WifiInfo is cleared upon exiting and entering WifiInfo, and that it is not * updated by SUPPLICAN_STATE_CHANGE_EVENTs in ScanModeState. diff --git a/tests/wifitests/src/com/android/server/wifi/util/InformationElementUtilTest.java b/tests/wifitests/src/com/android/server/wifi/util/InformationElementUtilTest.java index f914da2f2..b9a8c31e3 100644 --- a/tests/wifitests/src/com/android/server/wifi/util/InformationElementUtilTest.java +++ b/tests/wifitests/src/com/android/server/wifi/util/InformationElementUtilTest.java @@ -271,6 +271,32 @@ public class InformationElementUtilTest { } /** + * Test Capabilities.generateCapabilitiesString() with a RSN IE which is malformed. + * Expect the function to return a string with empty key management & pairswise cipher security + * information. + */ + @Test + public void buildCapabilities_malformedRsnElement() { + InformationElement ie = new InformationElement(); + ie.id = InformationElement.EID_RSN; + ie.bytes = new byte[] { (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x0F, + (byte) 0xAC, (byte) 0x02, (byte) 0x02, (byte) 0x00, + (byte) 0x00, (byte) 0x0F, (byte) 0xAC }; + + InformationElement[] ies = new InformationElement[] { ie }; + + BitSet beaconCap = new BitSet(16); + beaconCap.set(4); + + InformationElementUtil.Capabilities capabilities = + new InformationElementUtil.Capabilities(); + capabilities.from(ies, beaconCap); + String result = capabilities.generateCapabilitiesString(); + + assertEquals("[WPA2]", result); + } + + /** * Test Capabilities.generateCapabilitiesString() with a WPA type 1 IE. * Expect the function to return a string with the proper security information. */ @@ -299,6 +325,30 @@ public class InformationElementUtilTest { } /** + * Test Capabilities.generateCapabilitiesString() with a WPA type 1 IE which is malformed. + * Expect the function to return a string with empty key management & pairswise cipher security + * information. + */ + @Test + public void buildCapabilities_malformedWpa1Element() { + InformationElement ie = new InformationElement(); + ie.id = InformationElement.EID_VSA; + ie.bytes = new byte[] { (byte) 0x00, (byte) 0x50, (byte) 0xF2, (byte) 0x01, + (byte) 0x01, (byte) 0x00 }; + + InformationElement[] ies = new InformationElement[] { ie }; + + BitSet beaconCap = new BitSet(16); + beaconCap.set(4); + InformationElementUtil.Capabilities capabilities = + new InformationElementUtil.Capabilities(); + capabilities.from(ies, beaconCap); + String result = capabilities.generateCapabilitiesString(); + + assertEquals("[WPA]", result); + } + + /** * Test Capabilities.generateCapabilitiesString() with both RSN and WPA1 IE. * Expect the function to return a string with the proper security information. */ @@ -337,6 +387,38 @@ public class InformationElementUtilTest { } /** + * Test Capabilities.generateCapabilitiesString() with both RSN and WPA1 IE which are malformed. + * Expect the function to return a string with empty key management & pairswise cipher security + * information. + */ + @Test + public void buildCapabilities_malformedRsnAndWpaElement() { + InformationElement ieRsn = new InformationElement(); + ieRsn.id = InformationElement.EID_RSN; + ieRsn.bytes = new byte[] { (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x0F, + (byte) 0xAC, (byte) 0x02, (byte) 0x02 }; + + InformationElement ieWpa = new InformationElement(); + ieWpa.id = InformationElement.EID_VSA; + ieWpa.bytes = new byte[] { (byte) 0x00, (byte) 0x50, (byte) 0xF2, (byte) 0x01, + (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x50, + (byte) 0xF2, (byte) 0x02, (byte) 0x02, (byte) 0x00, + (byte) 0x00, (byte) 0x50 }; + + InformationElement[] ies = new InformationElement[] { ieWpa, ieRsn }; + + BitSet beaconCap = new BitSet(16); + beaconCap.set(4); + + InformationElementUtil.Capabilities capabilities = + new InformationElementUtil.Capabilities(); + capabilities.from(ies, beaconCap); + String result = capabilities.generateCapabilitiesString(); + + assertEquals("[WPA][WPA2]", result); + } + + /** * Test Capabilities.generateCapabilitiesString() with both WPS and WPA1 IE. * Expect the function to return a string with the proper security information. */ |