blob: 950015daef9109697d12a17b3377824c629d2e17 [file] [log] [blame]
Hayden Nix34acfc82021-03-02 23:36:51 +00001#!/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
17from acts import asserts
18from acts import utils
19from acts.controllers.access_point import setup_ap
20from acts.controllers.ap_lib import hostapd_constants
21from acts.controllers.ap_lib.hostapd_utils import generate_random_password
22from acts.controllers.ap_lib.hostapd_security import Security
23from acts_contrib.test_utils.abstract_devices.wlan_device import create_wlan_device
24from acts_contrib.test_utils.abstract_devices.wlan_device_lib.AbstractDeviceWlanDeviceBaseTest import AbstractDeviceWlanDeviceBaseTest
25
26
27class 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 Balanac7d93052021-09-23 15:00:28 -070032
Hayden Nix34acfc82021-03-02 23:36:51 +000033 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 Luc6b1d872022-01-06 23:49:12 +000053 def teardown_test(self):
Hayden Nix34acfc82021-03-02 23:36:51 +000054 self.dut.disconnect()
Patrick Luc6b1d872022-01-06 23:49:12 +000055 self.download_ap_logs()
Hayden Nix34acfc82021-03-02 23:36:51 +000056 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.')