summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2018-04-27 10:28:27 -0700
committerRoshan Pius <rpius@google.com>2018-05-03 13:26:32 -0700
commitc7b445ba6b5b5916d47daf22a77e6f67de3fc5f4 (patch)
tree79083432d3a269331e699a115514992417e71b01 /tests
parentd47fd3791387eded068f6554c0dfdaa0ee5ceef2 (diff)
WifiConfigurationUtil: Validate UTF-8 ssid length correctly
Validate the number of bytes in UTF-8 encoded SSID's. The previous check was only validating the number of characters which could end up violating the SSID length specification in the standard. Also, added an extra validation in NativeUtil.decodeSsid() to ensure the string is UTF-8 encoded. Bug: 78483295 Test: Unit tests Test: Able to add/update wifi network configs. Change-Id: I46076ba6b309af006c10f6a9d4ab1d9bc40be428
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConfigurationUtilTest.java14
-rw-r--r--tests/wifitests/src/com/android/server/wifi/util/NativeUtilTest.java12
2 files changed, 26 insertions, 0 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigurationUtilTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigurationUtilTest.java
index eb498e9d6..7bb24371a 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConfigurationUtilTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigurationUtilTest.java
@@ -265,6 +265,20 @@ public class WifiConfigurationUtilTest {
}
/**
+ * Verify that the validate method fails to validate WifiConfiguration with bad ssid length.
+ */
+ @Test
+ public void testValidateNegativeCases_BadUtf8SsidLength() {
+ WifiConfiguration config = WifiConfigurationTestUtil.createOpenNetwork();
+ assertTrue(WifiConfigurationUtil.validate(config, WifiConfigurationUtil.VALIDATE_FOR_ADD));
+
+ config.SSID = "\"가하아너너ㅓ저저ㅓ어아아다자저ㅓ더타아어어러두어\"";
+ assertFalse(WifiConfigurationUtil.validate(config, WifiConfigurationUtil.VALIDATE_FOR_ADD));
+ config.SSID = "\"\"";
+ assertFalse(WifiConfigurationUtil.validate(config, WifiConfigurationUtil.VALIDATE_FOR_ADD));
+ }
+
+ /**
* Verify that the validate method fails to validate WifiConfiguration with malformed ssid
* string.
*/
diff --git a/tests/wifitests/src/com/android/server/wifi/util/NativeUtilTest.java b/tests/wifitests/src/com/android/server/wifi/util/NativeUtilTest.java
index 367e6b34a..05b719cd2 100644
--- a/tests/wifitests/src/com/android/server/wifi/util/NativeUtilTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/util/NativeUtilTest.java
@@ -113,6 +113,18 @@ public class NativeUtilTest {
}
/**
+ * Test that conversion of non utf-8 SSID string to bytes fail.
+ */
+ @Test
+ public void testNonUtf8SsidDecodeFails() throws Exception {
+ try {
+ NativeUtil.decodeSsid("\"\ud800\"");
+ fail("Expected ssid decode to fail");
+ } catch (IllegalArgumentException e) {
+ }
+ }
+
+ /**
* Test that conversion of ssid bytes to hex string ssid works.
*/
@Test