blob: 24b62ddec811698e3bc8366bfb09246e2727829d [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 """
32 def setup_class(self):
33 super().setup_class()
34 dut = self.user_params.get('dut', None)
35 if dut:
36 if dut == 'fuchsia_devices':
37 self.dut = create_wlan_device(self.fuchsia_devices[0])
38 elif dut == 'android_devices':
39 self.dut = create_wlan_device(self.android_devices[0])
40 else:
41 raise ValueError('Invalid DUT specified in config. (%s)' %
42 self.user_params['dut'])
43 else:
44 # Default is an Fuchsia device
45 self.dut = create_wlan_device(self.fuchsia_devices[0])
46 self.access_point = self.access_points[0]
47
48 def teardown_class(self):
49 self.dut.disconnect()
50 self.access_point.stop_all_aps()
51
52 def setup_test(self):
53 self.dut.disconnect()
54 self.access_point.stop_all_aps()
55
56 def on_fail(self, test_name, begin_time):
57 super().on_fail(test_name, begin_time)
58 self.access_point.stop_all_aps()
59
60 def on_exception(self, test_name, begin_time):
61 super().on_exception(test_name, begin_time)
62 self.dut.disconnect()
63 self.access_point.stop_all_aps()
64
65 def test_connect_to_wpa2_after_wpa3_rejection(self):
66 """Test association to non-WPA3 network after receiving a WPA3
67 rejection, which was triggering a firmware hang.
68
69 Bug: https://bugs.fuchsia.dev/p/fuchsia/issues/detail?id=71233
70 """
71 # Setup a WPA3 network
72 wpa3_ssid = utils.rand_ascii_str(hostapd_constants.AP_SSID_LENGTH_5G)
73 setup_ap(access_point=self.access_point,
74 profile_name='whirlwind',
75 channel=hostapd_constants.AP_DEFAULT_CHANNEL_5G,
76 ssid=wpa3_ssid,
77 security=Security(security_mode='wpa3',
78 password=generate_random_password('wpa3')))
79 # Attempt to associate with wrong password, expecting failure
80 self.log.info('Attempting to associate WPA3 with wrong password.')
81 asserts.assert_false(
82 self.dut.associate(wpa3_ssid,
83 target_pwd='wrongpass',
84 target_security='wpa3'),
85 'Associated with WPA3 network using the wrong password')
86
87 self.access_point.stop_all_aps()
88
89 # Setup a WPA2 Network
90 wpa2_ssid = utils.rand_ascii_str(hostapd_constants.AP_SSID_LENGTH_5G)
91 wpa2_password = generate_random_password('wpa2')
92 setup_ap(access_point=self.access_point,
93 profile_name='whirlwind',
94 channel=hostapd_constants.AP_DEFAULT_CHANNEL_5G,
95 ssid=wpa2_ssid,
96 security=Security(security_mode='wpa2',
97 password=wpa2_password))
98
99 # Attempt to associate, expecting success
100 self.log.info('Attempting to associate with WPA2 network.')
101 asserts.assert_true(
102 self.dut.associate(wpa2_ssid,
103 target_pwd=wpa2_password,
104 target_security='wpa2'),
105 'Failed to associate with WPA2 network after a WPA3 rejection.')