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 | |
Patrick Lu | c6b1d87 | 2022-01-06 23:49:12 +0000 | [diff] [blame] | 53 | def teardown_test(self): |
Hayden Nix | 34acfc8 | 2021-03-02 23:36:51 +0000 | [diff] [blame] | 54 | self.dut.disconnect() |
Patrick Lu | c6b1d87 | 2022-01-06 23:49:12 +0000 | [diff] [blame] | 55 | self.download_ap_logs() |
Hayden Nix | 34acfc8 | 2021-03-02 23:36:51 +0000 | [diff] [blame] | 56 | self.access_point.stop_all_aps() |
| 57 | |
| 58 | def on_fail(self, test_name, begin_time): |
| 59 | super().on_fail(test_name, begin_time) |
| 60 | self.access_point.stop_all_aps() |
| 61 | |
| 62 | def on_exception(self, test_name, begin_time): |
| 63 | super().on_exception(test_name, begin_time) |
| 64 | self.dut.disconnect() |
| 65 | self.access_point.stop_all_aps() |
| 66 | |
| 67 | def test_connect_to_wpa2_after_wpa3_rejection(self): |
| 68 | """Test association to non-WPA3 network after receiving a WPA3 |
| 69 | rejection, which was triggering a firmware hang. |
| 70 | |
| 71 | Bug: https://bugs.fuchsia.dev/p/fuchsia/issues/detail?id=71233 |
| 72 | """ |
| 73 | # Setup a WPA3 network |
| 74 | wpa3_ssid = utils.rand_ascii_str(hostapd_constants.AP_SSID_LENGTH_5G) |
| 75 | setup_ap(access_point=self.access_point, |
| 76 | profile_name='whirlwind', |
| 77 | channel=hostapd_constants.AP_DEFAULT_CHANNEL_5G, |
| 78 | ssid=wpa3_ssid, |
| 79 | security=Security(security_mode='wpa3', |
| 80 | password=generate_random_password('wpa3'))) |
| 81 | # Attempt to associate with wrong password, expecting failure |
| 82 | self.log.info('Attempting to associate WPA3 with wrong password.') |
| 83 | asserts.assert_false( |
| 84 | self.dut.associate(wpa3_ssid, |
| 85 | target_pwd='wrongpass', |
| 86 | target_security='wpa3'), |
| 87 | 'Associated with WPA3 network using the wrong password') |
| 88 | |
| 89 | self.access_point.stop_all_aps() |
| 90 | |
| 91 | # Setup a WPA2 Network |
| 92 | wpa2_ssid = utils.rand_ascii_str(hostapd_constants.AP_SSID_LENGTH_5G) |
| 93 | wpa2_password = generate_random_password('wpa2') |
| 94 | setup_ap(access_point=self.access_point, |
| 95 | profile_name='whirlwind', |
| 96 | channel=hostapd_constants.AP_DEFAULT_CHANNEL_5G, |
| 97 | ssid=wpa2_ssid, |
| 98 | security=Security(security_mode='wpa2', |
| 99 | password=wpa2_password)) |
| 100 | |
| 101 | # Attempt to associate, expecting success |
| 102 | self.log.info('Attempting to associate with WPA2 network.') |
| 103 | asserts.assert_true( |
| 104 | self.dut.associate(wpa2_ssid, |
| 105 | target_pwd=wpa2_password, |
| 106 | target_security='wpa2'), |
| 107 | 'Failed to associate with WPA2 network after a WPA3 rejection.') |