From 1b93dea624b8f6067a4216646853826162719fe2 Mon Sep 17 00:00:00 2001 From: Glen Kuhne Date: Tue, 10 Jan 2017 14:00:20 -0800 Subject: [PATCH] CTS: WifiManager.addNetwork with HttpProxy Added CTS tests verifying, that adding a WifiConfiguration containing an httpProxy will: -Succeed if caller is DeviceOwner -Fail if caller is not DeviceOwner Test: Added two CTS tests Bug: 14669153 Change-Id: I2c81492dba5052117a03a2aa7b3cc8ffb5d52d5f Merged-In: I2c81492dba5052117a03a2aa7b3cc8ffb5d52d5f --- .../android/net/wifi/cts/WifiManagerTest.java | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/tests/cts/net/src/android/net/wifi/cts/WifiManagerTest.java b/tests/cts/net/src/android/net/wifi/cts/WifiManagerTest.java index 897e5cfe8e..dcedb18605 100644 --- a/tests/cts/net/src/android/net/wifi/cts/WifiManagerTest.java +++ b/tests/cts/net/src/android/net/wifi/cts/WifiManagerTest.java @@ -22,7 +22,6 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.pm.PackageManager; -import android.location.LocationManager; import android.net.NetworkInfo; import android.net.wifi.ScanResult; import android.net.wifi.WifiConfiguration; @@ -35,6 +34,8 @@ import android.provider.Settings; import android.test.AndroidTestCase; import android.util.Log; +import com.android.compatibility.common.util.WifiConfigCreator; + import java.net.HttpURLConnection; import java.net.URL; import java.util.HashSet; @@ -68,6 +69,8 @@ public class WifiManagerTest extends AndroidTestCase { private static final String TAG = "WifiManagerTest"; private static final String SSID1 = "\"WifiManagerTest\""; private static final String SSID2 = "\"WifiManagerTestModified\""; + private static final String PROXY_TEST_SSID = "SomeProxyAp"; + private static final String ADD_NETWORK_EXCEPTION_SUBSTR = "addNetwork"; private static final int TIMEOUT_MSEC = 6000; private static final int WAIT_MSEC = 60; private static final int DURATION = 10000; @@ -75,6 +78,8 @@ public class WifiManagerTest extends AndroidTestCase { private static final int WIFI_SCAN_TEST_CACHE_DELAY_MILLIS = 3 * 60 * 1000; private static final int WIFI_SCAN_TEST_ITERATIONS = 5; + private static final String TEST_PAC_URL = "http://www.example.com/proxy.pac"; + private IntentFilter mIntentFilter; private final BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override @@ -405,6 +410,31 @@ public class WifiManagerTest extends AndroidTestCase { } } + /** + * Verifies that addNetwork() fails for WifiConfigurations containing a non-null http proxy when + * the caller doesn't have OVERRIDE_WIFI_CONFIG permission, DeviceOwner or ProfileOwner device + * management policies + */ + public void testSetHttpProxy_PermissionFail() throws Exception { + if (!WifiFeature.isWifiSupported(getContext())) { + // skip the test if WiFi is not supported + return; + } + WifiConfigCreator configCreator = new WifiConfigCreator(getContext()); + boolean exceptionThrown = false; + try { + configCreator.addHttpProxyNetworkVerifyAndRemove( + PROXY_TEST_SSID, TEST_PAC_URL); + } catch (IllegalStateException e) { + // addHttpProxyNetworkVerifyAndRemove throws three IllegalStateException, + // expect it to throw for the addNetwork operation + if (e.getMessage().contains(ADD_NETWORK_EXCEPTION_SUBSTR)) { + exceptionThrown = true; + } + } + assertTrue(exceptionThrown); + } + private Set getEnabledNetworks(List configuredNetworks) { Set ssids = new HashSet(); for (WifiConfiguration wifiConfig : configuredNetworks) {