summaryrefslogtreecommitdiff
path: root/src/leap/eip/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/leap/eip/tests')
-rw-r--r--src/leap/eip/tests/data.py9
-rw-r--r--src/leap/eip/tests/test_checks.py30
-rw-r--r--src/leap/eip/tests/test_config.py14
-rw-r--r--src/leap/eip/tests/test_openvpnconnection.py12
4 files changed, 47 insertions, 18 deletions
diff --git a/src/leap/eip/tests/data.py b/src/leap/eip/tests/data.py
index 9bf86540..43df2013 100644
--- a/src/leap/eip/tests/data.py
+++ b/src/leap/eip/tests/data.py
@@ -7,7 +7,7 @@ from leap import __branding
PROVIDER = __branding.get('provider_domain')
-EIP_SAMPLE_JSON = {
+EIP_SAMPLE_CONFIG = {
"provider": "%s" % PROVIDER,
"transport": "openvpn",
"openvpn_protocol": "tcp",
@@ -38,9 +38,10 @@ EIP_SAMPLE_SERVICE = {
"adblock": True
},
"gateways": [
- {"country_code": "us",
- "label": {"en":"west"},
+ {"country_code": "tr",
+ "name": "turkey",
+ "label": {"en":"Ankara, Turkey"},
"capabilities": {},
- "hosts": ["1.2.3.4", "1.2.3.5"]},
+ "hosts": ["94.103.43.4"]}
]
}
diff --git a/src/leap/eip/tests/test_checks.py b/src/leap/eip/tests/test_checks.py
index 06133825..58ce473f 100644
--- a/src/leap/eip/tests/test_checks.py
+++ b/src/leap/eip/tests/test_checks.py
@@ -11,6 +11,8 @@ import urlparse
from mock import (patch, Mock)
+import jsonschema
+#import ping
import requests
from leap.base import config as baseconfig
@@ -89,12 +91,12 @@ class EIPCheckTest(BaseLeapTest):
# force re-evaluation of the paths
# small workaround for evaluating home dirs correctly
- EIP_SAMPLE_JSON = copy.copy(testdata.EIP_SAMPLE_JSON)
- EIP_SAMPLE_JSON['openvpn_client_certificate'] = \
+ EIP_SAMPLE_CONFIG = copy.copy(testdata.EIP_SAMPLE_CONFIG)
+ EIP_SAMPLE_CONFIG['openvpn_client_certificate'] = \
eipspecs.client_cert_path()
- EIP_SAMPLE_JSON['openvpn_ca_certificate'] = \
+ EIP_SAMPLE_CONFIG['openvpn_ca_certificate'] = \
eipspecs.provider_ca_path()
- self.assertEqual(deserialized, EIP_SAMPLE_JSON)
+ self.assertEqual(deserialized, EIP_SAMPLE_CONFIG)
# TODO: shold ALSO run validation methods.
@@ -111,16 +113,20 @@ class EIPCheckTest(BaseLeapTest):
# ok. now, messing with real files...
# blank out default_provider
- sampleconfig = copy.copy(testdata.EIP_SAMPLE_JSON)
+ sampleconfig = copy.copy(testdata.EIP_SAMPLE_CONFIG)
sampleconfig['provider'] = None
eipcfg_path = checker.eipconfig.filename
with open(eipcfg_path, 'w') as fp:
json.dump(sampleconfig, fp)
- with self.assertRaises(eipexceptions.EIPMissingDefaultProvider):
+ #with self.assertRaises(eipexceptions.EIPMissingDefaultProvider):
+ # XXX we should catch this as one of our errors, but do not
+ # see how to do it quickly.
+ with self.assertRaises(jsonschema.ValidationError):
+ #import ipdb;ipdb.set_trace()
checker.eipconfig.load(fromfile=eipcfg_path)
checker.check_is_there_default_provider()
- sampleconfig = testdata.EIP_SAMPLE_JSON
+ sampleconfig = testdata.EIP_SAMPLE_CONFIG
#eipcfg_path = checker._get_default_eipconfig_path()
with open(eipcfg_path, 'w') as fp:
json.dump(sampleconfig, fp)
@@ -132,7 +138,7 @@ class EIPCheckTest(BaseLeapTest):
mocked_get.return_value.status_code = 200
mocked_get.return_value.json = DEFAULT_PROVIDER_DEFINITION
checker = eipchecks.EIPConfigChecker(fetcher=requests)
- sampleconfig = testdata.EIP_SAMPLE_JSON
+ sampleconfig = testdata.EIP_SAMPLE_CONFIG
checker.fetch_definition(config=sampleconfig)
fn = os.path.join(baseconfig.get_default_provider_path(),
@@ -150,22 +156,22 @@ class EIPCheckTest(BaseLeapTest):
mocked_get.return_value.status_code = 200
mocked_get.return_value.json = testdata.EIP_SAMPLE_SERVICE
checker = eipchecks.EIPConfigChecker(fetcher=requests)
- sampleconfig = testdata.EIP_SAMPLE_JSON
+ sampleconfig = testdata.EIP_SAMPLE_CONFIG
checker.fetch_eip_service_config(config=sampleconfig)
def test_check_complete_eip_config(self):
checker = eipchecks.EIPConfigChecker()
with self.assertRaises(eipexceptions.EIPConfigurationError):
- sampleconfig = copy.copy(testdata.EIP_SAMPLE_JSON)
+ sampleconfig = copy.copy(testdata.EIP_SAMPLE_CONFIG)
sampleconfig['provider'] = None
checker.check_complete_eip_config(config=sampleconfig)
with self.assertRaises(eipexceptions.EIPConfigurationError):
- sampleconfig = copy.copy(testdata.EIP_SAMPLE_JSON)
+ sampleconfig = copy.copy(testdata.EIP_SAMPLE_CONFIG)
del sampleconfig['provider']
checker.check_complete_eip_config(config=sampleconfig)
# normal case
- sampleconfig = copy.copy(testdata.EIP_SAMPLE_JSON)
+ sampleconfig = copy.copy(testdata.EIP_SAMPLE_CONFIG)
checker.check_complete_eip_config(config=sampleconfig)
diff --git a/src/leap/eip/tests/test_config.py b/src/leap/eip/tests/test_config.py
index f9f963dc..6759b522 100644
--- a/src/leap/eip/tests/test_config.py
+++ b/src/leap/eip/tests/test_config.py
@@ -12,7 +12,7 @@ except ImportError:
#from leap.eip import config as eip_config
from leap import __branding as BRANDING
from leap.eip import config as eipconfig
-from leap.eip.tests.data import EIP_SAMPLE_SERVICE
+from leap.eip.tests.data import EIP_SAMPLE_CONFIG, EIP_SAMPLE_SERVICE
from leap.testing.basetest import BaseLeapTest
from leap.util.fileutil import mkdir_p
@@ -47,13 +47,21 @@ class EIPConfigTest(BaseLeapTest):
os.chmod(tfile, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
def write_sample_eipservice(self):
- conf = eipconfig.EIPConfig()
+ conf = eipconfig.EIPServiceConfig()
folder, f = os.path.split(conf.filename)
if not os.path.isdir(folder):
mkdir_p(folder)
with open(conf.filename, 'w') as fd:
fd.write(json.dumps(EIP_SAMPLE_SERVICE))
+ def write_sample_eipconfig(self):
+ conf = eipconfig.EIPConfig()
+ folder, f = os.path.split(conf.filename)
+ if not os.path.isdir(folder):
+ mkdir_p(folder)
+ with open(conf.filename, 'w') as fd:
+ fd.write(json.dumps(EIP_SAMPLE_CONFIG))
+
def get_expected_openvpn_args(self):
args = []
username = self.get_username()
@@ -123,6 +131,8 @@ class EIPConfigTest(BaseLeapTest):
def test_build_ovpn_command_empty_config(self):
self.touch_exec()
self.write_sample_eipservice()
+ self.write_sample_eipconfig()
+
from leap.eip import config as eipconfig
from leap.util.fileutil import which
path = os.environ['PATH']
diff --git a/src/leap/eip/tests/test_openvpnconnection.py b/src/leap/eip/tests/test_openvpnconnection.py
index 885c80b3..61769f04 100644
--- a/src/leap/eip/tests/test_openvpnconnection.py
+++ b/src/leap/eip/tests/test_openvpnconnection.py
@@ -1,6 +1,7 @@
import logging
import os
import platform
+import psutil
import shutil
#import socket
@@ -16,6 +17,7 @@ from mock import Mock, patch # MagicMock
from leap.eip import config as eipconfig
from leap.eip import openvpnconnection
+from leap.eip import exceptions as eipexceptions
from leap.eip.udstelnet import UDSTelnet
from leap.testing.basetest import BaseLeapTest
@@ -73,6 +75,16 @@ class OpenVPNConnectionTest(BaseLeapTest):
# tests
#
+ def test_detect_vpn(self):
+ openvpn_connection = openvpnconnection.OpenVPNConnection()
+ with patch.object(psutil, "get_process_list") as mocked_psutil:
+ with self.assertRaises(eipexceptions.OpenVPNAlreadyRunning):
+ mocked_process = Mock()
+ mocked_process.name = "openvpn"
+ mocked_psutil.return_value = [mocked_process]
+ openvpn_connection._check_if_running_instance()
+ openvpn_connection._check_if_running_instance()
+
@unittest.skipIf(_system == "Windows", "lin/mac only")
def test_lin_mac_default_init(self):
"""