From 75a766bae85ee8e94fbaad8fb5214804e7ff97e4 Mon Sep 17 00:00:00 2001 From: Bartosz Fabianowski Date: Tue, 26 Jan 2016 14:20:22 +0100 Subject: Test that WifiConfigStore handles duplicate configurations correctly When loading network configurations from the wpa_supplicant, the WifiConfigStore may encounter duplicate entries caused by WPS. This CL adds a test which verifies that the WifiConfigStore handles such duplicates correctly (by having the second configuraiton overwrite the first) BUG:25600871 Change-Id: Iec8fd9a6dc04849192a0761a9d26a0aacd401c0b --- .../android/server/wifi/WifiConfigStoreTest.java | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'tests') diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigStoreTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigStoreTest.java index 638a726e6..c129b1dcd 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConfigStoreTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigStoreTest.java @@ -540,6 +540,40 @@ public class WifiConfigStoreTest extends AndroidTestCase { verifyNetworkConfigs(CONFIGS, mConfiguredNetworks.valuesForAllUsers()); } + /** + * Verifies that loadConfiguredNetworks() correctly handles duplicates when reading network + * configurations from the wpa_supplicant: The second configuration overwrites the first. + */ + public void testLoadConfiguredNetworksEliminatesDuplicates() throws Exception { + final WifiConfiguration config = new WifiConfiguration(CONFIGS.get(0)); + config.networkId = 1; + + // Set up list of network configurations returned by wpa_supplicant. The two configurations + // are identical except for their network IDs. + final String header = "network id / ssid / bssid / flags"; + final String networks = + header + "\n0\t" + config.SSID + "\tany\n1\t" + config.SSID + "\tany"; + when(mWifiNative.listNetworks(anyInt())).thenReturn(header); + when(mWifiNative.listNetworks(-1)).thenReturn(networks); + + // Set up variables returned by wpa_supplicant. + when(mWifiNative.getNetworkVariable(anyInt(), eq(WifiConfiguration.ssidVarName))) + .thenReturn(encodeConfigSSID(config)); + final Map metadata = new HashMap(); + metadata.put(WifiConfigStore.ID_STRING_KEY_CONFIG_KEY, config.configKey()); + metadata.put(WifiConfigStore.ID_STRING_KEY_CREATOR_UID, + Integer.toString(config.creatorUid)); + when(mWifiNative.getNetworkExtra(anyInt(), eq(WifiConfigStore.ID_STRING_VAR_NAME))) + .thenReturn(metadata); + + // Load network configurations. + mConfigStore.loadConfiguredNetworks(); + + // Verify that the second network configuration (network ID 1) overwrote the first (network + // ID 0). + verifyNetworkConfigs(Arrays.asList(config), mConfiguredNetworks.valuesForAllUsers()); + } + /** * Verifies that handleUserSwitch() removes ephemeral network configurations, disables network * configurations that should no longer be visible and enables network configurations that -- cgit v1.2.3