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 = { |
Girish Moturu | 150d32f | 2017-02-14 12:27:07 -0800 | [diff] [blame^] | 62 | Ent.EAP: int(EAP.PEAP), |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 63 | Ent.CA_CERT: self.ca_cert, |
| 64 | Ent.IDENTITY: self.eap_identity, |
| 65 | Ent.PASSWORD: self.eap_password, |
Girish Moturu | 150d32f | 2017-02-14 12:27:07 -0800 | [diff] [blame^] | 66 | Ent.PHASE2: int(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 = { |
Girish Moturu | 150d32f | 2017-02-14 12:27:07 -0800 | [diff] [blame^] | 72 | Ent.EAP: int(EAP.TLS), |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 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 = { |
Girish Moturu | 150d32f | 2017-02-14 12:27:07 -0800 | [diff] [blame^] | 80 | Ent.EAP: int(EAP.TTLS), |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 81 | Ent.CA_CERT: self.ca_cert, |
| 82 | Ent.IDENTITY: self.eap_identity, |
| 83 | Ent.PASSWORD: self.eap_password, |
Girish Moturu | 150d32f | 2017-02-14 12:27:07 -0800 | [diff] [blame^] | 84 | Ent.PHASE2: int(EapPhase2.MSCHAPV2), |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 85 | WifiEnums.SSID_KEY: self.ssid_ttls |
| 86 | } |
Ang Li | 8252281 | 2016-06-02 13:57:21 -0700 | [diff] [blame] | 87 | self.config_pwd = { |
Girish Moturu | 150d32f | 2017-02-14 12:27:07 -0800 | [diff] [blame^] | 88 | Ent.EAP: int(EAP.PWD), |
Ang Li | 8252281 | 2016-06-02 13:57:21 -0700 | [diff] [blame] | 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 = { |
Girish Moturu | 150d32f | 2017-02-14 12:27:07 -0800 | [diff] [blame^] | 94 | Ent.EAP: int(EAP.SIM), |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 95 | WifiEnums.SSID_KEY: self.ssid_sim, |
| 96 | } |
Ang Li | 8252281 | 2016-06-02 13:57:21 -0700 | [diff] [blame] | 97 | self.config_aka = { |
Girish Moturu | 150d32f | 2017-02-14 12:27:07 -0800 | [diff] [blame^] | 98 | Ent.EAP: int(EAP.AKA), |
Ang Li | 8252281 | 2016-06-02 13:57:21 -0700 | [diff] [blame] | 99 | WifiEnums.SSID_KEY: self.ssid_aka, |
| 100 | } |
| 101 | self.config_aka_prime = { |
Girish Moturu | 150d32f | 2017-02-14 12:27:07 -0800 | [diff] [blame^] | 102 | Ent.EAP: int(EAP.AKA_PRIME), |
Ang Li | 8252281 | 2016-06-02 13:57:21 -0700 | [diff] [blame] | 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) |
Girish Moturu | 150d32f | 2017-02-14 12:27:07 -0800 | [diff] [blame^] | 184 | c[Ent.PHASE2] = phase2_type.value |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 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 | |
Roshan Pius | 58916a3 | 2016-06-16 16:26:44 -0700 | [diff] [blame] | 287 | def gen_eap_test_name_for_config_store(self, config, ad): |
| 288 | """Generates a test case name based on an EAP configuration for config |
| 289 | store tests. |
| 290 | |
| 291 | Args: |
| 292 | config: A dict representing an EAP credential. |
| 293 | ad: Discarded. This is here because name function signature needs |
| 294 | to be consistent with logic function signature for generated |
| 295 | test cases. |
| 296 | |
| 297 | Returns: |
| 298 | A string representing the name of a generated EAP test case. |
| 299 | """ |
Girish Moturu | 150d32f | 2017-02-14 12:27:07 -0800 | [diff] [blame^] | 300 | return wutils.generate_eap_test_name(config) + "-config_store" |
Roshan Pius | 58916a3 | 2016-06-16 16:26:44 -0700 | [diff] [blame] | 301 | |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 302 | def gen_passpoint_test_name(self, config, ad): |
| 303 | """Generates a test case name based on an EAP passpoint configuration. |
| 304 | |
| 305 | Args: |
| 306 | config: A dict representing an EAP passpoint credential. |
| 307 | ad: Discarded. This is here because name function signature needs |
| 308 | to be consistent with logic function signature for generated |
| 309 | test cases. |
| 310 | |
| 311 | Returns: |
| 312 | A string representing the name of a generated EAP passpoint connect |
| 313 | test case. |
| 314 | """ |
Girish Moturu | 150d32f | 2017-02-14 12:27:07 -0800 | [diff] [blame^] | 315 | name = wutils.generate_eap_test_name(config) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 316 | name = name.replace("connect", "passpoint_connect") |
| 317 | return name |
| 318 | |
Roshan Pius | 58916a3 | 2016-06-16 16:26:44 -0700 | [diff] [blame] | 319 | def gen_passpoint_test_name_for_config_store(self, config, ad): |
| 320 | """Generates a test case name based on an EAP passpoint configuration |
| 321 | for config store tests. |
| 322 | |
| 323 | Args: |
| 324 | config: A dict representing an EAP passpoint credential. |
| 325 | ad: Discarded. This is here because name function signature needs |
| 326 | to be consistent with logic function signature for generated |
| 327 | test cases. |
| 328 | |
| 329 | Returns: |
| 330 | A string representing the name of a generated EAP passpoint connect |
| 331 | test case. |
| 332 | """ |
| 333 | return self.gen_passpoint_test_name(config, ad) + "-config_store" |
| 334 | |
| 335 | def eap_connect_toggle_wifi(self, |
| 336 | config, |
| 337 | *args): |
| 338 | """Connects to an enterprise network, toggles wifi state and ensures |
| 339 | that the device reconnects. |
| 340 | |
| 341 | This logic expect the enterprise network to have Internet access. |
| 342 | |
| 343 | Args: |
| 344 | config: A dict representing a wifi enterprise configuration. |
| 345 | args: args to be passed to |wutils.eap_connect|. |
| 346 | |
| 347 | Returns: |
| 348 | True if the connection is successful and Internet access works. |
| 349 | """ |
Roshan Pius | 58916a3 | 2016-06-16 16:26:44 -0700 | [diff] [blame] | 350 | ad = args[0] |
Bindu Mahadev | 50374df | 2017-01-04 11:03:32 -0800 | [diff] [blame] | 351 | wutils.wifi_connect(ad, config) |
| 352 | 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] | 353 | |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 354 | """Tests""" |
Ang Li | 8154905 | 2016-06-09 18:51:14 -0700 | [diff] [blame] | 355 | |
Ang Li | 8252281 | 2016-06-02 13:57:21 -0700 | [diff] [blame] | 356 | @signals.generated_test |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 357 | def test_eap_connect(self): |
| 358 | """Test connecting to enterprise networks of different authentication |
| 359 | types. |
| 360 | |
| 361 | The authentication types tested are: |
| 362 | EAP-TLS |
| 363 | EAP-PEAP with different phase2 types. |
| 364 | EAP-TTLS with different phase2 types. |
| 365 | |
| 366 | Procedures: |
| 367 | For each enterprise wifi network |
| 368 | 1. Connect to the network. |
| 369 | 2. Send a GET request to a website and check response. |
| 370 | |
| 371 | Expect: |
| 372 | Successful connection and Internet access through the enterprise |
| 373 | networks. |
| 374 | """ |
| 375 | eap_configs = self.gen_eap_configs() |
Ang Li | 8154905 | 2016-06-09 18:51:14 -0700 | [diff] [blame] | 376 | self.log.info("Testing %d different configs.", len(eap_configs)) |
Ang Li | 8e76718 | 2015-12-09 17:29:24 -0800 | [diff] [blame] | 377 | random.shuffle(eap_configs) |
Bindu Mahadev | 50374df | 2017-01-04 11:03:32 -0800 | [diff] [blame] | 378 | failed = self.run_generated_testcases(wutils.wifi_connect, |
Ang Li | 8154905 | 2016-06-09 18:51:14 -0700 | [diff] [blame] | 379 | eap_configs, |
| 380 | args=(self.dut, ), |
Girish Moturu | 150d32f | 2017-02-14 12:27:07 -0800 | [diff] [blame^] | 381 | name_func=wutils.generate_eap_test_name, |
Bindu Mahadev | 50374df | 2017-01-04 11:03:32 -0800 | [diff] [blame] | 382 | format_args=True) |
Ang Li | 8154905 | 2016-06-09 18:51:14 -0700 | [diff] [blame] | 383 | asserts.assert_equal( |
| 384 | len(failed), 0, "The following configs failed EAP connect test: %s" |
| 385 | % pprint.pformat(failed)) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 386 | |
Ang Li | 8252281 | 2016-06-02 13:57:21 -0700 | [diff] [blame] | 387 | @signals.generated_test |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 388 | def test_eap_connect_negative(self): |
| 389 | """Test connecting to enterprise networks. |
| 390 | |
| 391 | Procedures: |
| 392 | For each enterprise wifi network |
| 393 | 1. Connect to the network with invalid credentials. |
| 394 | |
| 395 | Expect: |
| 396 | Fail to establish connection. |
| 397 | """ |
| 398 | neg_eap_configs = self.gen_negative_eap_configs() |
Ang Li | 8154905 | 2016-06-09 18:51:14 -0700 | [diff] [blame] | 399 | self.log.info("Testing %d different configs.", len(neg_eap_configs)) |
Ang Li | 8e76718 | 2015-12-09 17:29:24 -0800 | [diff] [blame] | 400 | random.shuffle(neg_eap_configs) |
Ang Li | 8154905 | 2016-06-09 18:51:14 -0700 | [diff] [blame] | 401 | |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 402 | def name_gen(config, ad): |
Girish Moturu | 150d32f | 2017-02-14 12:27:07 -0800 | [diff] [blame^] | 403 | name = wutils.generate_eap_test_name(config) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 404 | name += "-with_wrong-{}".format(config["invalid_field"]) |
| 405 | return name |
Ang Li | 8154905 | 2016-06-09 18:51:14 -0700 | [diff] [blame] | 406 | |
| 407 | failed = self.run_generated_testcases(self.eap_negative_connect_logic, |
| 408 | neg_eap_configs, |
| 409 | args=(self.dut, ), |
| 410 | name_func=name_gen) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 411 | msg = ("The following configs failed negative EAP connect test: %s" % |
| 412 | pprint.pformat(failed)) |
Ang Li | 8252281 | 2016-06-02 13:57:21 -0700 | [diff] [blame] | 413 | asserts.assert_equal(len(failed), 0, msg) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 414 | |
Ang Li | 8252281 | 2016-06-02 13:57:21 -0700 | [diff] [blame] | 415 | @signals.generated_test |
Roshan Pius | 58916a3 | 2016-06-16 16:26:44 -0700 | [diff] [blame] | 416 | def test_eap_connect_config_store(self): |
| 417 | """Test connecting to enterprise networks of different authentication |
| 418 | types after wifi toggle. |
| 419 | |
| 420 | The authentication types tested are: |
| 421 | EAP-TLS |
| 422 | EAP-PEAP with different phase2 types. |
| 423 | EAP-TTLS with different phase2 types. |
| 424 | |
| 425 | Procedures: |
| 426 | For each enterprise wifi network |
| 427 | 1. Connect to the network. |
| 428 | 2. Send a GET request to a website and check response. |
| 429 | 3. Toggle wifi. |
| 430 | 4. Ensure that the device reconnects to the same network. |
| 431 | |
| 432 | Expect: |
| 433 | Successful connection and Internet access through the enterprise |
| 434 | networks. |
| 435 | """ |
| 436 | eap_configs = self.gen_eap_configs() |
| 437 | self.log.info("Testing %d different configs.", len(eap_configs)) |
| 438 | random.shuffle(eap_configs) |
| 439 | failed = self.run_generated_testcases( |
| 440 | self.eap_connect_toggle_wifi, |
| 441 | eap_configs, |
| 442 | args=(self.dut, ), |
Girish Moturu | 150d32f | 2017-02-14 12:27:07 -0800 | [diff] [blame^] | 443 | name_func=wutils.generate_eap_test_name) |
Roshan Pius | 58916a3 | 2016-06-16 16:26:44 -0700 | [diff] [blame] | 444 | asserts.assert_equal( |
| 445 | len(failed), 0, "The following configs failed EAP connect test: %s" |
| 446 | % pprint.pformat(failed)) |
| 447 | |
| 448 | @signals.generated_test |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 449 | def test_passpoint_connect(self): |
| 450 | """Test connecting to enterprise networks of different authentication |
| 451 | types with passpoint support. |
| 452 | |
| 453 | The authentication types tested are: |
| 454 | EAP-TLS |
| 455 | EAP-TTLS with MSCHAPV2 as phase2. |
| 456 | |
| 457 | Procedures: |
| 458 | For each enterprise wifi network |
| 459 | 1. Connect to the network. |
| 460 | 2. Send a GET request to a website and check response. |
| 461 | |
| 462 | Expect: |
| 463 | Successful connection and Internet access through the enterprise |
| 464 | networks with passpoint support. |
| 465 | """ |
Ang Li | c2d4521 | 2016-03-10 18:38:53 -0800 | [diff] [blame] | 466 | asserts.skip_if(not self.dut.droid.wifiIsPasspointSupported(), |
Ang Li | 8154905 | 2016-06-09 18:51:14 -0700 | [diff] [blame] | 467 | "Passpoint is not supported on device %s" % |
| 468 | self.dut.model) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 469 | passpoint_configs = self.gen_passpoint_configs() |
Ang Li | 8154905 | 2016-06-09 18:51:14 -0700 | [diff] [blame] | 470 | self.log.info("Testing %d different configs.", len(passpoint_configs)) |
Ang Li | 8e76718 | 2015-12-09 17:29:24 -0800 | [diff] [blame] | 471 | random.shuffle(passpoint_configs) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 472 | failed = self.run_generated_testcases( |
Bindu Mahadev | 50374df | 2017-01-04 11:03:32 -0800 | [diff] [blame] | 473 | wutils.wifi_connect, |
| 474 | passpoint_configs, |
| 475 | args=(self.dut, ), |
| 476 | name_func=self.gen_passpoint_test_name, |
| 477 | format_args=True) |
Ang Li | 8154905 | 2016-06-09 18:51:14 -0700 | [diff] [blame] | 478 | asserts.assert_equal( |
| 479 | len(failed), 0, |
| 480 | "The following configs failed passpoint connect test: %s" % |
| 481 | pprint.pformat(failed)) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 482 | |
Ang Li | 8252281 | 2016-06-02 13:57:21 -0700 | [diff] [blame] | 483 | @signals.generated_test |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 484 | def test_passpoint_connect_negative(self): |
| 485 | """Test connecting to enterprise networks. |
| 486 | |
| 487 | Procedures: |
| 488 | For each enterprise wifi network |
| 489 | 1. Connect to the network with invalid credentials. |
| 490 | |
| 491 | Expect: |
| 492 | Fail to establish connection. |
| 493 | """ |
Ang Li | c2d4521 | 2016-03-10 18:38:53 -0800 | [diff] [blame] | 494 | asserts.skip_if(not self.dut.droid.wifiIsPasspointSupported(), |
Ang Li | 8154905 | 2016-06-09 18:51:14 -0700 | [diff] [blame] | 495 | "Passpoint is not supported on device %s" % |
| 496 | self.dut.model) |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 497 | neg_passpoint_configs = self.gen_negative_passpoint_configs() |
Ang Li | 8154905 | 2016-06-09 18:51:14 -0700 | [diff] [blame] | 498 | self.log.info("Testing %d different configs.", |
| 499 | len(neg_passpoint_configs)) |
Ang Li | 8e76718 | 2015-12-09 17:29:24 -0800 | [diff] [blame] | 500 | random.shuffle(neg_passpoint_configs) |
Ang Li | 8154905 | 2016-06-09 18:51:14 -0700 | [diff] [blame] | 501 | |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 502 | def name_gen(config, ad): |
| 503 | name = self.gen_passpoint_test_name(config, ad) |
| 504 | name += "-with_wrong-{}".format(config["invalid_field"]) |
| 505 | return name |
Ang Li | 8154905 | 2016-06-09 18:51:14 -0700 | [diff] [blame] | 506 | |
| 507 | failed = self.run_generated_testcases(self.eap_negative_connect_logic, |
| 508 | neg_passpoint_configs, |
| 509 | args=(self.dut, ), |
| 510 | name_func=name_gen) |
| 511 | asserts.assert_equal( |
| 512 | len(failed), 0, |
| 513 | "The following configs failed negative passpoint connect test: %s" |
| 514 | % pprint.pformat(failed)) |
Roshan Pius | 58916a3 | 2016-06-16 16:26:44 -0700 | [diff] [blame] | 515 | |
| 516 | @signals.generated_test |
| 517 | def test_passpoint_connect_config_store(self): |
| 518 | """Test connecting to enterprise networks of different authentication |
| 519 | types with passpoint support after wifi toggle. |
| 520 | |
| 521 | The authentication types tested are: |
| 522 | EAP-TLS |
| 523 | EAP-TTLS with MSCHAPV2 as phase2. |
| 524 | |
| 525 | Procedures: |
| 526 | For each enterprise wifi network |
| 527 | 1. Connect to the network. |
| 528 | 2. Send a GET request to a website and check response. |
| 529 | 3. Toggle wifi. |
| 530 | 4. Ensure that the device reconnects to the same network. |
| 531 | |
| 532 | Expect: |
| 533 | Successful connection and Internet access through the enterprise |
| 534 | networks with passpoint support. |
| 535 | """ |
| 536 | asserts.skip_if(not self.dut.droid.wifiIsPasspointSupported(), |
| 537 | "Passpoint is not supported on device %s" % |
| 538 | self.dut.model) |
| 539 | passpoint_configs = self.gen_passpoint_configs() |
| 540 | self.log.info("Testing %d different configs.", len(passpoint_configs)) |
| 541 | random.shuffle(passpoint_configs) |
| 542 | failed = self.run_generated_testcases( |
| 543 | self.eap_connect_toggle_wifi, |
| 544 | passpoint_configs, |
| 545 | args=(self.dut, ), |
| 546 | name_func=self.gen_passpoint_test_name_for_config_store) |
| 547 | asserts.assert_equal( |
| 548 | len(failed), 0, |
| 549 | "The following configs failed passpoint connect test: %s" % |
| 550 | pprint.pformat(failed)) |