From 79dc31303f1e2a5449a03b1a6a4bdf291cae52e7 Mon Sep 17 00:00:00 2001 From: antialias Date: Fri, 30 Nov 2012 16:28:07 -0500 Subject: in leap.base.checks.check_internet_connection modified the order in which errors are checked and improved test coverage. --- src/leap/base/checks.py | 11 +++++++---- src/leap/base/tests/test_checks.py | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) (limited to 'src/leap/base') diff --git a/src/leap/base/checks.py b/src/leap/base/checks.py index 23446f4a..dc2602c2 100644 --- a/src/leap/base/checks.py +++ b/src/leap/base/checks.py @@ -39,9 +39,6 @@ class LeapNetworkChecker(object): # XXX remove this hardcoded random ip # ping leap.se or eip provider instead...? requests.get('http://216.172.161.165') - - except (requests.HTTPError, requests.RequestException) as e: - raise exceptions.NoInternetConnection(e.message) except requests.ConnectionError as e: error = "Unidentified Connection Error" if e.message == "[Errno 113] No route to host": @@ -51,11 +48,17 @@ class LeapNetworkChecker(object): error = "Provider server appears to be down." logger.error(error) raise exceptions.NoInternetConnection(error) + except (requests.HTTPError, requests.RequestException) as e: + raise exceptions.NoInternetConnection(e.message) logger.debug('Network appears to be up.') def is_internet_up(self): iface, gateway = self.get_default_interface_gateway() - self.ping_gateway(self.provider_gateway) + try: + self.ping_gateway(self.provider_gateway) + except exceptions.NoConnectionToGateway: + return False + return True def check_tunnel_default_interface(self): """ diff --git a/src/leap/base/tests/test_checks.py b/src/leap/base/tests/test_checks.py index 8d573b1e..272e7053 100644 --- a/src/leap/base/tests/test_checks.py +++ b/src/leap/base/tests/test_checks.py @@ -118,6 +118,22 @@ class LeapNetworkCheckTest(BaseLeapTest): with self.assertRaises(exceptions.NoInternetConnection): checker.check_internet_connection() + with patch.object(requests, "get") as mocked_get: + mocked_get.side_effect = \ + requests.ConnectionError("[Errno 113] No route to host") + with self.assertRaises(exceptions.NoInternetConnection): + with patch.object(checker, "ping_gateway") as mock_ping: + mock_ping.return_value = True + checker.check_internet_connection() + + with patch.object(requests, "get") as mocked_get: + mocked_get.side_effect = \ + requests.ConnectionError("[Errno 113] No route to host") + with self.assertRaises(exceptions.NoInternetConnection): + with patch.object(checker, "ping_gateway") as mock_ping: + mock_ping.side_effect = exceptions.NoConnectionToGateway + checker.check_internet_connection() + @unittest.skipUnless(_uid == 0, "root only") def test_ping_gateway(self): checker = checks.LeapNetworkChecker() -- cgit v1.2.3 From e7dbf89f31711271e61f653e1cc7fb2c2b57cc6e Mon Sep 17 00:00:00 2001 From: antialias Date: Fri, 30 Nov 2012 18:04:13 -0500 Subject: to improve code coverage, began writing tests for leap.base.auth. --- src/leap/base/tests/test_auth.py | 57 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/leap/base/tests/test_auth.py (limited to 'src/leap/base') diff --git a/src/leap/base/tests/test_auth.py b/src/leap/base/tests/test_auth.py new file mode 100644 index 00000000..a6f2ceb9 --- /dev/null +++ b/src/leap/base/tests/test_auth.py @@ -0,0 +1,57 @@ +from BaseHTTPServer import BaseHTTPRequestHandler +try: + import unittest2 as unittest +except ImportError: + import unittest + +import requests +from mock import Mock + +from leap.base import auth +from leap.base import exceptions +from leap.eip.tests.test_checks import NoLogRequestHandler +from leap.testing.basetest import BaseLeapTest +from leap.testing.https_server import BaseHTTPSServerTestCase + + +class LeapSRPRegisterTests(BaseHTTPSServerTestCase, BaseLeapTest): + __name__ = "leap_srp_register_test" + provider = "testprovider.example.org" + + class request_handler(NoLogRequestHandler, BaseHTTPRequestHandler): + responses = { + '/': ['OK', ''], + } + + def do_GET(self): + path = urlparse.urlparse(self.path) + message = '\n'.join(self.responses.get( + path.path, None)) + self.send_response(200) + self.end_headers() + self.wfile.write(message) + + def setUp(self): + pass + + def tearDown(self): + pass + + def test_srp_auth_should_implement_check_methods(self): + SERVER = "https://localhost:8443" + srp_auth = auth.LeapSRPRegister(provider=SERVER, verify=False) + + self.assertTrue(hasattr(srp_auth, "init_session"), + "missing meth") + self.assertTrue(hasattr(srp_auth, "get_registration_uri"), + "missing meth") + self.assertTrue(hasattr(srp_auth, "register_user"), + "missing meth") + + def test_srp_auth_basic_functionality(self): + SERVER = "https://localhost:8443" + srp_auth = auth.LeapSRPRegister(provider=SERVER, verify=False) + + self.assertIsInstance(srp_auth.session, requests.sessions.Session) + self.assertEqual(srp_auth.get_registration_uri(), + "https://localhost:8443/1/users.json") -- cgit v1.2.3 From 4c2f68b1158f3840f33a38a81a5fc03495d28466 Mon Sep 17 00:00:00 2001 From: kali Date: Fri, 7 Dec 2012 02:22:33 +0900 Subject: pep8 --- src/leap/base/tests/test_auth.py | 13 +++++++------ src/leap/base/tests/test_checks.py | 8 ++++---- 2 files changed, 11 insertions(+), 10 deletions(-) (limited to 'src/leap/base') diff --git a/src/leap/base/tests/test_auth.py b/src/leap/base/tests/test_auth.py index a6f2ceb9..17b84b52 100644 --- a/src/leap/base/tests/test_auth.py +++ b/src/leap/base/tests/test_auth.py @@ -1,14 +1,15 @@ from BaseHTTPServer import BaseHTTPRequestHandler +import urlparse try: import unittest2 as unittest except ImportError: import unittest import requests -from mock import Mock +#from mock import Mock from leap.base import auth -from leap.base import exceptions +#from leap.base import exceptions from leap.eip.tests.test_checks import NoLogRequestHandler from leap.testing.basetest import BaseLeapTest from leap.testing.https_server import BaseHTTPSServerTestCase @@ -20,8 +21,7 @@ class LeapSRPRegisterTests(BaseHTTPSServerTestCase, BaseLeapTest): class request_handler(NoLogRequestHandler, BaseHTTPRequestHandler): responses = { - '/': ['OK', ''], - } + '/': ['OK', '']} def do_GET(self): path = urlparse.urlparse(self.path) @@ -53,5 +53,6 @@ class LeapSRPRegisterTests(BaseHTTPSServerTestCase, BaseLeapTest): srp_auth = auth.LeapSRPRegister(provider=SERVER, verify=False) self.assertIsInstance(srp_auth.session, requests.sessions.Session) - self.assertEqual(srp_auth.get_registration_uri(), - "https://localhost:8443/1/users.json") + self.assertEqual( + srp_auth.get_registration_uri(), + "https://localhost:8443/1/users.json") diff --git a/src/leap/base/tests/test_checks.py b/src/leap/base/tests/test_checks.py index 272e7053..7a694f89 100644 --- a/src/leap/base/tests/test_checks.py +++ b/src/leap/base/tests/test_checks.py @@ -119,16 +119,16 @@ class LeapNetworkCheckTest(BaseLeapTest): checker.check_internet_connection() with patch.object(requests, "get") as mocked_get: - mocked_get.side_effect = \ - requests.ConnectionError("[Errno 113] No route to host") + mocked_get.side_effect = requests.ConnectionError( + "[Errno 113] No route to host") with self.assertRaises(exceptions.NoInternetConnection): with patch.object(checker, "ping_gateway") as mock_ping: mock_ping.return_value = True checker.check_internet_connection() with patch.object(requests, "get") as mocked_get: - mocked_get.side_effect = \ - requests.ConnectionError("[Errno 113] No route to host") + mocked_get.side_effect = requests.ConnectionError( + "[Errno 113] No route to host") with self.assertRaises(exceptions.NoInternetConnection): with patch.object(checker, "ping_gateway") as mock_ping: mock_ping.side_effect = exceptions.NoConnectionToGateway -- cgit v1.2.3 From 53fa2c134ab2c96376276aa1c0ed74db0aaba218 Mon Sep 17 00:00:00 2001 From: kali Date: Mon, 10 Dec 2012 23:20:09 +0900 Subject: get cipher config from eip-service --- src/leap/base/auth.py | 16 ++-------------- src/leap/base/network.py | 20 +++++++++++++++----- 2 files changed, 17 insertions(+), 19 deletions(-) (limited to 'src/leap/base') diff --git a/src/leap/base/auth.py b/src/leap/base/auth.py index 50533278..73856bb0 100644 --- a/src/leap/base/auth.py +++ b/src/leap/base/auth.py @@ -10,6 +10,7 @@ from PyQt4 import QtCore from leap.base import constants as baseconstants from leap.crypto import leapkeyring +from leap.util.misc import null_check from leap.util.web import get_https_domain_and_port logger = logging.getLogger(__name__) @@ -26,11 +27,6 @@ one if not. """ -class ImproperlyConfigured(Exception): - """ - """ - - class SRPAuthenticationError(Exception): """ exception raised @@ -38,14 +34,6 @@ class SRPAuthenticationError(Exception): """ -def null_check(value, value_name): - try: - assert value is not None - except AssertionError: - raise ImproperlyConfigured( - "%s parameter cannot be None" % value_name) - - safe_unhexlify = lambda x: binascii.unhexlify(x) \ if (len(x) % 2 == 0) else binascii.unhexlify('0' + x) @@ -64,7 +52,7 @@ class LeapSRPRegister(object): hashfun=srp.SHA256, ng_constant=srp.NG_1024): - null_check(provider, provider) + null_check(provider, "provider") self.schema = schema diff --git a/src/leap/base/network.py b/src/leap/base/network.py index 3aba3f61..765d8ea0 100644 --- a/src/leap/base/network.py +++ b/src/leap/base/network.py @@ -3,10 +3,11 @@ from __future__ import (print_function) import logging import threading -from leap.eip.config import get_eip_gateway +from leap.eip import config as eipconfig from leap.base.checks import LeapNetworkChecker from leap.base.constants import ROUTE_CHECK_INTERVAL from leap.base.exceptions import TunnelNotDefaultRouteError +from leap.util.misc import null_check from leap.util.coroutines import (launch_thread, process_events) from time import sleep @@ -27,11 +28,20 @@ class NetworkCheckerThread(object): lambda exc: logger.error("%s", exc.message)) self.shutdown = threading.Event() - # XXX get provider_gateway and pass it to checker - # see in eip.config for function - # #718 + # XXX get provider passed here + provider = kwargs.pop('provider', None) + null_check(provider, 'provider') + + eipconf = eipconfig.EIPConfig(domain=provider) + eipconf.load() + eipserviceconf = eipconfig.EIPServiceConfig(domain=provider) + eipserviceconf.load() + + gw = eipconfig.get_eip_gateway( + eipconfig=eipconf, + eipserviceconfig=eipserviceconf) self.checker = LeapNetworkChecker( - provider_gw=get_eip_gateway()) + provider_gw=gw) def start(self): self.process_handle = self._launch_recurrent_network_checks( -- cgit v1.2.3 From 18be85f13abc6bc94a3725950ec16ad1adec0ab8 Mon Sep 17 00:00:00 2001 From: kali Date: Tue, 11 Dec 2012 01:40:05 +0900 Subject: fetch only if not changed-since config file timestamp Changing this now to be able to test different providers by just updating our local config file. --- src/leap/base/config.py | 75 ++++++++++++++++++++++++++++++---------- src/leap/base/pluggableconfig.py | 17 +++++++++ 2 files changed, 74 insertions(+), 18 deletions(-) (limited to 'src/leap/base') diff --git a/src/leap/base/config.py b/src/leap/base/config.py index 0255fbab..321fbdcd 100644 --- a/src/leap/base/config.py +++ b/src/leap/base/config.py @@ -5,11 +5,12 @@ import grp import json import logging import socket -import tempfile +import time import os logger = logging.getLogger(name=__name__) +from dateutil import parser as dateparser import requests from leap.base import exceptions @@ -126,16 +127,23 @@ class JSONLeapConfig(BaseLeapConfig): # mandatory baseconfig interface def save(self, to=None): - if to is None: - to = self.filename - folder, filename = os.path.split(to) - if folder and not os.path.isdir(folder): - mkdir_p(folder) - self._config.serialize(to) - - def load(self, fromfile=None, from_uri=None, fetcher=None, verify=False): + if self._config.is_dirty(): + if to is None: + to = self.filename + folder, filename = os.path.split(to) + if folder and not os.path.isdir(folder): + mkdir_p(folder) + self._config.serialize(to) + + def load(self, fromfile=None, from_uri=None, fetcher=None, + force_download=False, verify=False): + if from_uri is not None: - fetched = self.fetch(from_uri, fetcher=fetcher, verify=verify) + fetched = self.fetch( + from_uri, + fetcher=fetcher, + verify=verify, + force_dl=force_download) if fetched: return if fromfile is None: @@ -146,33 +154,64 @@ class JSONLeapConfig(BaseLeapConfig): logger.error('tried to load config from non-existent path') logger.error('Not Found: %s', fromfile) - def fetch(self, uri, fetcher=None, verify=True): + def fetch(self, uri, fetcher=None, verify=True, force_dl=False): if not fetcher: fetcher = self.fetcher + logger.debug('verify: %s', verify) logger.debug('uri: %s', uri) - request = fetcher.get(uri, verify=verify) - # XXX should send a if-modified-since header - # XXX get 404, ... - # and raise a UnableToFetch... + rargs = (uri, ) + rkwargs = {'verify': verify} + headers = {} + + curmtime = self.get_mtime() if not force_dl else None + if curmtime: + logger.debug('requesting with if-modified-since %s' % curmtime) + headers['if-modified-since'] = curmtime + rkwargs['headers'] = headers + + #request = fetcher.get(uri, verify=verify) + request = fetcher.get(*rargs, **rkwargs) request.raise_for_status() - fd, fname = tempfile.mkstemp(suffix=".json") - if request.json: - self._config.load(json.dumps(request.json)) + if request.status_code == 304: + logger.debug('...304 Not Changed') + # On this point, we have to assume that + # we HAD the filename. If that filename is corruct, + # we should enforce a force_download in the load + # method above. + self._config.load(fromfile=self.filename) + return True + if request.json: + mtime = None + last_modified = request.headers.get('last-modified', None) + if last_modified: + _mtime = dateparser.parse(last_modified) + mtime = int(_mtime.strftime("%s")) + self._config.load(json.dumps(request.json), mtime=mtime) + self._config.set_dirty() else: # not request.json # might be server did not announce content properly, # let's try deserializing all the same. try: self._config.load(request.content) + self._config.set_dirty() except ValueError: raise eipexceptions.LeapBadConfigFetchedError return True + def get_mtime(self): + try: + _mtime = os.stat(self.filename)[8] + mtime = time.strftime("%c GMT", time.gmtime(_mtime)) + return mtime + except OSError: + return None + def get_config(self): return self._config.config diff --git a/src/leap/base/pluggableconfig.py b/src/leap/base/pluggableconfig.py index b8615ad8..34c1e060 100644 --- a/src/leap/base/pluggableconfig.py +++ b/src/leap/base/pluggableconfig.py @@ -180,6 +180,8 @@ class PluggableConfig(object): self.adaptors = adaptors self.types = types self._format = format + self.mtime = None + self.dirty = False @property def option_dict(self): @@ -319,6 +321,13 @@ class PluggableConfig(object): serializable = self.prep_value(config) adaptor.write(serializable, filename) + if self.mtime: + self.touch_mtime(filename) + + def touch_mtime(self, filename): + mtime = self.mtime + os.utime(filename, (mtime, mtime)) + def deserialize(self, string=None, fromfile=None, format=None): """ load configuration from a file or string @@ -364,6 +373,12 @@ class PluggableConfig(object): content = _try_deserialize() return content + def set_dirty(self): + self.dirty = True + + def is_dirty(self): + return self.dirty + def load(self, *args, **kwargs): """ load from string or file @@ -373,6 +388,8 @@ class PluggableConfig(object): """ string = args[0] if args else None fromfile = kwargs.get("fromfile", None) + mtime = kwargs.pop("mtime", None) + self.mtime = mtime content = None # start with defaults, so we can -- cgit v1.2.3 From 04d423e2a89034dfb86fe305108162fd2a696079 Mon Sep 17 00:00:00 2001 From: kali Date: Wed, 12 Dec 2012 03:29:31 +0900 Subject: tests for openvpn options and make the rest of tests pass after some changes in this branch (dirtyness in config files) --- src/leap/base/config.py | 23 +++++++++++++++++++++-- src/leap/base/tests/test_providers.py | 8 ++++---- 2 files changed, 25 insertions(+), 6 deletions(-) (limited to 'src/leap/base') diff --git a/src/leap/base/config.py b/src/leap/base/config.py index 321fbdcd..b307ad05 100644 --- a/src/leap/base/config.py +++ b/src/leap/base/config.py @@ -126,14 +126,33 @@ class JSONLeapConfig(BaseLeapConfig): # mandatory baseconfig interface - def save(self, to=None): - if self._config.is_dirty(): + def save(self, to=None, force=False): + """ + force param will skip the dirty check. + :type force: bool + """ + # XXX this force=True does not feel to right + # but still have to look for a better way + # of dealing with dirtiness and the + # trick of loading remote config only + # when newer. + + if force: + do_save = True + else: + do_save = self._config.is_dirty() + + if do_save: if to is None: to = self.filename folder, filename = os.path.split(to) if folder and not os.path.isdir(folder): mkdir_p(folder) self._config.serialize(to) + return True + + else: + return False def load(self, fromfile=None, from_uri=None, fetcher=None, force_download=False, verify=False): diff --git a/src/leap/base/tests/test_providers.py b/src/leap/base/tests/test_providers.py index 15c4ed58..d9604fab 100644 --- a/src/leap/base/tests/test_providers.py +++ b/src/leap/base/tests/test_providers.py @@ -8,7 +8,7 @@ import os import jsonschema -from leap import __branding as BRANDING +#from leap import __branding as BRANDING from leap.testing.basetest import BaseLeapTest from leap.base import providers @@ -33,8 +33,8 @@ class TestLeapProviderDefinition(BaseLeapTest): self.domain = "testprovider.example.org" self.definition = providers.LeapProviderDefinition( domain=self.domain) - self.definition.save() - self.definition.load() + self.definition.save(force=True) + self.definition.load() # why have to load after save?? self.config = self.definition.config def tearDown(self): @@ -61,7 +61,7 @@ class TestLeapProviderDefinition(BaseLeapTest): def test_provider_dump(self): # check a good provider definition is dumped to disk self.testfile = self.get_tempfile('test.json') - self.definition.save(to=self.testfile) + self.definition.save(to=self.testfile, force=True) deserialized = json.load(open(self.testfile, 'rb')) self.maxDiff = None self.assertEqual(deserialized, EXPECTED_DEFAULT_CONFIG) -- cgit v1.2.3 From ff6d4b8633edc763f22489030766a6c7a9377693 Mon Sep 17 00:00:00 2001 From: kali Date: Fri, 30 Nov 2012 04:46:55 +0900 Subject: progress initial tests --- src/leap/base/pluggableconfig.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/leap/base') diff --git a/src/leap/base/pluggableconfig.py b/src/leap/base/pluggableconfig.py index 34c1e060..0ca985ea 100644 --- a/src/leap/base/pluggableconfig.py +++ b/src/leap/base/pluggableconfig.py @@ -419,7 +419,8 @@ class PluggableConfig(object): return True -def testmain(): +def testmain(): # pragma: no cover + from tests import test_validation as t import pprint -- cgit v1.2.3 From 4984f2c966d11f529a2a8b722814b748b6a524d2 Mon Sep 17 00:00:00 2001 From: kali Date: Wed, 12 Dec 2012 09:16:53 +0900 Subject: changed some values in new style eipconfig --- src/leap/base/auth.py | 6 +++--- src/leap/base/specs.py | 16 ++++++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) (limited to 'src/leap/base') diff --git a/src/leap/base/auth.py b/src/leap/base/auth.py index 73856bb0..56b7cf96 100644 --- a/src/leap/base/auth.py +++ b/src/leap/base/auth.py @@ -43,7 +43,7 @@ class LeapSRPRegister(object): def __init__(self, schema="https", provider=None, - port=None, + #port=None, verify=True, register_path="1/users.json", method="POST", @@ -57,8 +57,8 @@ class LeapSRPRegister(object): self.schema = schema # XXX FIXME - self.provider = provider - self.port = port + #self.provider = provider + #self.port = port # XXX splitting server,port # deprecate port call. domain, port = get_https_domain_and_port(provider) diff --git a/src/leap/base/specs.py b/src/leap/base/specs.py index b4bb8dcf..962aa07d 100644 --- a/src/leap/base/specs.py +++ b/src/leap/base/specs.py @@ -2,22 +2,26 @@ leap_provider_spec = { 'description': 'provider definition', 'type': 'object', 'properties': { - 'serial': { - 'type': int, - 'default': 1, - 'required': True, - }, + #'serial': { + #'type': int, + #'default': 1, + #'required': True, + #}, 'version': { 'type': unicode, 'default': '0.1.0' #'required': True }, + "default_language": { + 'type': unicode, + 'default': 'en' + }, 'domain': { 'type': unicode, # XXX define uri type 'default': 'testprovider.example.org' #'required': True, }, - 'display_name': { + 'name': { 'type': dict, # XXX multilingual object? 'default': {u'en': u'Test Provider'} #'required': True -- cgit v1.2.3 From 914a07aaf8ef52b2eaf88f1bf01fb6f72adcac5a Mon Sep 17 00:00:00 2001 From: kali Date: Sat, 15 Dec 2012 02:25:12 +0900 Subject: use gnutls to parse pemfiles --- src/leap/base/auth.py | 8 ++++++-- src/leap/base/tests/test_providers.py | 6 ++++-- 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'src/leap/base') diff --git a/src/leap/base/auth.py b/src/leap/base/auth.py index 56b7cf96..c6bd3518 100644 --- a/src/leap/base/auth.py +++ b/src/leap/base/auth.py @@ -255,6 +255,7 @@ class SRPAuth(requests.auth.AuthBase): try: assert self.srp_usr.authenticated() logger.debug('user is authenticated!') + print 'user is authenticated!' except (AssertionError): raise SRPAuthenticationError( "Auth verification failed.") @@ -355,8 +356,11 @@ if __name__ == "__main__": req.raise_for_status return req - req = test_srp_protected_get('https://localhost:8443/1/cert') - print 'cert :', req.content[:200] + "..." + #req = test_srp_protected_get('https://localhost:8443/1/cert') + req = test_srp_protected_get('%s/1/cert' % SERVER) + import ipdb;ipdb.set_trace() + #print 'cert :', req.content[:200] + "..." + print 'cert :', req.content sys.exit(0) if action == "add": diff --git a/src/leap/base/tests/test_providers.py b/src/leap/base/tests/test_providers.py index d9604fab..8801a3eb 100644 --- a/src/leap/base/tests/test_providers.py +++ b/src/leap/base/tests/test_providers.py @@ -16,10 +16,12 @@ from leap.base import providers EXPECTED_DEFAULT_CONFIG = { u"api_version": u"0.1.0", u"description": {u'en': u"Test provider"}, - u"display_name": {u'en': u"Test Provider"}, + u"default_language": u"en", + #u"display_name": {u'en': u"Test Provider"}, u"domain": u"testprovider.example.org", + u'name': {u'en': u'Test Provider'}, u"enrollment_policy": u"open", - u"serial": 1, + #u"serial": 1, u"services": [ u"eip" ], -- cgit v1.2.3 From 0c2275222cf77bf5975a25a75ab0e50ac752bc9e Mon Sep 17 00:00:00 2001 From: kali Date: Mon, 17 Dec 2012 04:35:16 +0900 Subject: fix srp authentication cookies --- src/leap/base/auth.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/leap/base') diff --git a/src/leap/base/auth.py b/src/leap/base/auth.py index c6bd3518..ec854cf0 100644 --- a/src/leap/base/auth.py +++ b/src/leap/base/auth.py @@ -262,7 +262,7 @@ class SRPAuth(requests.auth.AuthBase): def __call__(self, req): self.authenticate() - req.session = self.session + req.cookies = self.session.cookies return req @@ -358,9 +358,8 @@ if __name__ == "__main__": #req = test_srp_protected_get('https://localhost:8443/1/cert') req = test_srp_protected_get('%s/1/cert' % SERVER) - import ipdb;ipdb.set_trace() #print 'cert :', req.content[:200] + "..." - print 'cert :', req.content + print req.content sys.exit(0) if action == "add": -- cgit v1.2.3 From ef3e6f7badf4d477e796f8522b4d79b554f18f93 Mon Sep 17 00:00:00 2001 From: kali Date: Tue, 18 Dec 2012 06:09:57 +0900 Subject: back-compat fix for requests api change --- src/leap/base/config.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/leap/base') diff --git a/src/leap/base/config.py b/src/leap/base/config.py index b307ad05..438d1993 100644 --- a/src/leap/base/config.py +++ b/src/leap/base/config.py @@ -209,7 +209,12 @@ class JSONLeapConfig(BaseLeapConfig): if last_modified: _mtime = dateparser.parse(last_modified) mtime = int(_mtime.strftime("%s")) - self._config.load(json.dumps(request.json), mtime=mtime) + if callable(request.json): + _json = request.json() + else: + # back-compat + _json = request.json + self._config.load(json.dumps(_json), mtime=mtime) self._config.set_dirty() else: # not request.json -- cgit v1.2.3 From 34cdc516cbdef476d0329fff5d09d6eb0e85431f Mon Sep 17 00:00:00 2001 From: kali Date: Tue, 18 Dec 2012 07:17:56 +0900 Subject: freeze requests requirement lower than 1.0 srp auth breaking with 1.0 api --- src/leap/base/auth.py | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'src/leap/base') diff --git a/src/leap/base/auth.py b/src/leap/base/auth.py index ec854cf0..ecc24179 100644 --- a/src/leap/base/auth.py +++ b/src/leap/base/auth.py @@ -142,9 +142,6 @@ class SRPAuth(requests.auth.AuthBase): self.init_srp() - def get_json_data(self, response): - return json.loads(response.content) - def init_srp(self): usr = srp.User( self.username, @@ -175,8 +172,7 @@ class SRPAuth(requests.auth.AuthBase): raise SRPAuthenticationError( "No valid response (salt).") - # XXX should get auth_result.json instead - self.init_data = self.get_json_data(init_session) + self.init_data = init_session.json return self.init_data def get_server_proof_data(self): @@ -194,13 +190,7 @@ class SRPAuth(requests.auth.AuthBase): raise SRPAuthenticationError( "No valid response (HAMK).") - # XXX should get auth_result.json instead - try: - self.auth_data = self.get_json_data(auth_result) - except ValueError: - raise SRPAuthenticationError( - "No valid data sent (HAMK)") - + self.auth_data = auth_result.json return self.auth_data def authenticate(self): -- cgit v1.2.3 From e98c3cc5fad75bea038dc67238e5ce85d701b1e1 Mon Sep 17 00:00:00 2001 From: kali Date: Thu, 20 Dec 2012 02:50:52 +0900 Subject: fix broken tests --- src/leap/base/constants.py | 33 +++++++++++++++++++++------------ src/leap/base/tests/test_providers.py | 3 ++- 2 files changed, 23 insertions(+), 13 deletions(-) (limited to 'src/leap/base') diff --git a/src/leap/base/constants.py b/src/leap/base/constants.py index f7be8d98..b38723be 100644 --- a/src/leap/base/constants.py +++ b/src/leap/base/constants.py @@ -14,18 +14,27 @@ DEFAULT_PROVIDER = __branding.get( DEFINITION_EXPECTED_PATH = "provider.json" DEFAULT_PROVIDER_DEFINITION = { - u'api_uri': u'https://api.%s/' % DEFAULT_PROVIDER, - u'api_version': u'0.1.0', - u'ca_cert_fingerprint': u'8aab80ae4326fd30721689db813733783fe0bd7e', - u'ca_cert_uri': u'https://%s/cacert.pem' % DEFAULT_PROVIDER, - u'description': {u'en': u'This is a test provider'}, - u'display_name': {u'en': u'Test Provider'}, - u'domain': u'%s' % DEFAULT_PROVIDER, - u'enrollment_policy': u'open', - u'public_key': u'cb7dbd679f911e85bc2e51bd44afd7308ee19c21', - u'serial': 1, - u'services': [u'eip'], - u'version': u'0.1.0'} + u"api_uri": "https://api.%s/" % DEFAULT_PROVIDER, + u"api_version": u"1", + u"ca_cert_fingerprint": "SHA256: fff", + u"ca_cert_uri": u"https://%s/ca.crt" % DEFAULT_PROVIDER, + u"default_language": u"en", + u"description": { + u"en": u"A demonstration service provider using the LEAP platform" + }, + u"domain": "%s" % DEFAULT_PROVIDER, + u"enrollment_policy": u"open", + u"languages": [ + u"en" + ], + u"name": { + u"en": u"Test Provider" + }, + u"services": [ + "openvpn" + ] +} + MAX_ICMP_PACKET_LOSS = 10 diff --git a/src/leap/base/tests/test_providers.py b/src/leap/base/tests/test_providers.py index 8801a3eb..9c11f270 100644 --- a/src/leap/base/tests/test_providers.py +++ b/src/leap/base/tests/test_providers.py @@ -90,7 +90,8 @@ class TestLeapProviderDefinition(BaseLeapTest): def test_provider_validation(self): self.definition.validate(self.config) _config = copy.deepcopy(self.config) - _config['serial'] = 'aaa' + # bad type, raise validation error + _config['domain'] = 111 with self.assertRaises(jsonschema.ValidationError): self.definition.validate(_config) -- cgit v1.2.3