blob: 7542ee9bdf57826729ccf1dca98469e6f550c94c [file] [log] [blame]
Girish Moturu7e48b432019-07-11 14:52:13 -07001#
2# Copyright 2019 - The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16import time
17
18from acts import asserts
jerrypcchen1d148642021-07-21 10:39:35 +000019from acts.controllers.openwrt_ap import MOBLY_CONTROLLER_CONFIG_NAME as OPENWRT
Girish Moturu7e48b432019-07-11 14:52:13 -070020from acts import base_test
Girish Moturu7e48b432019-07-11 14:52:13 -070021from acts.test_decorators import test_tracker_info
Xianyuan Jia63751fb2020-11-17 00:07:40 +000022from acts_contrib.test_utils.net import connectivity_const as cconst
23from acts_contrib.test_utils.net import connectivity_test_utils as cutils
24from acts_contrib.test_utils.net import ui_utils as uutils
25from acts_contrib.test_utils.wifi import wifi_test_utils as wutils
26from acts_contrib.test_utils.wifi.WifiBaseTest import WifiBaseTest
Girish Moturu7e48b432019-07-11 14:52:13 -070027
28WifiEnums = wutils.WifiEnums
29IFACE = "InterfaceName"
30TIME_OUT = 20
31WLAN = "wlan0"
Girish Moturu267f71e2020-05-16 22:51:03 -070032ACCEPT_CONTINUE = "Accept and Continue"
Girish Moturu572d5212021-01-08 10:48:17 -080033CONNECTED = "Connected"
34SIGN_IN_NOTIFICATION = "Sign in to network"
Girish Moturu7e48b432019-07-11 14:52:13 -070035
36
jerrypcchen1d148642021-07-21 10:39:35 +000037class CaptivePortalTest(WifiBaseTest):
38 """Check device can access the network after pass captive portal check."""
Girish Moturu7e48b432019-07-11 14:52:13 -070039
40 def setup_class(self):
Girish Moturu3a8de0d2019-12-06 13:00:33 -080041 """Setup devices for tests and unpack params.
Girish Moturu7e48b432019-07-11 14:52:13 -070042
43 Required params:
44 1. rk_captive_portal: SSID of ruckus captive portal network in dict
45 2. gg_captive_portal: SSID of guestgate network in dict
46 3. uicd_workflows: uicd workflow that specify click actions to accept
47 a captive portal connection. Ex: Click on SignIn, Accept & Continue
48 //wireless/android/platform/testing/wifi/configs/uicd/
49 4. uic_zip: Zip file location of UICD application
50 """
51 self.dut = self.android_devices[0]
jerrypcchen1d148642021-07-21 10:39:35 +000052 opt_params = ["rk_captive_portal", "gg_captive_portal",
53 "configure_OpenWrt", "wifi_network"]
54 self.unpack_userparams(opt_param_names=opt_params,)
Girish Moturu267f71e2020-05-16 22:51:03 -070055 wutils.wifi_test_device_init(self.dut)
Girish Moturu7e48b432019-07-11 14:52:13 -070056
jerrypcchen1d148642021-07-21 10:39:35 +000057 if OPENWRT in self.user_params:
58 self.openwrt = self.access_points[0]
59 if hasattr(self, "configure_OpenWrt") and self.configure_OpenWrt == "skip":
60 self.dut.log.info("Skip configure Wifi interface due to config setup.")
61 else:
62 self.configure_openwrt_ap_and_start(wpa_network=True)
63 self.wifi_network = self.openwrt.get_wifi_network()
64 self.openwrt.network_setting.setup_captive_portal()
65
Girish Moturu7e48b432019-07-11 14:52:13 -070066 def teardown_class(self):
Girish Moturu3a8de0d2019-12-06 13:00:33 -080067 """Reset devices."""
Girish Moturu7e48b432019-07-11 14:52:13 -070068 cutils.set_private_dns(self.dut, cconst.PRIVATE_DNS_MODE_OPPORTUNISTIC)
Girish Moturu267f71e2020-05-16 22:51:03 -070069 wutils.reset_wifi(self.dut)
70 self.dut.droid.telephonyToggleDataConnection(True)
Girish Moturu7e48b432019-07-11 14:52:13 -070071
72 def setup_test(self):
Girish Moturu3a8de0d2019-12-06 13:00:33 -080073 """Setup device."""
Girish Moturu7e48b432019-07-11 14:52:13 -070074 wutils.reset_wifi(self.dut)
Girish Moturu267f71e2020-05-16 22:51:03 -070075 self.dut.unlock_screen()
76 self._go_to_wifi_settings()
Girish Moturu7e48b432019-07-11 14:52:13 -070077
78 def on_fail(self, test_name, begin_time):
79 self.dut.take_bug_report(test_name, begin_time)
80
81 ### Helper methods ###
82
Girish Moturu267f71e2020-05-16 22:51:03 -070083 def _go_to_wifi_settings(self):
84 """Go to wifi settings to perform UI actions for Captive portal."""
85 self.dut.adb.shell("am start -a android.settings.SETTINGS")
86 asserts.assert_true(
87 uutils.has_element(self.dut, text="Network & internet"),
88 "Failed to find 'Network & internet' icon")
89 uutils.wait_and_click(self.dut, text="Network & internet")
jerrypcchen1d148642021-07-21 10:39:35 +000090 uutils.wait_and_click(self.dut, text="Internet")
Girish Moturu267f71e2020-05-16 22:51:03 -070091
Girish Moturu572d5212021-01-08 10:48:17 -080092 def _verify_sign_in_notification(self):
93 """Verify sign in notification shows for captive portal."""
94 curr_time = time.time()
95 while time.time() < curr_time + TIME_OUT:
Girish Moturue648b6a2021-03-04 13:52:15 -080096 time.sleep(3) # wait for sometime before checking the notification
Girish Moturu572d5212021-01-08 10:48:17 -080097 screen_dump = uutils.get_screen_dump_xml(self.dut)
98 nodes = screen_dump.getElementsByTagName('node')
99 for node in nodes:
100 if SIGN_IN_NOTIFICATION in node.getAttribute(
101 'text') or CONNECTED in node.getAttribute('text'):
102 return
Girish Moturu572d5212021-01-08 10:48:17 -0800103 asserts.fail("Failed to get sign in notification")
104
Girish Moturu267f71e2020-05-16 22:51:03 -0700105 def _verify_captive_portal(self, network, click_accept=ACCEPT_CONTINUE):
Girish Moturu3a8de0d2019-12-06 13:00:33 -0800106 """Connect to captive portal network using uicd workflow.
Girish Moturu7e48b432019-07-11 14:52:13 -0700107
108 Steps:
109 1. Connect to captive portal network
110 2. Run uicd workflow to accept connection
111 3. Verify internet connectivity
112
113 Args:
Girish Moturu3a8de0d2019-12-06 13:00:33 -0800114 network: captive portal network to connect to
Girish Moturu267f71e2020-05-16 22:51:03 -0700115 click_accept: Notification to select to accept captive portal
Girish Moturu7e48b432019-07-11 14:52:13 -0700116 """
117 # connect to captive portal wifi network
Girish Moturu267f71e2020-05-16 22:51:03 -0700118 wutils.connect_to_wifi_network(
119 self.dut, network, check_connectivity=False)
Girish Moturu7e48b432019-07-11 14:52:13 -0700120
Girish Moturu267f71e2020-05-16 22:51:03 -0700121 # run ui automator
Girish Moturu572d5212021-01-08 10:48:17 -0800122 self._verify_sign_in_notification()
Girish Moturu267f71e2020-05-16 22:51:03 -0700123 uutils.wait_and_click(self.dut, text="%s" % network["SSID"])
124 if uutils.has_element(self.dut, text="%s" % click_accept):
125 uutils.wait_and_click(self.dut, text="%s" % click_accept)
Girish Moturu7e48b432019-07-11 14:52:13 -0700126
127 # wait for sometime for captive portal connection to go through
128 curr_time = time.time()
129 while time.time() < curr_time + TIME_OUT:
Girish Moturue648b6a2021-03-04 13:52:15 -0800130 time.sleep(3) # wait for sometime for AP to send DHCP info
Girish Moturu7e48b432019-07-11 14:52:13 -0700131 link_prop = self.dut.droid.connectivityGetActiveLinkProperties()
132 self.log.debug("Link properties %s" % link_prop)
133 if link_prop and link_prop[IFACE] == WLAN:
134 break
Girish Moturu7e48b432019-07-11 14:52:13 -0700135
136 # verify connectivity
Girish Moturu267f71e2020-05-16 22:51:03 -0700137 asserts.assert_true(
138 wutils.validate_connection(self.dut, ping_gateway=False),
139 "Failed to connect to internet. Captive portal test failed")
Girish Moturu7e48b432019-07-11 14:52:13 -0700140
141 ### Test Cases ###
142
143 @test_tracker_info(uuid="b035b4f9-40f7-42f6-9941-ec27afe15040")
Girish Moturu3a8de0d2019-12-06 13:00:33 -0800144 @WifiBaseTest.wifi_test_wrap
Girish Moturu7e48b432019-07-11 14:52:13 -0700145 def test_ruckus_captive_portal_default(self):
Girish Moturu3a8de0d2019-12-06 13:00:33 -0800146 """Verify captive portal network.
Girish Moturu7e48b432019-07-11 14:52:13 -0700147
148 Steps:
149 1. Set default private dns mode
150 2. Connect to ruckus captive portal network
151 3. Verify connectivity
152 """
153 # set private dns to opportunistic
154 cutils.set_private_dns(self.dut, cconst.PRIVATE_DNS_MODE_OPPORTUNISTIC)
155
156 # verify connection to captive portal network
Girish Moturu267f71e2020-05-16 22:51:03 -0700157 self._verify_captive_portal(self.rk_captive_portal)
Girish Moturu7e48b432019-07-11 14:52:13 -0700158
159 @test_tracker_info(uuid="8ea18d80-0170-41b1-8945-fe14bcd4feab")
Girish Moturu3a8de0d2019-12-06 13:00:33 -0800160 @WifiBaseTest.wifi_test_wrap
Girish Moturu7e48b432019-07-11 14:52:13 -0700161 def test_ruckus_captive_portal_private_dns_off(self):
Girish Moturu3a8de0d2019-12-06 13:00:33 -0800162 """Verify captive portal network.
Girish Moturu7e48b432019-07-11 14:52:13 -0700163
164 Steps:
165 1. Turn off private dns mode
166 2. Connect to ruckus captive portal network
167 3. Verify connectivity
168 """
169 # turn off private dns
170 cutils.set_private_dns(self.dut, cconst.PRIVATE_DNS_MODE_OFF)
171
172 # verify connection to captive portal network
Girish Moturu267f71e2020-05-16 22:51:03 -0700173 self._verify_captive_portal(self.rk_captive_portal)
Girish Moturu7e48b432019-07-11 14:52:13 -0700174
175 @test_tracker_info(uuid="e8e05907-55f7-40e5-850c-b3111ceb31a4")
Girish Moturu3a8de0d2019-12-06 13:00:33 -0800176 @WifiBaseTest.wifi_test_wrap
Girish Moturu7e48b432019-07-11 14:52:13 -0700177 def test_ruckus_captive_portal_private_dns_strict(self):
Girish Moturu3a8de0d2019-12-06 13:00:33 -0800178 """Verify captive portal network.
Girish Moturu7e48b432019-07-11 14:52:13 -0700179
180 Steps:
181 1. Set strict private dns mode
182 2. Connect to ruckus captive portal network
183 3. Verify connectivity
184 """
185 # set private dns to strict mode
186 cutils.set_private_dns(self.dut,
187 cconst.PRIVATE_DNS_MODE_STRICT,
188 cconst.DNS_GOOGLE)
189
190 # verify connection to captive portal network
Girish Moturu267f71e2020-05-16 22:51:03 -0700191 self._verify_captive_portal(self.rk_captive_portal)
Girish Moturu7e48b432019-07-11 14:52:13 -0700192
193 @test_tracker_info(uuid="76e49800-f141-4fd2-9969-562585eb1e7a")
194 def test_guestgate_captive_portal_default(self):
Girish Moturu3a8de0d2019-12-06 13:00:33 -0800195 """Verify captive portal network.
Girish Moturu7e48b432019-07-11 14:52:13 -0700196
197 Steps:
198 1. Set default private dns mode
199 2. Connect to guestgate captive portal network
200 3. Verify connectivity
201 """
202 # set private dns to opportunistic
203 cutils.set_private_dns(self.dut, cconst.PRIVATE_DNS_MODE_OPPORTUNISTIC)
204
205 # verify connection to captive portal network
Girish Moturu267f71e2020-05-16 22:51:03 -0700206 self._verify_captive_portal(self.gg_captive_portal)
Girish Moturu7e48b432019-07-11 14:52:13 -0700207
208 @test_tracker_info(uuid="0aea0cac-0f42-406b-84ba-62c1ef74adfc")
209 def test_guestgate_captive_portal_private_dns_off(self):
Girish Moturu3a8de0d2019-12-06 13:00:33 -0800210 """Verify captive portal network.
Girish Moturu7e48b432019-07-11 14:52:13 -0700211
212 Steps:
213 1. Turn off private dns mode
214 2. Connect to guestgate captive portal network
215 3. Verify connectivity
216 """
217 # turn off private dns
218 cutils.set_private_dns(self.dut, cconst.PRIVATE_DNS_MODE_OFF)
219
220 # verify connection to captive portal network
Girish Moturu267f71e2020-05-16 22:51:03 -0700221 self._verify_captive_portal(self.gg_captive_portal)
Girish Moturu7e48b432019-07-11 14:52:13 -0700222
223 @test_tracker_info(uuid="39124dcc-2fd3-4d33-b129-a1c8150b7f2a")
224 def test_guestgate_captive_portal_private_dns_strict(self):
Girish Moturu3a8de0d2019-12-06 13:00:33 -0800225 """Verify captive portal network.
Girish Moturu7e48b432019-07-11 14:52:13 -0700226
227 Steps:
228 1. Set strict private dns mode
229 2. Connect to guestgate captive portal network
230 3. Verify connectivity
231 """
232 # set private dns to strict mode
233 cutils.set_private_dns(self.dut,
234 cconst.PRIVATE_DNS_MODE_STRICT,
235 cconst.DNS_GOOGLE)
236
237 # verify connection to captive portal network
Girish Moturu267f71e2020-05-16 22:51:03 -0700238 self._verify_captive_portal(self.gg_captive_portal)
jerrypcchen1d148642021-07-21 10:39:35 +0000239
240 @test_tracker_info(uuid="c25a1be7-f202-41c4-ac95-bed1720833ab")
241 def test_openwrt_captive_portal_default(self):
242 """Verify captive portal network.
243
244 Steps:
245 1. Set default private dns mode
246 2. Connect to openwrt captive portal network
247 3. Verify connectivity
248 """
249 cutils.set_private_dns(self.dut, cconst.PRIVATE_DNS_MODE_OPPORTUNISTIC)
250 self.openwrt.network_setting.service_manager.restart("nodogsplash")
251 self._verify_captive_portal(self.wifi_network, click_accept="Continue")
252
253 @test_tracker_info(uuid="1419e36d-0303-44ba-bc60-4d707b45ef48")
254 def test_openwrt_captive_portal_private_dns_off(self):
255 """Verify captive portal network.
256
257 Steps:
258 1. Turn off private dns mode
259 2. Connect to openwrt captive portal network
260 3. Verify connectivity
261 """
262 cutils.set_private_dns(self.dut, cconst.PRIVATE_DNS_MODE_OFF)
263 self.openwrt.network_setting.service_manager.restart("nodogsplash")
264 self._verify_captive_portal(self.wifi_network, click_accept="Continue")
265
266 @test_tracker_info(uuid="5aae44ee-fa62-47b9-9b3d-8121f9f92da1")
267 def test_openwrt_captive_portal_private_dns_strict(self):
268 """Verify captive portal network.
269
270 Steps:
271 1. Set strict private dns mode
272 2. Connect to openwrt captive portal network
273 3. Verify connectivity
274 """
275 cutils.set_private_dns(self.dut,
276 cconst.PRIVATE_DNS_MODE_STRICT,
277 cconst.DNS_GOOGLE)
278 self.openwrt.network_setting.service_manager.restart("nodogsplash")
279 self._verify_captive_portal(self.wifi_network, click_accept="Continue")