1#
2#   Copyright 2020 - 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
16
17from acts import base_test
18from acts.test_decorators import test_tracker_info
19from acts_contrib.test_utils.net import connectivity_const
20from acts_contrib.test_utils.net import net_test_utils as nutils
21from acts_contrib.test_utils.wifi import wifi_test_utils as wutils
22
23VPN_CONST = connectivity_const.VpnProfile
24VPN_TYPE = connectivity_const.VpnProfileType
25VPN_PARAMS = connectivity_const.VpnReqParams
26
27
28class IKEv2VpnOverLTETest(base_test.BaseTestClass):
29  """IKEv2 VPN tests."""
30
31  def setup_class(self):
32
33    required_params = dir(VPN_PARAMS)
34    required_params = [x for x in required_params if not x.startswith("__")]
35    self.unpack_userparams(req_param_names=required_params)
36    self.vpn_params = {
37        "vpn_username": self.vpn_username,
38        "vpn_password": self.vpn_password,
39        "psk_secret": self.psk_secret,
40        "client_pkcs_file_name": self.client_pkcs_file_name,
41        "cert_path_vpnserver": self.cert_path_vpnserver,
42        "cert_password": self.cert_password,
43        "vpn_identity": self.vpn_identity,
44    }
45
46    for ad in self.android_devices:
47      wutils.wifi_test_device_init(ad)
48      nutils.verify_lte_data_and_tethering_supported(ad)
49    self.tmo_dut = self.android_devices[0]
50    self.vzw_dut = self.android_devices[1]
51
52  def on_fail(self, test_name, begin_time):
53    for ad in self.android_devices:
54      ad.take_bug_report(test_name, begin_time)
55
56  ### Helper methods ###
57
58  def _test_ikev2_vpn(self, ad, vpn, hostname=None):
59    """Verify IKEv2 VPN connection.
60
61    Args:
62      ad: android device to run the test.
63      vpn: type of VPN.
64      hostname: hostname or IP address of the server.
65    """
66    server_addr = self.vpn_server_addresses[vpn.name][0]
67    self.vpn_params["server_addr"] = server_addr
68    if not hostname:
69      hostname = server_addr
70    vpn_addr = self.vpn_verify_addresses[vpn.name][0]
71    vpn_profile = nutils.generate_ikev2_vpn_profile(
72        ad, self.vpn_params, vpn, hostname, self.log_path)
73    nutils.legacy_vpn_connection_test_logic(ad, vpn_profile, vpn_addr)
74
75  ### Test cases ###
76
77  @test_tracker_info(uuid="31fac6c5-f76c-403c-8b76-29c01557a48a")
78  def test_ikev2_psk_vpn_tmo(self):
79    self._test_ikev2_vpn(self.tmo_dut, VPN_TYPE.IKEV2_IPSEC_PSK)
80
81  @test_tracker_info(uuid="c28adef0-6578-4841-a833-e52a5b16a390")
82  def test_ikev2_mschapv2_vpn_tmo(self):
83    self._test_ikev2_vpn(self.tmo_dut, VPN_TYPE.IKEV2_IPSEC_USER_PASS)
84
85  @test_tracker_info(uuid="6c7daad9-ae7a-493d-bbab-9001068f22c5")
86  def test_ikev2_rsa_vpn_tmo(self):
87    self._test_ikev2_vpn(self.tmo_dut, VPN_TYPE.IKEV2_IPSEC_RSA)
88
89  @test_tracker_info(uuid="1275a2f-e939-4557-879d-fbbd9c5dbd93")
90  def test_ikev2_psk_vpn_vzw(self):
91    self._test_ikev2_vpn(self.vzw_dut, VPN_TYPE.IKEV2_IPSEC_PSK)
92
93  @test_tracker_info(uuid="fd146163-f28d-4514-96a0-82f51b70e218")
94  def test_ikev2_mschapv2_vpn_vzw(self):
95    self._test_ikev2_vpn(self.vzw_dut, VPN_TYPE.IKEV2_IPSEC_USER_PASS)
96
97  @test_tracker_info(uuid="722de9b5-834f-4854-b4a6-e31860628fe9")
98  def test_ikev2_rsa_vpn_vzw(self):
99    self._test_ikev2_vpn(self.vzw_dut, VPN_TYPE.IKEV2_IPSEC_RSA)
100