summaryrefslogtreecommitdiff
path: root/src/leap
diff options
context:
space:
mode:
Diffstat (limited to 'src/leap')
-rw-r--r--src/leap/base/exceptions.py2
-rw-r--r--src/leap/base/providers.py2
-rw-r--r--src/leap/base/tests/test_config.py62
-rw-r--r--src/leap/base/tests/test_providers.py6
-rw-r--r--src/leap/eip/config.py1
-rw-r--r--src/leap/eip/tests/data.py14
-rw-r--r--src/leap/eip/tests/test_checks.py4
-rw-r--r--src/leap/eip/tests/test_config.py26
8 files changed, 70 insertions, 47 deletions
diff --git a/src/leap/base/exceptions.py b/src/leap/base/exceptions.py
index caaa3be6..9c4aa77b 100644
--- a/src/leap/base/exceptions.py
+++ b/src/leap/base/exceptions.py
@@ -4,5 +4,3 @@ class MissingConfigFileError(Exception):
class ImproperlyConfigured(Exception):
pass
-
-
diff --git a/src/leap/base/providers.py b/src/leap/base/providers.py
index ce30d4a4..7b219cc7 100644
--- a/src/leap/base/providers.py
+++ b/src/leap/base/providers.py
@@ -9,7 +9,7 @@ class LeapProviderDefinition(baseconfig.JSONLeapConfig):
def _get_slug(self):
provider_path = baseconfig.get_default_provider_path()
return baseconfig.get_config_file(
- 'provider-definition.json',
+ 'provider.json',
folder=provider_path)
def _set_slug(self, *args, **kwargs):
diff --git a/src/leap/base/tests/test_config.py b/src/leap/base/tests/test_config.py
index 74b06119..bede5ea1 100644
--- a/src/leap/base/tests/test_config.py
+++ b/src/leap/base/tests/test_config.py
@@ -65,15 +65,15 @@ class ProviderTest(BaseLeapTest):
pass
-class BareHomeTestCase(ProviderTest):
+# XXX depreacated. similar test in eip.checks
- __name__ = "provider_config_tests_bare_home"
-
- # XXX review. is it still needed?
-
- def test_should_raise_if_missing_eip_json(self):
- with self.assertRaises(exceptions.MissingConfigFileError):
- config.get_config_json(os.path.join(self.home, 'eip.json'))
+#class BareHomeTestCase(ProviderTest):
+#
+ #__name__ = "provider_config_tests_bare_home"
+#
+ #def test_should_raise_if_missing_eip_json(self):
+ #with self.assertRaises(exceptions.MissingConfigFileError):
+ #config.get_config_json(os.path.join(self.home, 'eip.json'))
class ProviderDefinitionTestCase(ProviderTest):
@@ -94,8 +94,10 @@ class ProviderDefinitionTestCase(ProviderTest):
json.dump(eipconstants.EIP_SAMPLE_JSON, fp)
-# these tests below should move to wherever
-# we put the fetcher for provider files and related stuff.
+# these tests below should move to
+# eip.checks
+# config.Configuration has been deprecated
+
# TODO:
# - We're instantiating a ProviderTest because we're doing the home wipeoff
# on setUpClass instead of the setUp (for speedup of the general cases).
@@ -112,26 +114,26 @@ class ProviderDefinitionTestCase(ProviderTest):
# (so we can pass mock easily).
-class ProviderFetchConError(ProviderTest):
- def test_connection_error(self):
- with mock.patch.object(requests, "get") as mock_method:
- mock_method.side_effect = requests.ConnectionError
- cf = config.Configuration()
- self.assertIsInstance(cf.error, str)
-
-
-class ProviderFetchHttpError(ProviderTest):
- def test_file_not_found(self):
- with mock.patch.object(requests, "get") as mock_method:
- mock_method.side_effect = requests.HTTPError
- cf = config.Configuration()
- self.assertIsInstance(cf.error, str)
-
-
-class ProviderFetchInvalidUrl(ProviderTest):
- def test_invalid_url(self):
- cf = config.Configuration("ht")
- self.assertTrue(cf.error)
+#class ProviderFetchConError(ProviderTest):
+ #def test_connection_error(self):
+ #with mock.patch.object(requests, "get") as mock_method:
+ #mock_method.side_effect = requests.ConnectionError
+ #cf = config.Configuration()
+ #self.assertIsInstance(cf.error, str)
+#
+#
+#class ProviderFetchHttpError(ProviderTest):
+ #def test_file_not_found(self):
+ #with mock.patch.object(requests, "get") as mock_method:
+ #mock_method.side_effect = requests.HTTPError
+ #cf = config.Configuration()
+ #self.assertIsInstance(cf.error, str)
+#
+#
+#class ProviderFetchInvalidUrl(ProviderTest):
+ #def test_invalid_url(self):
+ #cf = config.Configuration("ht")
+ #self.assertTrue(cf.error)
# end provider fetch tests
diff --git a/src/leap/base/tests/test_providers.py b/src/leap/base/tests/test_providers.py
index 23f63a95..9e0ff90c 100644
--- a/src/leap/base/tests/test_providers.py
+++ b/src/leap/base/tests/test_providers.py
@@ -6,9 +6,11 @@ except ImportError:
import os
+from leap import __branding as BRANDING
from leap.testing.basetest import BaseLeapTest
from leap.base import providers
+
EXPECTED_DEFAULT_CONFIG = {
"api_version": "0.1.0",
"description": "test provider",
@@ -45,8 +47,8 @@ class TestLeapProviderDefinition(BaseLeapTest):
os.path.join(
self.home,
'.config', 'leap', 'providers',
- 'testprovider.example.org',
- 'provider-definition.json'))
+ '%s' % BRANDING.get('provider_domain'),
+ 'provider.json'))
with self.assertRaises(AttributeError):
self.definition.slug = 23
diff --git a/src/leap/eip/config.py b/src/leap/eip/config.py
index e5fcd164..44922310 100644
--- a/src/leap/eip/config.py
+++ b/src/leap/eip/config.py
@@ -112,6 +112,7 @@ def build_ovpn_options(daemon=False, socket_path=None, **kwargs):
# remote
opts.append('--remote')
gw = get_eip_gateway()
+ #gw = "springbokvpn.org"
logger.debug('setting eip gateway to %s', gw)
opts.append(str(gw))
opts.append('1194')
diff --git a/src/leap/eip/tests/data.py b/src/leap/eip/tests/data.py
index 284b398f..4da0e18f 100644
--- a/src/leap/eip/tests/data.py
+++ b/src/leap/eip/tests/data.py
@@ -1,21 +1,25 @@
from __future__ import unicode_literals
import os
+from leap import __branding
+
# sample data used in tests
+PROVIDER = __branding.get('provider_domain')
+
EIP_SAMPLE_JSON = {
- "provider": "testprovider.example.org",
+ "provider": "%s" % PROVIDER,
"transport": "openvpn",
"openvpn_protocol": "tcp",
"openvpn_port": 80,
"openvpn_ca_certificate": os.path.expanduser(
"~/.config/leap/providers/"
- "testprovider.example.org/"
- "keys/ca/testprovider-ca-cert.pem"),
+ "%s/"
+ "keys/ca/testprovider-ca-cert.pem" % PROVIDER),
"openvpn_client_certificate": os.path.expanduser(
"~/.config/leap/providers/"
- "testprovider.example.org/"
- "keys/client/openvpn.pem"),
+ "%s/"
+ "keys/client/openvpn.pem" % PROVIDER),
"connect_on_login": True,
"block_cleartext_traffic": True,
"primary_gateway": "usa_west",
diff --git a/src/leap/eip/tests/test_checks.py b/src/leap/eip/tests/test_checks.py
index 952b10d2..42aa9cce 100644
--- a/src/leap/eip/tests/test_checks.py
+++ b/src/leap/eip/tests/test_checks.py
@@ -331,10 +331,10 @@ class ProviderCertCheckerHTTPSTests(BaseHTTPSServerTestCase, BaseLeapTest):
fetcher.get(uri, verify=True)
self.assertTrue(
"SSL23_GET_SERVER_HELLO:unknown protocol" in exc.message)
- with self.assertRaises(requests.exceptions.SSLError) as exc:
+ with self.assertRaises(eipexceptions.EIPBadCertError) as exc:
checker.is_https_working(uri=uri, verify=True)
self.assertTrue(
- "SSL23_GET_SERVER_HELLO:unknown protocol" in exc.message)
+ "cert verification failed" in exc.message)
# get cacert from testing.https_server
cacert = where_cert('cacert.pem')
diff --git a/src/leap/eip/tests/test_config.py b/src/leap/eip/tests/test_config.py
index 60300770..f9f963dc 100644
--- a/src/leap/eip/tests/test_config.py
+++ b/src/leap/eip/tests/test_config.py
@@ -1,3 +1,4 @@
+import json
import os
import platform
import stat
@@ -9,11 +10,17 @@ except ImportError:
#from leap.base import constants
#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.testing.basetest import BaseLeapTest
from leap.util.fileutil import mkdir_p
_system = platform.system()
+PROVIDER = BRANDING.get('provider_domain')
+PROVIDER_SHORTNAME = BRANDING.get('short_name')
+
class EIPConfigTest(BaseLeapTest):
@@ -39,6 +46,14 @@ class EIPConfigTest(BaseLeapTest):
open(tfile, 'wb').close()
os.chmod(tfile, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
+ def write_sample_eipservice(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_SERVICE))
+
def get_expected_openvpn_args(self):
args = []
username = self.get_username()
@@ -51,7 +66,7 @@ class EIPConfigTest(BaseLeapTest):
args.append('--persist-tun')
args.append('--persist-key')
args.append('--remote')
- args.append('testprovider.example.org')
+ args.append('%s' % eipconfig.get_eip_gateway())
# XXX get port!?
args.append('1194')
# XXX get proto
@@ -80,23 +95,23 @@ class EIPConfigTest(BaseLeapTest):
args.append(os.path.join(
self.home,
'.config', 'leap', 'providers',
- 'testprovider.example.org',
+ '%s' % PROVIDER,
'keys', 'client',
'openvpn.pem'))
args.append('--key')
args.append(os.path.join(
self.home,
'.config', 'leap', 'providers',
- 'testprovider.example.org',
+ '%s' % PROVIDER,
'keys', 'client',
'openvpn.pem'))
args.append('--ca')
args.append(os.path.join(
self.home,
'.config', 'leap', 'providers',
- 'testprovider.example.org',
+ '%s' % PROVIDER,
'keys', 'ca',
- 'testprovider-ca-cert.pem'))
+ '%s-cacert.pem' % PROVIDER_SHORTNAME))
return args
# build command string
@@ -107,6 +122,7 @@ class EIPConfigTest(BaseLeapTest):
def test_build_ovpn_command_empty_config(self):
self.touch_exec()
+ self.write_sample_eipservice()
from leap.eip import config as eipconfig
from leap.util.fileutil import which
path = os.environ['PATH']