tturney | 1bdf77d | 2015-12-28 17:46:13 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python3.4 |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 2 | # |
tturney | 1bdf77d | 2015-12-28 17:46:13 -0800 | [diff] [blame] | 3 | # Copyright 2016 - The Android Open Source Project |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | import pprint |
Ang Li | 8e76718 | 2015-12-09 17:29:24 -0800 | [diff] [blame] | 18 | import random |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 19 | import time |
| 20 | |
Ang Li | c2d4521 | 2016-03-10 18:38:53 -0800 | [diff] [blame] | 21 | from acts import asserts |
Ang Li | 8252281 | 2016-06-02 13:57:21 -0700 | [diff] [blame] | 22 | from acts import base_test |
| 23 | from acts import signals |
| 24 | from acts.test_utils.wifi import wifi_test_utils as wutils |
Ang Li | c2d4521 | 2016-03-10 18:38:53 -0800 | [diff] [blame] | 25 | |
Ang Li | e8ed2b3 | 2015-12-11 12:30:20 -0800 | [diff] [blame] | 26 | WifiEnums = wutils.WifiEnums |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 27 | |
| 28 | # EAP Macros |
| 29 | EAP = WifiEnums.Eap |
| 30 | EapPhase2 = WifiEnums.EapPhase2 |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 31 | # Enterprise Config Macros |
| 32 | Ent = WifiEnums.Enterprise |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 33 | |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 34 | |
Ang Li | 8154905 | 2016-06-09 18:51:14 -0700 | [diff] [blame] | 35 | class WifiEnterpriseTest(base_test.BaseTestClass): |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 36 | def __init__(self, controllers): |
Ang Li | 8252281 | 2016-06-02 13:57:21 -0700 | [diff] [blame] | 37 | base_test.BaseTestClass.__init__(self, controllers) |
Roshan Pius | 58916a3 | 2016-06-16 16:26:44 -0700 | [diff] [blame] | 38 | self.tests = ("test_eap_connect", "test_eap_connect_negative", |
| 39 | "test_eap_connect_config_store", ) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 40 | |
| 41 | def setup_class(self): |
| 42 | self.dut = self.android_devices[0] |
Ang Li | 8e76718 | 2015-12-09 17:29:24 -0800 | [diff] [blame] | 43 | wutils.wifi_test_device_init(self.dut) |
Ang Li | 8154905 | 2016-06-09 18:51:14 -0700 | [diff] [blame] | 44 | # If running in a setup with attenuators, set attenuation on all |
| 45 | # channels to zero. |
| 46 | if getattr(self, "attenuators", []): |
| 47 | for a in self.attenuators: |
| 48 | a.set_atten(0) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 49 | required_userparam_names = ( |
Ang Li | 8154905 | 2016-06-09 18:51:14 -0700 | [diff] [blame] | 50 | "ca_cert", "client_cert", "client_key", "passpoint_ca_cert", |
| 51 | "passpoint_client_cert", "passpoint_client_key", "eap_identity", |
| 52 | "eap_password", "invalid_ca_cert", "invalid_client_cert", |
| 53 | "invalid_client_key", "fqdn", "provider_friendly_name", "realm", |
| 54 | "ssid_peap0", "ssid_peap1", "ssid_tls", "ssid_ttls", "ssid_pwd", |
| 55 | "ssid_sim", "ssid_aka", "ssid_aka_prime", "ssid_passpoint", |
| 56 | "device_password", "ping_addr") |
Ang Li | 5cd6d3c | 2016-02-01 11:29:14 -0800 | [diff] [blame] | 57 | self.unpack_userparams(required_userparam_names, |
Ang Li | 8252281 | 2016-06-02 13:57:21 -0700 | [diff] [blame] | 58 | roaming_consortium_ids=None, |
| 59 | plmn=None) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 60 | # Default configs for EAP networks. |
Ang Li | 8252281 | 2016-06-02 13:57:21 -0700 | [diff] [blame] | 61 | self.config_peap0 = { |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 62 | Ent.EAP: EAP.PEAP, |
| 63 | Ent.CA_CERT: self.ca_cert, |
| 64 | Ent.IDENTITY: self.eap_identity, |
| 65 | Ent.PASSWORD: self.eap_password, |
| 66 | Ent.PHASE2: EapPhase2.MSCHAPV2, |
Ang Li | 8252281 | 2016-06-02 13:57:21 -0700 | [diff] [blame] | 67 | WifiEnums.SSID_KEY: self.ssid_peap0 |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 68 | } |
Ang Li | 8252281 | 2016-06-02 13:57:21 -0700 | [diff] [blame] | 69 | self.config_peap1 = dict(self.config_peap0) |
| 70 | self.config_peap1[WifiEnums.SSID_KEY] = self.ssid_peap1 |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 71 | self.config_tls = { |
| 72 | Ent.EAP: EAP.TLS, |
| 73 | Ent.CA_CERT: self.ca_cert, |
| 74 | WifiEnums.SSID_KEY: self.ssid_tls, |
| 75 | Ent.CLIENT_CERT: self.client_cert, |
| 76 | Ent.PRIVATE_KEY_ID: self.client_key, |
| 77 | Ent.IDENTITY: self.eap_identity, |
| 78 | } |
| 79 | self.config_ttls = { |
| 80 | Ent.EAP: EAP.TTLS, |
| 81 | Ent.CA_CERT: self.ca_cert, |
| 82 | Ent.IDENTITY: self.eap_identity, |
| 83 | Ent.PASSWORD: self.eap_password, |
| 84 | Ent.PHASE2: EapPhase2.MSCHAPV2, |
| 85 | WifiEnums.SSID_KEY: self.ssid_ttls |
| 86 | } |
Ang Li | 8252281 | 2016-06-02 13:57:21 -0700 | [diff] [blame] | 87 | self.config_pwd = { |
| 88 | Ent.EAP: EAP.PWD, |
| 89 | Ent.IDENTITY: self.eap_identity, |
| 90 | Ent.PASSWORD: self.eap_password, |
| 91 | WifiEnums.SSID_KEY: self.ssid_pwd |
| 92 | } |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 93 | self.config_sim = { |
| 94 | Ent.EAP: EAP.SIM, |
| 95 | WifiEnums.SSID_KEY: self.ssid_sim, |
| 96 | } |
Ang Li | 8252281 | 2016-06-02 13:57:21 -0700 | [diff] [blame] | 97 | self.config_aka = { |
| 98 | Ent.EAP: EAP.AKA, |
| 99 | WifiEnums.SSID_KEY: self.ssid_aka, |
| 100 | } |
| 101 | self.config_aka_prime = { |
| 102 | Ent.EAP: EAP.AKA_PRIME, |
| 103 | WifiEnums.SSID_KEY: self.ssid_aka_prime, |
| 104 | } |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 105 | |
| 106 | # Base config for passpoint networks. |
| 107 | self.config_passpoint = { |
| 108 | Ent.FQDN: self.fqdn, |
| 109 | Ent.FRIENDLY_NAME: self.provider_friendly_name, |
| 110 | Ent.REALM: self.realm, |
| 111 | Ent.CA_CERT: self.passpoint_ca_cert |
| 112 | } |
Ang Li | 8252281 | 2016-06-02 13:57:21 -0700 | [diff] [blame] | 113 | if self.plmn: |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 114 | self.config_passpoint[Ent.PLMN] = self.plmn |
Ang Li | 8252281 | 2016-06-02 13:57:21 -0700 | [diff] [blame] | 115 | if self.roaming_consortium_ids: |
Ang Li | 8154905 | 2016-06-09 18:51:14 -0700 | [diff] [blame] | 116 | self.config_passpoint[ |
| 117 | Ent.ROAMING_IDS] = self.roaming_consortium_ids |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 118 | |
| 119 | # Default configs for passpoint networks. |
| 120 | self.config_passpoint_tls = dict(self.config_tls) |
| 121 | self.config_passpoint_tls.update(self.config_passpoint) |
| 122 | self.config_passpoint_tls[Ent.CLIENT_CERT] = self.passpoint_client_cert |
Ang Li | 8154905 | 2016-06-09 18:51:14 -0700 | [diff] [blame] | 123 | self.config_passpoint_tls[ |
| 124 | Ent.PRIVATE_KEY_ID] = self.passpoint_client_key |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 125 | del self.config_passpoint_tls[WifiEnums.SSID_KEY] |
| 126 | self.config_passpoint_ttls = dict(self.config_ttls) |
| 127 | self.config_passpoint_ttls.update(self.config_passpoint) |
| 128 | del self.config_passpoint_ttls[WifiEnums.SSID_KEY] |
| 129 | # Set screen lock password so ConfigStore is unlocked. |
Ang Li | a9d188f | 2016-02-17 18:03:01 -0800 | [diff] [blame] | 130 | self.dut.droid.setDevicePassword(self.device_password) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 131 | |
| 132 | def teardown_class(self): |
Ang Li | 8e76718 | 2015-12-09 17:29:24 -0800 | [diff] [blame] | 133 | wutils.reset_wifi(self.dut) |
Ang Li | a9d188f | 2016-02-17 18:03:01 -0800 | [diff] [blame] | 134 | self.dut.droid.disableDevicePassword() |
| 135 | self.dut.ed.clear_all_events() |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 136 | |
| 137 | def setup_test(self): |
Ang Li | a9d188f | 2016-02-17 18:03:01 -0800 | [diff] [blame] | 138 | self.dut.droid.wifiStartTrackingStateChange() |
| 139 | self.dut.droid.wakeLockAcquireBright() |
| 140 | self.dut.droid.wakeUpNow() |
Ang Li | 8e76718 | 2015-12-09 17:29:24 -0800 | [diff] [blame] | 141 | wutils.reset_wifi(self.dut) |
Ang Li | a9d188f | 2016-02-17 18:03:01 -0800 | [diff] [blame] | 142 | self.dut.ed.clear_all_events() |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 143 | |
| 144 | def teardown_test(self): |
Ang Li | a9d188f | 2016-02-17 18:03:01 -0800 | [diff] [blame] | 145 | self.dut.droid.wakeLockRelease() |
| 146 | self.dut.droid.goToSleepNow() |
| 147 | self.dut.droid.wifiStopTrackingStateChange() |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 148 | |
Ang Li | 20377aa | 2016-02-26 13:19:51 -0800 | [diff] [blame] | 149 | def on_fail(self, test_name, begin_time): |
| 150 | self.dut.cat_adb_log(test_name, begin_time) |
| 151 | |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 152 | """Helper Functions""" |
| 153 | |
| 154 | def eap_negative_connect_logic(self, config, ad): |
| 155 | """Tries to connect to an enterprise network with invalid credentials |
| 156 | and expect a failure. |
| 157 | |
| 158 | Args: |
| 159 | config: A dict representing an invalid EAP credential. |
| 160 | |
| 161 | Returns: |
| 162 | True if connection failed as expected, False otherwise. |
| 163 | """ |
Ang Li | 8252281 | 2016-06-02 13:57:21 -0700 | [diff] [blame] | 164 | with asserts.assert_raises(signals.TestFailure, extras=config): |
Bindu Mahadev | 50374df | 2017-01-04 11:03:32 -0800 | [diff] [blame^] | 165 | verdict = wutils.wifi_connect(ad, config) |
Ang Li | 8252281 | 2016-06-02 13:57:21 -0700 | [diff] [blame] | 166 | asserts.explicit_pass("Connection failed as expected.") |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 167 | |
| 168 | def expand_config_by_phase2(self, config): |
| 169 | """Take an enterprise config and generate a list of configs, each with |
| 170 | a different phase2 auth type. |
| 171 | |
| 172 | Args: |
| 173 | config: A dict representing enterprise config. |
| 174 | |
| 175 | Returns |
| 176 | A list of enterprise configs. |
| 177 | """ |
| 178 | results = [] |
| 179 | for phase2_type in EapPhase2: |
| 180 | # Skip a special case for passpoint TTLS. |
| 181 | if Ent.FQDN in config and phase2_type == EapPhase2.GTC: |
| 182 | continue |
| 183 | c = dict(config) |
| 184 | c[Ent.PHASE2] = phase2_type |
| 185 | results.append(c) |
| 186 | return results |
| 187 | |
| 188 | def gen_eap_configs(self): |
| 189 | """Generates configurations for different EAP authentication types. |
| 190 | |
| 191 | Returns: |
| 192 | A list of dicts each representing an EAP configuration. |
| 193 | """ |
Ang Li | 8154905 | 2016-06-09 18:51:14 -0700 | [diff] [blame] | 194 | configs = [self.config_tls, self.config_pwd, self.config_sim, |
| 195 | self.config_aka, self.config_aka_prime] |
Ang Li | 8e76718 | 2015-12-09 17:29:24 -0800 | [diff] [blame] | 196 | configs += wutils.expand_enterprise_config_by_phase2(self.config_ttls) |
Ang Li | 8252281 | 2016-06-02 13:57:21 -0700 | [diff] [blame] | 197 | configs += wutils.expand_enterprise_config_by_phase2(self.config_peap0) |
| 198 | configs += wutils.expand_enterprise_config_by_phase2(self.config_peap1) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 199 | return configs |
| 200 | |
| 201 | def gen_passpoint_configs(self): |
| 202 | """Generates passpoint configurations for different EAP authentication |
| 203 | types. |
| 204 | |
| 205 | Returns: |
| 206 | A list of dicts each representing an EAP configuration for |
| 207 | passpoint networks. |
| 208 | """ |
| 209 | configs = [self.config_passpoint_tls] |
Ang Li | 8154905 | 2016-06-09 18:51:14 -0700 | [diff] [blame] | 210 | configs += wutils.expand_enterprise_config_by_phase2( |
| 211 | self.config_passpoint_ttls) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 212 | return configs |
| 213 | |
| 214 | def gen_negative_configs(self, configs, neg_params): |
| 215 | """Generic function used to generate negative configs. |
| 216 | |
| 217 | For all the valid configurations, if a param in the neg_params also |
| 218 | exists in a config, a copy of the config is made with an invalid value |
| 219 | of the param. |
| 220 | |
| 221 | Args: |
| 222 | configs: A list of valid configurations. |
| 223 | neg_params: A dict that has all the invalid values. |
| 224 | |
| 225 | Returns: |
| 226 | A list of invalid configurations generated based on the valid |
| 227 | configurations. Each invalid configuration has a different invalid |
| 228 | field. |
| 229 | """ |
| 230 | results = [] |
| 231 | for c in configs: |
| 232 | for k, v in neg_params.items(): |
| 233 | # Skip negative test for TLS's identity field since it's not |
| 234 | # used for auth. |
| 235 | if c[Ent.EAP] == EAP.TLS and k == Ent.IDENTITY: |
| 236 | continue |
| 237 | if k in c: |
| 238 | nc = dict(c) |
| 239 | nc[k] = v |
| 240 | nc["invalid_field"] = k |
| 241 | results.append(nc) |
| 242 | return results |
| 243 | |
| 244 | def gen_negative_eap_configs(self): |
| 245 | """Generates invalid configurations for different EAP authentication |
| 246 | types. |
| 247 | |
| 248 | For all the valid EAP configurations, if a param that is part of the |
| 249 | authentication info exists in a config, a copy of the config is made |
| 250 | with an invalid value of the param. |
| 251 | |
| 252 | Returns: |
| 253 | A list of dicts each representing an invalid EAP configuration. |
| 254 | """ |
| 255 | neg_params = { |
| 256 | Ent.CLIENT_CERT: self.invalid_client_cert, |
| 257 | Ent.CA_CERT: self.invalid_ca_cert, |
| 258 | Ent.PRIVATE_KEY_ID: self.invalid_client_key, |
| 259 | Ent.IDENTITY: "fake_identity", |
| 260 | Ent.PASSWORD: "wrong_password" |
| 261 | } |
| 262 | configs = self.gen_eap_configs() |
| 263 | return self.gen_negative_configs(configs, neg_params) |
| 264 | |
| 265 | def gen_negative_passpoint_configs(self): |
| 266 | """Generates invalid configurations for different EAP authentication |
| 267 | types with passpoint support. |
| 268 | |
| 269 | Returns: |
| 270 | A list of dicts each representing an invalid EAP configuration |
| 271 | with passpoint fields. |
| 272 | """ |
| 273 | neg_params = { |
| 274 | Ent.CLIENT_CERT: self.invalid_client_cert, |
| 275 | Ent.CA_CERT: self.invalid_ca_cert, |
| 276 | Ent.PRIVATE_KEY_ID: self.invalid_client_key, |
| 277 | Ent.IDENTITY: "fake_identity", |
| 278 | Ent.PASSWORD: "wrong_password", |
| 279 | Ent.FQDN: "fake_fqdn", |
| 280 | Ent.REALM: "where_no_one_has_gone_before", |
| 281 | Ent.PLMN: "fake_plmn", |
| 282 | Ent.ROAMING_IDS: [1234567890, 9876543210] |
| 283 | } |
| 284 | configs = self.gen_passpoint_configs() |
| 285 | return self.gen_negative_configs(configs, neg_params) |
| 286 | |
| 287 | def gen_eap_test_name(self, config, ad): |
| 288 | """Generates a test case name based on an EAP configuration. |
| 289 | |
| 290 | Args: |
| 291 | config: A dict representing an EAP credential. |
| 292 | ad: Discarded. This is here because name function signature needs |
| 293 | to be consistent with logic function signature for generated |
| 294 | test cases. |
| 295 | |
| 296 | Returns: |
| 297 | A string representing the name of a generated EAP test case. |
| 298 | """ |
Ang Li | 8252281 | 2016-06-02 13:57:21 -0700 | [diff] [blame] | 299 | eap_name = config[Ent.EAP].name |
| 300 | if "peap0" in config[WifiEnums.SSID_KEY].lower(): |
| 301 | eap_name = "PEAP0" |
| 302 | if "peap1" in config[WifiEnums.SSID_KEY].lower(): |
| 303 | eap_name = "PEAP1" |
| 304 | name = "test_connect-%s" % eap_name |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 305 | if Ent.PHASE2 in config: |
| 306 | name += "-{}".format(config[Ent.PHASE2].name) |
| 307 | return name |
| 308 | |
Roshan Pius | 58916a3 | 2016-06-16 16:26:44 -0700 | [diff] [blame] | 309 | def gen_eap_test_name_for_config_store(self, config, ad): |
| 310 | """Generates a test case name based on an EAP configuration for config |
| 311 | store tests. |
| 312 | |
| 313 | Args: |
| 314 | config: A dict representing an EAP credential. |
| 315 | ad: Discarded. This is here because name function signature needs |
| 316 | to be consistent with logic function signature for generated |
| 317 | test cases. |
| 318 | |
| 319 | Returns: |
| 320 | A string representing the name of a generated EAP test case. |
| 321 | """ |
| 322 | return self.gen_eap_test_name(config, ad) + "-config_store" |
| 323 | |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 324 | def gen_passpoint_test_name(self, config, ad): |
| 325 | """Generates a test case name based on an EAP passpoint configuration. |
| 326 | |
| 327 | Args: |
| 328 | config: A dict representing an EAP passpoint credential. |
| 329 | ad: Discarded. This is here because name function signature needs |
| 330 | to be consistent with logic function signature for generated |
| 331 | test cases. |
| 332 | |
| 333 | Returns: |
| 334 | A string representing the name of a generated EAP passpoint connect |
| 335 | test case. |
| 336 | """ |
| 337 | name = self.gen_eap_test_name(config, ad) |
| 338 | name = name.replace("connect", "passpoint_connect") |
| 339 | return name |
| 340 | |
Roshan Pius | 58916a3 | 2016-06-16 16:26:44 -0700 | [diff] [blame] | 341 | def gen_passpoint_test_name_for_config_store(self, config, ad): |
| 342 | """Generates a test case name based on an EAP passpoint configuration |
| 343 | for config store tests. |
| 344 | |
| 345 | Args: |
| 346 | config: A dict representing an EAP passpoint credential. |
| 347 | ad: Discarded. This is here because name function signature needs |
| 348 | to be consistent with logic function signature for generated |
| 349 | test cases. |
| 350 | |
| 351 | Returns: |
| 352 | A string representing the name of a generated EAP passpoint connect |
| 353 | test case. |
| 354 | """ |
| 355 | return self.gen_passpoint_test_name(config, ad) + "-config_store" |
| 356 | |
| 357 | def eap_connect_toggle_wifi(self, |
| 358 | config, |
| 359 | *args): |
| 360 | """Connects to an enterprise network, toggles wifi state and ensures |
| 361 | that the device reconnects. |
| 362 | |
| 363 | This logic expect the enterprise network to have Internet access. |
| 364 | |
| 365 | Args: |
| 366 | config: A dict representing a wifi enterprise configuration. |
| 367 | args: args to be passed to |wutils.eap_connect|. |
| 368 | |
| 369 | Returns: |
| 370 | True if the connection is successful and Internet access works. |
| 371 | """ |
Roshan Pius | 58916a3 | 2016-06-16 16:26:44 -0700 | [diff] [blame] | 372 | ad = args[0] |
Bindu Mahadev | 50374df | 2017-01-04 11:03:32 -0800 | [diff] [blame^] | 373 | wutils.wifi_connect(ad, config) |
| 374 | wutils.toggle_wifi_and_wait_for_reconnection(ad, config, num_of_tries=5) |
Roshan Pius | 58916a3 | 2016-06-16 16:26:44 -0700 | [diff] [blame] | 375 | |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 376 | """Tests""" |
Ang Li | 8154905 | 2016-06-09 18:51:14 -0700 | [diff] [blame] | 377 | |
Ang Li | 8252281 | 2016-06-02 13:57:21 -0700 | [diff] [blame] | 378 | @signals.generated_test |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 379 | def test_eap_connect(self): |
| 380 | """Test connecting to enterprise networks of different authentication |
| 381 | types. |
| 382 | |
| 383 | The authentication types tested are: |
| 384 | EAP-TLS |
| 385 | EAP-PEAP with different phase2 types. |
| 386 | EAP-TTLS with different phase2 types. |
| 387 | |
| 388 | Procedures: |
| 389 | For each enterprise wifi network |
| 390 | 1. Connect to the network. |
| 391 | 2. Send a GET request to a website and check response. |
| 392 | |
| 393 | Expect: |
| 394 | Successful connection and Internet access through the enterprise |
| 395 | networks. |
| 396 | """ |
| 397 | eap_configs = self.gen_eap_configs() |
Ang Li | 8154905 | 2016-06-09 18:51:14 -0700 | [diff] [blame] | 398 | self.log.info("Testing %d different configs.", len(eap_configs)) |
Ang Li | 8e76718 | 2015-12-09 17:29:24 -0800 | [diff] [blame] | 399 | random.shuffle(eap_configs) |
Bindu Mahadev | 50374df | 2017-01-04 11:03:32 -0800 | [diff] [blame^] | 400 | failed = self.run_generated_testcases(wutils.wifi_connect, |
Ang Li | 8154905 | 2016-06-09 18:51:14 -0700 | [diff] [blame] | 401 | eap_configs, |
| 402 | args=(self.dut, ), |
Bindu Mahadev | 50374df | 2017-01-04 11:03:32 -0800 | [diff] [blame^] | 403 | name_func=self.gen_eap_test_name, |
| 404 | format_args=True) |
Ang Li | 8154905 | 2016-06-09 18:51:14 -0700 | [diff] [blame] | 405 | asserts.assert_equal( |
| 406 | len(failed), 0, "The following configs failed EAP connect test: %s" |
| 407 | % pprint.pformat(failed)) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 408 | |
Ang Li | 8252281 | 2016-06-02 13:57:21 -0700 | [diff] [blame] | 409 | @signals.generated_test |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 410 | def test_eap_connect_negative(self): |
| 411 | """Test connecting to enterprise networks. |
| 412 | |
| 413 | Procedures: |
| 414 | For each enterprise wifi network |
| 415 | 1. Connect to the network with invalid credentials. |
| 416 | |
| 417 | Expect: |
| 418 | Fail to establish connection. |
| 419 | """ |
| 420 | neg_eap_configs = self.gen_negative_eap_configs() |
Ang Li | 8154905 | 2016-06-09 18:51:14 -0700 | [diff] [blame] | 421 | self.log.info("Testing %d different configs.", len(neg_eap_configs)) |
Ang Li | 8e76718 | 2015-12-09 17:29:24 -0800 | [diff] [blame] | 422 | random.shuffle(neg_eap_configs) |
Ang Li | 8154905 | 2016-06-09 18:51:14 -0700 | [diff] [blame] | 423 | |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 424 | def name_gen(config, ad): |
| 425 | name = self.gen_eap_test_name(config, ad) |
| 426 | name += "-with_wrong-{}".format(config["invalid_field"]) |
| 427 | return name |
Ang Li | 8154905 | 2016-06-09 18:51:14 -0700 | [diff] [blame] | 428 | |
| 429 | failed = self.run_generated_testcases(self.eap_negative_connect_logic, |
| 430 | neg_eap_configs, |
| 431 | args=(self.dut, ), |
| 432 | name_func=name_gen) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 433 | msg = ("The following configs failed negative EAP connect test: %s" % |
| 434 | pprint.pformat(failed)) |
Ang Li | 8252281 | 2016-06-02 13:57:21 -0700 | [diff] [blame] | 435 | asserts.assert_equal(len(failed), 0, msg) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 436 | |
Ang Li | 8252281 | 2016-06-02 13:57:21 -0700 | [diff] [blame] | 437 | @signals.generated_test |
Roshan Pius | 58916a3 | 2016-06-16 16:26:44 -0700 | [diff] [blame] | 438 | def test_eap_connect_config_store(self): |
| 439 | """Test connecting to enterprise networks of different authentication |
| 440 | types after wifi toggle. |
| 441 | |
| 442 | The authentication types tested are: |
| 443 | EAP-TLS |
| 444 | EAP-PEAP with different phase2 types. |
| 445 | EAP-TTLS with different phase2 types. |
| 446 | |
| 447 | Procedures: |
| 448 | For each enterprise wifi network |
| 449 | 1. Connect to the network. |
| 450 | 2. Send a GET request to a website and check response. |
| 451 | 3. Toggle wifi. |
| 452 | 4. Ensure that the device reconnects to the same network. |
| 453 | |
| 454 | Expect: |
| 455 | Successful connection and Internet access through the enterprise |
| 456 | networks. |
| 457 | """ |
| 458 | eap_configs = self.gen_eap_configs() |
| 459 | self.log.info("Testing %d different configs.", len(eap_configs)) |
| 460 | random.shuffle(eap_configs) |
| 461 | failed = self.run_generated_testcases( |
| 462 | self.eap_connect_toggle_wifi, |
| 463 | eap_configs, |
| 464 | args=(self.dut, ), |
| 465 | name_func=self.gen_eap_test_name_for_config_store) |
| 466 | asserts.assert_equal( |
| 467 | len(failed), 0, "The following configs failed EAP connect test: %s" |
| 468 | % pprint.pformat(failed)) |
| 469 | |
| 470 | @signals.generated_test |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 471 | def test_passpoint_connect(self): |
| 472 | """Test connecting to enterprise networks of different authentication |
| 473 | types with passpoint support. |
| 474 | |
| 475 | The authentication types tested are: |
| 476 | EAP-TLS |
| 477 | EAP-TTLS with MSCHAPV2 as phase2. |
| 478 | |
| 479 | Procedures: |
| 480 | For each enterprise wifi network |
| 481 | 1. Connect to the network. |
| 482 | 2. Send a GET request to a website and check response. |
| 483 | |
| 484 | Expect: |
| 485 | Successful connection and Internet access through the enterprise |
| 486 | networks with passpoint support. |
| 487 | """ |
Ang Li | c2d4521 | 2016-03-10 18:38:53 -0800 | [diff] [blame] | 488 | asserts.skip_if(not self.dut.droid.wifiIsPasspointSupported(), |
Ang Li | 8154905 | 2016-06-09 18:51:14 -0700 | [diff] [blame] | 489 | "Passpoint is not supported on device %s" % |
| 490 | self.dut.model) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 491 | passpoint_configs = self.gen_passpoint_configs() |
Ang Li | 8154905 | 2016-06-09 18:51:14 -0700 | [diff] [blame] | 492 | self.log.info("Testing %d different configs.", len(passpoint_configs)) |
Ang Li | 8e76718 | 2015-12-09 17:29:24 -0800 | [diff] [blame] | 493 | random.shuffle(passpoint_configs) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 494 | failed = self.run_generated_testcases( |
Bindu Mahadev | 50374df | 2017-01-04 11:03:32 -0800 | [diff] [blame^] | 495 | wutils.wifi_connect, |
| 496 | passpoint_configs, |
| 497 | args=(self.dut, ), |
| 498 | name_func=self.gen_passpoint_test_name, |
| 499 | format_args=True) |
Ang Li | 8154905 | 2016-06-09 18:51:14 -0700 | [diff] [blame] | 500 | asserts.assert_equal( |
| 501 | len(failed), 0, |
| 502 | "The following configs failed passpoint connect test: %s" % |
| 503 | pprint.pformat(failed)) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 504 | |
Ang Li | 8252281 | 2016-06-02 13:57:21 -0700 | [diff] [blame] | 505 | @signals.generated_test |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 506 | def test_passpoint_connect_negative(self): |
| 507 | """Test connecting to enterprise networks. |
| 508 | |
| 509 | Procedures: |
| 510 | For each enterprise wifi network |
| 511 | 1. Connect to the network with invalid credentials. |
| 512 | |
| 513 | Expect: |
| 514 | Fail to establish connection. |
| 515 | """ |
Ang Li | c2d4521 | 2016-03-10 18:38:53 -0800 | [diff] [blame] | 516 | asserts.skip_if(not self.dut.droid.wifiIsPasspointSupported(), |
Ang Li | 8154905 | 2016-06-09 18:51:14 -0700 | [diff] [blame] | 517 | "Passpoint is not supported on device %s" % |
| 518 | self.dut.model) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 519 | neg_passpoint_configs = self.gen_negative_passpoint_configs() |
Ang Li | 8154905 | 2016-06-09 18:51:14 -0700 | [diff] [blame] | 520 | self.log.info("Testing %d different configs.", |
| 521 | len(neg_passpoint_configs)) |
Ang Li | 8e76718 | 2015-12-09 17:29:24 -0800 | [diff] [blame] | 522 | random.shuffle(neg_passpoint_configs) |
Ang Li | 8154905 | 2016-06-09 18:51:14 -0700 | [diff] [blame] | 523 | |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 524 | def name_gen(config, ad): |
| 525 | name = self.gen_passpoint_test_name(config, ad) |
| 526 | name += "-with_wrong-{}".format(config["invalid_field"]) |
| 527 | return name |
Ang Li | 8154905 | 2016-06-09 18:51:14 -0700 | [diff] [blame] | 528 | |
| 529 | failed = self.run_generated_testcases(self.eap_negative_connect_logic, |
| 530 | neg_passpoint_configs, |
| 531 | args=(self.dut, ), |
| 532 | name_func=name_gen) |
| 533 | asserts.assert_equal( |
| 534 | len(failed), 0, |
| 535 | "The following configs failed negative passpoint connect test: %s" |
| 536 | % pprint.pformat(failed)) |
Roshan Pius | 58916a3 | 2016-06-16 16:26:44 -0700 | [diff] [blame] | 537 | |
| 538 | @signals.generated_test |
| 539 | def test_passpoint_connect_config_store(self): |
| 540 | """Test connecting to enterprise networks of different authentication |
| 541 | types with passpoint support after wifi toggle. |
| 542 | |
| 543 | The authentication types tested are: |
| 544 | EAP-TLS |
| 545 | EAP-TTLS with MSCHAPV2 as phase2. |
| 546 | |
| 547 | Procedures: |
| 548 | For each enterprise wifi network |
| 549 | 1. Connect to the network. |
| 550 | 2. Send a GET request to a website and check response. |
| 551 | 3. Toggle wifi. |
| 552 | 4. Ensure that the device reconnects to the same network. |
| 553 | |
| 554 | Expect: |
| 555 | Successful connection and Internet access through the enterprise |
| 556 | networks with passpoint support. |
| 557 | """ |
| 558 | asserts.skip_if(not self.dut.droid.wifiIsPasspointSupported(), |
| 559 | "Passpoint is not supported on device %s" % |
| 560 | self.dut.model) |
| 561 | passpoint_configs = self.gen_passpoint_configs() |
| 562 | self.log.info("Testing %d different configs.", len(passpoint_configs)) |
| 563 | random.shuffle(passpoint_configs) |
| 564 | failed = self.run_generated_testcases( |
| 565 | self.eap_connect_toggle_wifi, |
| 566 | passpoint_configs, |
| 567 | args=(self.dut, ), |
| 568 | name_func=self.gen_passpoint_test_name_for_config_store) |
| 569 | asserts.assert_equal( |
| 570 | len(failed), 0, |
| 571 | "The following configs failed passpoint connect test: %s" % |
| 572 | pprint.pformat(failed)) |