blob: 10240e40320a69675e4547a96491b81550a59ff9 [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
20from acts import signals
21from acts.libs.uicd.uicd_cli import UicdCli
22from acts.test_decorators import test_tracker_info
23from acts.test_utils.net import connectivity_const as cconst
24from acts.test_utils.net import connectivity_test_utils as cutils
25from acts.test_utils.wifi import wifi_test_utils as wutils
26
27WifiEnums = wutils.WifiEnums
28IFACE = "InterfaceName"
29TIME_OUT = 20
30WLAN = "wlan0"
31
32
33class CaptivePortalTest(base_test.BaseTestClass):
34 """ Tests for Captive portal """
35
36 def setup_class(self):
37 """Setup devices for tests and unpack params
38
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):
60 """ Reset devices """
61 cutils.set_private_dns(self.dut, cconst.PRIVATE_DNS_MODE_OPPORTUNISTIC)
62
63 def setup_test(self):
64 """ Setup device """
65 self.dut.unlock_screen()
66
67 def teardown_test(self):
68 """ Reset to default state after each test """
69 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):
77 """Connect to captive portal network using uicd workflow
78
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:
85 1. network: captive portal network to connect to
86 2. uicd_workflow: ui workflow to accept captive portal conn
87 """
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
106 internet = wutils.validate_connection(self.dut,
107 wutils.DEFAULT_PING_ADDR)
108 if not internet:
109 raise signals.TestFailure("Failed to connect to internet on %s" %
110 network[WifiEnums.SSID_KEY])
111
112 ### Test Cases ###
113
114 @test_tracker_info(uuid="b035b4f9-40f7-42f6-9941-ec27afe15040")
115 def test_ruckus_captive_portal_default(self):
116 """Verify captive portal network
117
118 Steps:
119 1. Set default private dns mode
120 2. Connect to ruckus captive portal network
121 3. Verify connectivity
122 """
123 # set private dns to opportunistic
124 cutils.set_private_dns(self.dut, cconst.PRIVATE_DNS_MODE_OPPORTUNISTIC)
125
126 # verify connection to captive portal network
127 self._verify_captive_portal(self.rk_captive_portal,
128 self.rk_workflow_config)
129
130 @test_tracker_info(uuid="8ea18d80-0170-41b1-8945-fe14bcd4feab")
131 def test_ruckus_captive_portal_private_dns_off(self):
132 """Verify captive portal network
133
134 Steps:
135 1. Turn off private dns mode
136 2. Connect to ruckus captive portal network
137 3. Verify connectivity
138 """
139 # turn off private dns
140 cutils.set_private_dns(self.dut, cconst.PRIVATE_DNS_MODE_OFF)
141
142 # verify connection to captive portal network
143 self._verify_captive_portal(self.rk_captive_portal,
144 self.rk_workflow_config)
145
146 @test_tracker_info(uuid="e8e05907-55f7-40e5-850c-b3111ceb31a4")
147 def test_ruckus_captive_portal_private_dns_strict(self):
148 """Verify captive portal network
149
150 Steps:
151 1. Set strict private dns mode
152 2. Connect to ruckus captive portal network
153 3. Verify connectivity
154 """
155 # set private dns to strict mode
156 cutils.set_private_dns(self.dut,
157 cconst.PRIVATE_DNS_MODE_STRICT,
158 cconst.DNS_GOOGLE)
159
160 # verify connection to captive portal network
161 self._verify_captive_portal(self.rk_captive_portal,
162 self.rk_workflow_config)
163
164 @test_tracker_info(uuid="76e49800-f141-4fd2-9969-562585eb1e7a")
165 def test_guestgate_captive_portal_default(self):
166 """Verify captive portal network
167
168 Steps:
169 1. Set default private dns mode
170 2. Connect to guestgate captive portal network
171 3. Verify connectivity
172 """
173 # set private dns to opportunistic
174 cutils.set_private_dns(self.dut, cconst.PRIVATE_DNS_MODE_OPPORTUNISTIC)
175
176 # verify connection to captive portal network
177 self._verify_captive_portal(self.gg_captive_portal, "gg_captive_portal")
178
179 @test_tracker_info(uuid="0aea0cac-0f42-406b-84ba-62c1ef74adfc")
180 def test_guestgate_captive_portal_private_dns_off(self):
181 """Verify captive portal network
182
183 Steps:
184 1. Turn off private dns mode
185 2. Connect to guestgate captive portal network
186 3. Verify connectivity
187 """
188 # turn off private dns
189 cutils.set_private_dns(self.dut, cconst.PRIVATE_DNS_MODE_OFF)
190
191 # verify connection to captive portal network
192 self._verify_captive_portal(self.gg_captive_portal, "gg_captive_portal")
193
194 @test_tracker_info(uuid="39124dcc-2fd3-4d33-b129-a1c8150b7f2a")
195 def test_guestgate_captive_portal_private_dns_strict(self):
196 """Verify captive portal network
197
198 Steps:
199 1. Set strict private dns mode
200 2. Connect to guestgate captive portal network
201 3. Verify connectivity
202 """
203 # set private dns to strict mode
204 cutils.set_private_dns(self.dut,
205 cconst.PRIVATE_DNS_MODE_STRICT,
206 cconst.DNS_GOOGLE)
207
208 # verify connection to captive portal network
209 self._verify_captive_portal(self.gg_captive_portal, "gg_captive_portal")