blob: 0611640b13d6d1f1704ac7938d03b90ba0ca9203 [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
19from acts import base_test
Girish Moturu7e48b432019-07-11 14:52:13 -070020from acts.libs.uicd.uicd_cli import UicdCli
21from acts.test_decorators import test_tracker_info
22from acts.test_utils.net import connectivity_const as cconst
23from acts.test_utils.net import connectivity_test_utils as cutils
24from acts.test_utils.wifi import wifi_test_utils as wutils
Girish Moturu3a8de0d2019-12-06 13:00:33 -080025from acts.test_utils.wifi.WifiBaseTest import WifiBaseTest
Girish Moturu7e48b432019-07-11 14:52:13 -070026
27WifiEnums = wutils.WifiEnums
28IFACE = "InterfaceName"
29TIME_OUT = 20
30WLAN = "wlan0"
31
32
33class CaptivePortalTest(base_test.BaseTestClass):
Girish Moturu3a8de0d2019-12-06 13:00:33 -080034 """Tests for Captive portal."""
Girish Moturu7e48b432019-07-11 14:52:13 -070035
36 def setup_class(self):
Girish Moturu3a8de0d2019-12-06 13:00:33 -080037 """Setup devices for tests and unpack params.
Girish Moturu7e48b432019-07-11 14:52:13 -070038
39 Required params:
40 1. rk_captive_portal: SSID of ruckus captive portal network in dict
41 2. gg_captive_portal: SSID of guestgate network in dict
42 3. uicd_workflows: uicd workflow that specify click actions to accept
43 a captive portal connection. Ex: Click on SignIn, Accept & Continue
44 //wireless/android/platform/testing/wifi/configs/uicd/
45 4. uic_zip: Zip file location of UICD application
46 """
47 self.dut = self.android_devices[0]
48 wutils.wifi_test_device_init(self.dut)
49 wutils.wifi_toggle_state(self.dut, True)
50 req_params = ["rk_captive_portal",
51 "gg_captive_portal",
52 "uicd_workflows",
53 "uicd_zip"]
54 self.unpack_userparams(req_param_names=req_params,)
55 self.ui = UicdCli(self.uicd_zip, self.uicd_workflows)
56 self.rk_workflow_config = "rk_captive_portal_%s" % self.dut.model
57 self.gg_workflow_config = "gg_captive_portal_%s" % self.dut.model
58
59 def teardown_class(self):
Girish Moturu3a8de0d2019-12-06 13:00:33 -080060 """Reset devices."""
Girish Moturu7e48b432019-07-11 14:52:13 -070061 cutils.set_private_dns(self.dut, cconst.PRIVATE_DNS_MODE_OPPORTUNISTIC)
62
63 def setup_test(self):
Girish Moturu3a8de0d2019-12-06 13:00:33 -080064 """Setup device."""
Girish Moturu7e48b432019-07-11 14:52:13 -070065 self.dut.unlock_screen()
66
67 def teardown_test(self):
Girish Moturu3a8de0d2019-12-06 13:00:33 -080068 """Reset to default state after each test."""
Girish Moturu7e48b432019-07-11 14:52:13 -070069 wutils.reset_wifi(self.dut)
70
71 def on_fail(self, test_name, begin_time):
72 self.dut.take_bug_report(test_name, begin_time)
73
74 ### Helper methods ###
75
76 def _verify_captive_portal(self, network, uicd_workflow):
Girish Moturu3a8de0d2019-12-06 13:00:33 -080077 """Connect to captive portal network using uicd workflow.
Girish Moturu7e48b432019-07-11 14:52:13 -070078
79 Steps:
80 1. Connect to captive portal network
81 2. Run uicd workflow to accept connection
82 3. Verify internet connectivity
83
84 Args:
Girish Moturu3a8de0d2019-12-06 13:00:33 -080085 network: captive portal network to connect to
86 uicd_workflow: ui workflow to accept captive portal conn
Girish Moturu7e48b432019-07-11 14:52:13 -070087 """
88 # connect to captive portal wifi network
89 wutils.start_wifi_connection_scan_and_ensure_network_found(
90 self.dut, network[WifiEnums.SSID_KEY])
91 wutils.wifi_connect(self.dut, network, check_connectivity=False)
92
93 # run uicd
94 self.ui.run(self.dut.serial, uicd_workflow)
95
96 # wait for sometime for captive portal connection to go through
97 curr_time = time.time()
98 while time.time() < curr_time + TIME_OUT:
99 link_prop = self.dut.droid.connectivityGetActiveLinkProperties()
100 self.log.debug("Link properties %s" % link_prop)
101 if link_prop and link_prop[IFACE] == WLAN:
102 break
103 time.sleep(2)
104
105 # verify connectivity
Girish Moturu3a8de0d2019-12-06 13:00:33 -0800106 try:
107 asserts.assert_true(wutils.validate_connection(self.dut),
108 "Failed to verify internet connectivity")
109 except Exception as e:
110 asserts.fail("Failed to connect to captive portal: %s" % e)
Girish Moturu7e48b432019-07-11 14:52:13 -0700111
112 ### Test Cases ###
113
114 @test_tracker_info(uuid="b035b4f9-40f7-42f6-9941-ec27afe15040")
Girish Moturu3a8de0d2019-12-06 13:00:33 -0800115 @WifiBaseTest.wifi_test_wrap
Girish Moturu7e48b432019-07-11 14:52:13 -0700116 def test_ruckus_captive_portal_default(self):
Girish Moturu3a8de0d2019-12-06 13:00:33 -0800117 """Verify captive portal network.
Girish Moturu7e48b432019-07-11 14:52:13 -0700118
119 Steps:
120 1. Set default private dns mode
121 2. Connect to ruckus captive portal network
122 3. Verify connectivity
123 """
124 # set private dns to opportunistic
125 cutils.set_private_dns(self.dut, cconst.PRIVATE_DNS_MODE_OPPORTUNISTIC)
126
127 # verify connection to captive portal network
128 self._verify_captive_portal(self.rk_captive_portal,
129 self.rk_workflow_config)
130
131 @test_tracker_info(uuid="8ea18d80-0170-41b1-8945-fe14bcd4feab")
Girish Moturu3a8de0d2019-12-06 13:00:33 -0800132 @WifiBaseTest.wifi_test_wrap
Girish Moturu7e48b432019-07-11 14:52:13 -0700133 def test_ruckus_captive_portal_private_dns_off(self):
Girish Moturu3a8de0d2019-12-06 13:00:33 -0800134 """Verify captive portal network.
Girish Moturu7e48b432019-07-11 14:52:13 -0700135
136 Steps:
137 1. Turn off private dns mode
138 2. Connect to ruckus captive portal network
139 3. Verify connectivity
140 """
141 # turn off private dns
142 cutils.set_private_dns(self.dut, cconst.PRIVATE_DNS_MODE_OFF)
143
144 # verify connection to captive portal network
145 self._verify_captive_portal(self.rk_captive_portal,
146 self.rk_workflow_config)
147
148 @test_tracker_info(uuid="e8e05907-55f7-40e5-850c-b3111ceb31a4")
Girish Moturu3a8de0d2019-12-06 13:00:33 -0800149 @WifiBaseTest.wifi_test_wrap
Girish Moturu7e48b432019-07-11 14:52:13 -0700150 def test_ruckus_captive_portal_private_dns_strict(self):
Girish Moturu3a8de0d2019-12-06 13:00:33 -0800151 """Verify captive portal network.
Girish Moturu7e48b432019-07-11 14:52:13 -0700152
153 Steps:
154 1. Set strict private dns mode
155 2. Connect to ruckus captive portal network
156 3. Verify connectivity
157 """
158 # set private dns to strict mode
159 cutils.set_private_dns(self.dut,
160 cconst.PRIVATE_DNS_MODE_STRICT,
161 cconst.DNS_GOOGLE)
162
163 # verify connection to captive portal network
164 self._verify_captive_portal(self.rk_captive_portal,
165 self.rk_workflow_config)
166
167 @test_tracker_info(uuid="76e49800-f141-4fd2-9969-562585eb1e7a")
168 def test_guestgate_captive_portal_default(self):
Girish Moturu3a8de0d2019-12-06 13:00:33 -0800169 """Verify captive portal network.
Girish Moturu7e48b432019-07-11 14:52:13 -0700170
171 Steps:
172 1. Set default private dns mode
173 2. Connect to guestgate captive portal network
174 3. Verify connectivity
175 """
176 # set private dns to opportunistic
177 cutils.set_private_dns(self.dut, cconst.PRIVATE_DNS_MODE_OPPORTUNISTIC)
178
179 # verify connection to captive portal network
180 self._verify_captive_portal(self.gg_captive_portal, "gg_captive_portal")
181
182 @test_tracker_info(uuid="0aea0cac-0f42-406b-84ba-62c1ef74adfc")
183 def test_guestgate_captive_portal_private_dns_off(self):
Girish Moturu3a8de0d2019-12-06 13:00:33 -0800184 """Verify captive portal network.
Girish Moturu7e48b432019-07-11 14:52:13 -0700185
186 Steps:
187 1. Turn off private dns mode
188 2. Connect to guestgate captive portal network
189 3. Verify connectivity
190 """
191 # turn off private dns
192 cutils.set_private_dns(self.dut, cconst.PRIVATE_DNS_MODE_OFF)
193
194 # verify connection to captive portal network
195 self._verify_captive_portal(self.gg_captive_portal, "gg_captive_portal")
196
197 @test_tracker_info(uuid="39124dcc-2fd3-4d33-b129-a1c8150b7f2a")
198 def test_guestgate_captive_portal_private_dns_strict(self):
Girish Moturu3a8de0d2019-12-06 13:00:33 -0800199 """Verify captive portal network.
Girish Moturu7e48b432019-07-11 14:52:13 -0700200
201 Steps:
202 1. Set strict private dns mode
203 2. Connect to guestgate captive portal network
204 3. Verify connectivity
205 """
206 # set private dns to strict mode
207 cutils.set_private_dns(self.dut,
208 cconst.PRIVATE_DNS_MODE_STRICT,
209 cconst.DNS_GOOGLE)
210
211 # verify connection to captive portal network
212 self._verify_captive_portal(self.gg_captive_portal, "gg_captive_portal")