1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
#!/usr/bin/env python
# Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import os
import subprocess
import pyauto_functional
import pyauto
import chromeos_network
class PrivateNetworkTest(chromeos_network.PyNetworkUITest):
"""Tests for VPN.
Expected to be run with access to the lab setup as defined in
vpn_testbed_config.
"""
def _PingTest(self, hostname, timeout=10):
"""Attempt to ping a remote host.
Returns:
True if the ping succeeds.
False otherwise.
"""
return subprocess.call(['ping', '-c', '1', '-W',
str(timeout), hostname]) == 0
def testCanAddNetwork(self):
"""Test to add a VPN network, connect and disconnect."""
# Load VPN config data from file.
vpn_info_file = os.path.join(pyauto.PyUITest.DataDir(),
'pyauto_private/chromeos/network',
'vpn_testbed_config')
self.assertTrue(os.path.exists(vpn_info_file))
vpn = self.EvalDataFrom(vpn_info_file)
# Connect to wifi.
self.NetworkScan()
self.WaitUntilWifiNetworkAvailable(vpn['wifi'])
wifi_vpn = self.GetServicePath(vpn['wifi'])
self.assertTrue(wifi_vpn)
self.assertTrue(self.ConnectToWifiNetwork(wifi_vpn) is None)
self.assertFalse(self._PingTest(vpn['ping']),
msg='VPN ping succeeded when not connected.')
# Connect to the VPN.
self.AddPrivateNetwork(hostname=vpn['hostname'],
service_name=vpn['service_name'],
provider_type=vpn['provider_type'],
username=vpn['username'],
password=vpn['password'],
key=vpn['key'])
# Get private network info.
result = self.GetPrivateNetworkInfo()
self.assertTrue('connected' in result, msg='Could not connect to VPN')
connected = result['connected']
self.assertTrue(self._PingTest(vpn['ping']), msg='VPN ping failed.')
self.DisconnectFromPrivateNetwork()
self.assertFalse(self._PingTest(vpn['ping']),
msg='VPN ping succeeded when not connected.')
# Connect to the remembered private network.
self.ConnectToPrivateNetwork(connected)
self.assertTrue(self._PingTest(vpn['ping']), msg='VPN ping failed.')
self.DisconnectFromPrivateNetwork()
self.assertFalse(self._PingTest(vpn['ping']),
msg='VPN ping succeeded when not connected.')
if __name__ == '__main__':
pyauto_functional.Main()
|