Hayden Nix | 34acfc8 | 2021-03-02 23:36:51 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # |
| 3 | # Copyright 2021 - The Android secure Source Project |
| 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 | from acts import asserts |
| 18 | from acts import utils |
| 19 | from acts.controllers.access_point import setup_ap |
| 20 | from acts.controllers.ap_lib import hostapd_constants |
| 21 | from acts.controllers.ap_lib.hostapd_utils import generate_random_password |
| 22 | from acts.controllers.ap_lib.hostapd_security import Security |
| 23 | from acts_contrib.test_utils.abstract_devices.wlan_device import create_wlan_device |
| 24 | from acts_contrib.test_utils.abstract_devices.wlan_device_lib.AbstractDeviceWlanDeviceBaseTest import AbstractDeviceWlanDeviceBaseTest |
| 25 | |
| 26 | |
| 27 | class WlanMiscScenarioTest(AbstractDeviceWlanDeviceBaseTest): |
| 28 | """Random scenario tests, usually to reproduce certain bugs, that do not |
| 29 | fit into a specific test category, but should still be run in CI to catch |
| 30 | regressions. |
| 31 | """ |
Sam Balana | c7d9305 | 2021-09-23 15:00:28 -0700 | [diff] [blame^] | 32 | |
Hayden Nix | 34acfc8 | 2021-03-02 23:36:51 +0000 | [diff] [blame] | 33 | def setup_class(self): |
| 34 | super().setup_class() |
| 35 | dut = self.user_params.get('dut', None) |
| 36 | if dut: |
| 37 | if dut == 'fuchsia_devices': |
| 38 | self.dut = create_wlan_device(self.fuchsia_devices[0]) |
| 39 | elif dut == 'android_devices': |
| 40 | self.dut = create_wlan_device(self.android_devices[0]) |
| 41 | else: |
| 42 | raise ValueError('Invalid DUT specified in config. (%s)' % |
| 43 | self.user_params['dut']) |
| 44 | else: |
| 45 | # Default is an Fuchsia device |
| 46 | self.dut = create_wlan_device(self.fuchsia_devices[0]) |
| 47 | self.access_point = self.access_points[0] |
| 48 | |
| 49 | def teardown_class(self): |
| 50 | self.dut.disconnect() |
| 51 | self.access_point.stop_all_aps() |
| 52 | |
| 53 | def setup_test(self): |
| 54 | self.dut.disconnect() |
| 55 | self.access_point.stop_all_aps() |
| 56 | |
| 57 | def on_fail(self, test_name, begin_time): |
| 58 | super().on_fail(test_name, begin_time) |
| 59 | self.access_point.stop_all_aps() |
| 60 | |
| 61 | def on_exception(self, test_name, begin_time): |
| 62 | super().on_exception(test_name, begin_time) |
| 63 | self.dut.disconnect() |
| 64 | self.access_point.stop_all_aps() |
| 65 | |
| 66 | def test_connect_to_wpa2_after_wpa3_rejection(self): |
| 67 | """Test association to non-WPA3 network after receiving a WPA3 |
| 68 | rejection, which was triggering a firmware hang. |
| 69 | |
| 70 | Bug: https://bugs.fuchsia.dev/p/fuchsia/issues/detail?id=71233 |
| 71 | """ |
| 72 | # Setup a WPA3 network |
| 73 | wpa3_ssid = utils.rand_ascii_str(hostapd_constants.AP_SSID_LENGTH_5G) |
| 74 | setup_ap(access_point=self.access_point, |
| 75 | profile_name='whirlwind', |
| 76 | channel=hostapd_constants.AP_DEFAULT_CHANNEL_5G, |
| 77 | ssid=wpa3_ssid, |
| 78 | security=Security(security_mode='wpa3', |
| 79 | password=generate_random_password('wpa3'))) |
| 80 | # Attempt to associate with wrong password, expecting failure |
| 81 | self.log.info('Attempting to associate WPA3 with wrong password.') |
| 82 | asserts.assert_false( |
| 83 | self.dut.associate(wpa3_ssid, |
| 84 | target_pwd='wrongpass', |
| 85 | target_security='wpa3'), |
| 86 | 'Associated with WPA3 network using the wrong password') |
| 87 | |
| 88 | self.access_point.stop_all_aps() |
| 89 | |
| 90 | # Setup a WPA2 Network |
| 91 | wpa2_ssid = utils.rand_ascii_str(hostapd_constants.AP_SSID_LENGTH_5G) |
| 92 | wpa2_password = generate_random_password('wpa2') |
| 93 | setup_ap(access_point=self.access_point, |
| 94 | profile_name='whirlwind', |
| 95 | channel=hostapd_constants.AP_DEFAULT_CHANNEL_5G, |
| 96 | ssid=wpa2_ssid, |
| 97 | security=Security(security_mode='wpa2', |
| 98 | password=wpa2_password)) |
| 99 | |
| 100 | # Attempt to associate, expecting success |
| 101 | self.log.info('Attempting to associate with WPA2 network.') |
| 102 | asserts.assert_true( |
| 103 | self.dut.associate(wpa2_ssid, |
| 104 | target_pwd=wpa2_password, |
| 105 | target_security='wpa2'), |
| 106 | 'Failed to associate with WPA2 network after a WPA3 rejection.') |