From 37a4b6bbd3410ff2225c2af31237ee4e8e11d359 Mon Sep 17 00:00:00 2001 From: Hai Shalom Date: Thu, 21 Nov 2019 19:26:05 +0000 Subject: Revert submission Reason for revert: Incomplete fix that causes additional issues which were not anticipated earlier. Change-Id: I526410612fe2f733ae41efe7ed1a20ab6d620458 --- .../android/server/wifi/ConfigurationMapTest.java | 51 -------- .../server/wifi/ScanResultMatchInfoTest.java | 2 +- .../android/server/wifi/WifiConfigManagerTest.java | 137 --------------------- .../server/wifi/WifiConfigurationTestUtil.java | 40 ++---- .../server/wifi/WifiNetworkFactoryTest.java | 46 +++++++ 5 files changed, 57 insertions(+), 219 deletions(-) (limited to 'tests') diff --git a/tests/wifitests/src/com/android/server/wifi/ConfigurationMapTest.java b/tests/wifitests/src/com/android/server/wifi/ConfigurationMapTest.java index 40cc4b391..0b3cc45e8 100644 --- a/tests/wifitests/src/com/android/server/wifi/ConfigurationMapTest.java +++ b/tests/wifitests/src/com/android/server/wifi/ConfigurationMapTest.java @@ -281,7 +281,6 @@ public class ConfigurationMapTest extends WifiBaseTest { verifyScanResultMatchWithNetwork(WifiConfigurationTestUtil.createPskNetwork()); verifyScanResultMatchWithNetwork(WifiConfigurationTestUtil.createWepNetwork()); verifyScanResultMatchWithNetwork(WifiConfigurationTestUtil.createEapNetwork()); - verifyScanResultMatchWithNetwork(WifiConfigurationTestUtil.createSaeNetwork()); } /** @@ -334,54 +333,4 @@ public class ConfigurationMapTest extends WifiBaseTest { mConfigs.clear(); assertNull(mConfigs.getByScanResultForCurrentUser(scanResult)); } - - /** - * Verifies that {@link ConfigurationMap#getPskNetworkByScanResultForCurrentUser(ScanResult)} - * can positively match a PSK network for transition mode AP. - */ - @Test - public void testFindPskNetworkFromSaeScanResult() { - final String wpa2Wpa3TransitionSsid = "\"WPA3-Transition\""; - WifiConfiguration saePskConfig = - WifiConfigurationTestUtil.createSaeNetwork(wpa2Wpa3TransitionSsid); - WifiConfiguration pskConfig = - WifiConfigurationTestUtil.createPskNetwork(wpa2Wpa3TransitionSsid); - mConfigs.put(saePskConfig); - mConfigs.put(pskConfig); - - ScanDetail scanDetail = WifiConfigurationTestUtil - .createScanDetailForWpa2Wpa3TransitionModeNetwork(saePskConfig, - "AA:BB:CC:DD:CC:BB", -40, 2402, 0, 1); - ScanResult scanResult = scanDetail.getScanResult(); - - WifiConfiguration retrievedConfig = - mConfigs.getPskNetworkByScanResultForCurrentUser(scanResult); - assertNotNull(retrievedConfig); - assertEquals(pskConfig.configKey(), retrievedConfig.configKey()); - } - - /** - * Verifies that {@link ConfigurationMap#getOpenNetworkByScanResultForCurrentUser(ScanResult)} - * can positively match a PSK network for transition mode AP. - */ - @Test - public void testFindOpenNetworkFromOweScanResult() { - final String oweTransitionSsid = "\"OWE-Transition\""; - WifiConfiguration oweOpenConfig = - WifiConfigurationTestUtil.createOweNetwork(oweTransitionSsid); - WifiConfiguration openConfig = - WifiConfigurationTestUtil.createOpenNetwork(oweTransitionSsid); - mConfigs.put(oweOpenConfig); - mConfigs.put(openConfig); - - ScanDetail scanDetail = WifiConfigurationTestUtil - .createScanDetailForOweTransitionModeNetwork(oweOpenConfig, - "AA:BB:CC:DD:CC:BB", -40, 2402, 0, 1); - ScanResult scanResult = scanDetail.getScanResult(); - - WifiConfiguration retrievedConfig = - mConfigs.getOpenNetworkByScanResultForCurrentUser(scanResult); - assertNotNull(retrievedConfig); - assertEquals(openConfig.configKey(), retrievedConfig.configKey()); - } } diff --git a/tests/wifitests/src/com/android/server/wifi/ScanResultMatchInfoTest.java b/tests/wifitests/src/com/android/server/wifi/ScanResultMatchInfoTest.java index 4192da68c..1cc7fa83f 100644 --- a/tests/wifitests/src/com/android/server/wifi/ScanResultMatchInfoTest.java +++ b/tests/wifitests/src/com/android/server/wifi/ScanResultMatchInfoTest.java @@ -92,7 +92,7 @@ public class ScanResultMatchInfoTest extends WifiBaseTest { @Test public void testEqualityRulesForTransitionMode() { WifiConfiguration wifiConfiguration = - WifiConfigurationTestUtil.createSaeNetwork("\"Transition is Hard\""); + WifiConfigurationTestUtil.createPskNetwork("\"Transition is Hard\""); ScanDetail scanDetail = createScanDetailForWpa2Wpa3TransitionModeNetwork(wifiConfiguration, "AA:BB:CC:DD:CC:BB"); diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java index 203250e9f..61646f076 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java @@ -190,8 +190,6 @@ public class WifiConfigManagerTest extends WifiBaseTest { return TEST_NO_PERM_NAME; } else if (uid == Process.WIFI_UID) { return TEST_WIFI_NAME; - } else if (uid == Process.SYSTEM_UID) { - return TEST_WIFI_NAME; } fail("Unexpected UID: " + uid); return ""; @@ -5617,139 +5615,4 @@ public class WifiConfigManagerTest extends WifiBaseTest { assertNotEquals(WifiConfiguration.INVALID_NETWORK_ID, networkUpdateResult.getNetworkId()); assertFalse(mWifiConfigManager.isInFlakyRandomizationSsidHotlist(networkId)); } - - /** - * Verifies that when scanning a WPA3 in transition mode AP, and there is a matching WPA2 saved - * network, {@link WifiConfigManager#getConfiguredNetworkForScanDetailAndCache(ScanDetail)} - * clones a new WPA3 saved network that will be used to connect to it. - * - * The test also verifies that the new network is marked as cloned. - */ - @Test - public void testCloningPskNetworkForTransitionMode() { - final String wpa2Wpa3TransitionSsid = "\"WPA3-Transition\""; - WifiConfiguration saeNetwork = WifiConfigurationTestUtil - .createSaeNetwork(wpa2Wpa3TransitionSsid); - WifiConfiguration pskNetwork = WifiConfigurationTestUtil - .createPskNetwork(wpa2Wpa3TransitionSsid); - - // First add the WPA2 saved network. - verifyAddNetworkToWifiConfigManager(pskNetwork); - - // Now create a dummy scan detail for WPA3-Transition. - ScanDetail scanDetail = WifiConfigurationTestUtil - .createScanDetailForWpa2Wpa3TransitionModeNetwork(saeNetwork, - "AA:BB:CC:DD:CC:BB", -40, 2402, 0, 1); - - - WifiConfiguration retrievedNetwork = - mWifiConfigManager.getConfiguredNetworkForScanDetailAndCache(scanDetail); - // Retrieve the network with password data for comparison. - retrievedNetwork = - mWifiConfigManager.getConfiguredNetworkWithPassword(retrievedNetwork.networkId); - - // Verify cloned network matches the expected WPA3 network - assertEquals(saeNetwork.SSID, retrievedNetwork.SSID); - assertEquals(saeNetwork.BSSID, retrievedNetwork.BSSID); - assertEquals(saeNetwork.preSharedKey, retrievedNetwork.preSharedKey); - assertEquals(saeNetwork.requirePMF, retrievedNetwork.requirePMF); - assertEquals(saeNetwork.allowedKeyManagement, retrievedNetwork.allowedKeyManagement); - assertNotNull(retrievedNetwork.clonedNetworkConfigKey); - assertEquals(retrievedNetwork.clonedNetworkConfigKey, pskNetwork.configKey()); - } - - /** - * Verifies that when scanning a WPA3 in transition mode AP, and there is a matching WPA2 saved - * network, {@link WifiConfigManager#getConfiguredNetworkForScanDetailAndCache(ScanDetail)} - * clones a new WPA3 saved network that will be used to connect to it. - * - * The test also verifies that the new network is marked as cloned. - */ - @Test - public void testCloningOweNetworkForTransitionMode() { - final String oweTransitionSsid = "\"OWE-Transition\""; - WifiConfiguration oweNetwork = WifiConfigurationTestUtil - .createOweNetwork(oweTransitionSsid); - WifiConfiguration openNetwork = WifiConfigurationTestUtil - .createOpenNetwork(oweTransitionSsid); - - // First add the Open saved network. - verifyAddNetworkToWifiConfigManager(openNetwork); - - // Now create a dummy scan detail for OWE-Transition. - ScanDetail scanDetail = WifiConfigurationTestUtil - .createScanDetailForOweTransitionModeNetwork(oweNetwork, - "AA:BB:CC:DD:CC:BB", -40, 2402, 0, 1); - - - WifiConfiguration retrievedNetwork = - mWifiConfigManager.getConfiguredNetworkForScanDetailAndCache(scanDetail); - // Retrieve the network with password data for comparison. - retrievedNetwork = - mWifiConfigManager.getConfiguredNetworkWithPassword(retrievedNetwork.networkId); - - // Verify cloned network matches the expected OWE network - assertEquals(oweNetwork.SSID, retrievedNetwork.SSID); - assertEquals(oweNetwork.BSSID, retrievedNetwork.BSSID); - assertEquals(oweNetwork.preSharedKey, retrievedNetwork.preSharedKey); - assertEquals(oweNetwork.requirePMF, retrievedNetwork.requirePMF); - assertEquals(oweNetwork.allowedKeyManagement, retrievedNetwork.allowedKeyManagement); - assertNotNull(retrievedNetwork.clonedNetworkConfigKey); - assertEquals(retrievedNetwork.clonedNetworkConfigKey, openNetwork.configKey()); - } - - /** - * Verifies that when a cloned network is removed, its original pair is removed as well - * {@link WifiConfigManager#removeNetwork(int)} - */ - @Test - public void testRemoveClonedSaeNetwork() { - final String wpa2Wpa3TransitionSsid = "\"WPA3-Transition\""; - WifiConfiguration saeNetwork = WifiConfigurationTestUtil - .createSaeNetwork(wpa2Wpa3TransitionSsid); - WifiConfiguration pskNetwork = WifiConfigurationTestUtil - .createPskNetwork(wpa2Wpa3TransitionSsid); - ArgumentCaptor wifiConfigCaptor = - ArgumentCaptor.forClass(WifiConfiguration.class); - - // First add the WPA2 saved network. - NetworkUpdateResult result = verifyAddNetworkToWifiConfigManager(pskNetwork); - verify(mWcmListener).onNetworkAdded(wifiConfigCaptor.capture()); - assertEquals(pskNetwork.networkId, wifiConfigCaptor.getValue().networkId); - reset(mWcmListener); - - // Now create a dummy scan detail for WPA3-Transition. - ScanDetail scanDetail = WifiConfigurationTestUtil - .createScanDetailForWpa2Wpa3TransitionModeNetwork(saeNetwork, - "AA:BB:CC:DD:CC:BB", -40, 2402, 0, 1); - - WifiConfiguration retrievedNetwork = - mWifiConfigManager.getConfiguredNetworkForScanDetailAndCache(scanDetail); - // Retrieve the network with password data for comparison. - retrievedNetwork = - mWifiConfigManager.getConfiguredNetworkWithPassword(retrievedNetwork.networkId); - - // Verify cloned network matches the expected WPA3 network - assertEquals(saeNetwork.SSID, retrievedNetwork.SSID); - assertEquals(saeNetwork.BSSID, retrievedNetwork.BSSID); - assertEquals(saeNetwork.preSharedKey, retrievedNetwork.preSharedKey); - assertEquals(saeNetwork.requirePMF, retrievedNetwork.requirePMF); - assertEquals(saeNetwork.allowedKeyManagement, retrievedNetwork.allowedKeyManagement); - assertNotNull(retrievedNetwork.clonedNetworkConfigKey); - assertEquals(retrievedNetwork.clonedNetworkConfigKey, pskNetwork.configKey()); - - // Ensure that configured network list is not empty. - assertTrue(mWifiConfigManager.getConfiguredNetworks().size() == 2); - verify(mWcmListener).onNetworkAdded(wifiConfigCaptor.capture()); - assertEquals(retrievedNetwork.networkId, wifiConfigCaptor.getValue().networkId); - reset(mWcmListener); - - assertTrue(mWifiConfigManager.removeNetwork(retrievedNetwork.networkId, TEST_CREATOR_UID, - TEST_CREATOR_NAME)); - - // Ensure that configured network list is empty now. - assertTrue(mWifiConfigManager.getConfiguredNetworks().isEmpty()); - verify(mWcmListener).onNetworkRemoved(wifiConfigCaptor.capture()); - assertEquals(retrievedNetwork.networkId, wifiConfigCaptor.getValue().networkId); - } } diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java index ba5f0056a..9e2783e1b 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java @@ -248,11 +248,8 @@ public class WifiConfigurationTestUtil { } public static WifiConfiguration createOweNetwork(String ssid) { - WifiConfiguration configuration = generateWifiConfig(TEST_NETWORK_ID, TEST_UID, ssid, - true, true, null, null, SECURITY_OWE); - - configuration.requirePMF = true; - return configuration; + return generateWifiConfig(TEST_NETWORK_ID, TEST_UID, ssid, true, true, null, + null, SECURITY_OWE); } public static WifiConfiguration createOpenNetwork() { @@ -277,7 +274,14 @@ public class WifiConfigurationTestUtil { } public static WifiConfiguration createSaeNetwork() { - return createSaeNetwork(createNewSSID()); + WifiConfiguration configuration = + generateWifiConfig(TEST_NETWORK_ID, TEST_UID, createNewSSID(), true, true, null, + null, SECURITY_SAE); + + // SAE password uses the same member. + configuration.preSharedKey = TEST_PSK; + configuration.requirePMF = true; + return configuration; } public static WifiConfiguration createPskNetwork() { @@ -300,10 +304,6 @@ public class WifiConfigurationTestUtil { WifiConfiguration configuration = generateWifiConfig(TEST_NETWORK_ID, TEST_UID, ssid, true, true, null, null, SECURITY_SAE); - - // SAE password uses the same member. - configuration.preSharedKey = TEST_PSK; - configuration.requirePMF = true; return configuration; } @@ -513,15 +513,6 @@ public class WifiConfigurationTestUtil { return caps; } - /** - * Gets scan result capabilities for a WPA2/WPA3-Transition mode network configuration - */ - private static String - getScanResultCapsForOweTransitionNetwork(WifiConfiguration configuration) { - String caps = "[OWE_TRANSITION-CCMP]"; - return caps; - } - /** * Creates a scan detail corresponding to the provided network and given BSSID, etc. */ @@ -545,17 +536,6 @@ public class WifiConfigurationTestUtil { return new ScanDetail(ssid, bssid, caps, level, frequency, tsf, seen); } - /** - * Creates a scan detail corresponding to the provided network and given BSSID, but sets - * the capabilities to OWE-Transition mode network. - */ - public static ScanDetail createScanDetailForOweTransitionModeNetwork( - WifiConfiguration configuration, String bssid, int level, int frequency, - long tsf, long seen) { - String caps = getScanResultCapsForOweTransitionNetwork(configuration); - WifiSsid ssid = WifiSsid.createFromAsciiEncoded(configuration.getPrintableSsid()); - return new ScanDetail(ssid, bssid, caps, level, frequency, tsf, seen); - } /** * Asserts that the 2 WifiConfigurations are equal in the elements saved for both backup/restore diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java index b2f74f68f..345672aec 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java @@ -750,6 +750,49 @@ public class WifiNetworkFactoryTest extends WifiBaseTest { matchedScanResultsCaptor.getValue().size()); } + /** + * Verify network specifier matching for a specifier containing a specific SSID match using + * 4 WPA_PSK + SAE transition scan results, each with unique SSID. + */ + @Test + public void testNetworkSpecifierMatchSuccessUsingLiteralSsidMatchForSaeTransitionScanResult() + throws Exception { + setupScanData(SCAN_RESULT_TYPE_WPA_PSK_SAE_TRANSITION, + TEST_SSID_1, TEST_SSID_2, TEST_SSID_3, TEST_SSID_4); + + // Setup network specifier for open networks. + PatternMatcher ssidPatternMatch = + new PatternMatcher(TEST_SSID_1, PatternMatcher.PATTERN_LITERAL); + Pair bssidPatternMatch = + Pair.create(MacAddress.ALL_ZEROS_ADDRESS, MacAddress.ALL_ZEROS_ADDRESS); + WifiConfiguration wifiConfiguration = new WifiConfiguration(); + wifiConfiguration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK); + WifiNetworkSpecifier specifier = new WifiNetworkSpecifier( + ssidPatternMatch, bssidPatternMatch, wifiConfiguration, TEST_UID_1, + TEST_PACKAGE_NAME_1); + + mNetworkRequest.networkCapabilities.setNetworkSpecifier(specifier); + mWifiNetworkFactory.needNetworkFor(mNetworkRequest, 0); + + validateUiStartParams(true); + + mWifiNetworkFactory.addCallback(mAppBinder, mNetworkRequestMatchCallback, + TEST_CALLBACK_IDENTIFIER); + + verifyPeriodicScans(0, PERIODIC_SCAN_INTERVAL_MS); + + ArgumentCaptor> matchedScanResultsCaptor = + ArgumentCaptor.forClass(List.class); + verify(mNetworkRequestMatchCallback).onMatch(matchedScanResultsCaptor.capture()); + + assertNotNull(matchedScanResultsCaptor.getValue()); + // We only expect 1 network match in this case. + validateScanResults(matchedScanResultsCaptor.getValue(), mTestScanDatas[0].getResults()[0]); + + verify(mWifiMetrics).incrementNetworkRequestApiMatchSizeHistogram( + matchedScanResultsCaptor.getValue().size()); + } + /** * Verify network specifier matching for a specifier containing a Prefix SSID match using * 4 open scan results, each with unique SSID. @@ -2776,6 +2819,7 @@ public class WifiNetworkFactoryTest extends WifiBaseTest { private static final int SCAN_RESULT_TYPE_OPEN = 0; private static final int SCAN_RESULT_TYPE_WPA_PSK = 1; private static final int SCAN_RESULT_TYPE_WPA_EAP = 2; + private static final int SCAN_RESULT_TYPE_WPA_PSK_SAE_TRANSITION = 3; private String getScanResultCapsForType(int scanResultType) { switch (scanResultType) { @@ -2788,6 +2832,8 @@ public class WifiNetworkFactoryTest extends WifiBaseTest { case SCAN_RESULT_TYPE_WPA_EAP: return WifiConfigurationTestUtil.getScanResultCapsForNetwork( WifiConfigurationTestUtil.createEapNetwork()); + case SCAN_RESULT_TYPE_WPA_PSK_SAE_TRANSITION: + return WifiConfigurationTestUtil.getScanResultCapsForWpa2Wpa3TransitionNetwork(); } fail("Invalid scan result type " + scanResultType); return ""; -- cgit v1.2.3