summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xrun_tests.sh2
-rw-r--r--src/leap/crypto/srpauth.py4
-rw-r--r--src/leap/crypto/srpregister.py12
-rwxr-xr-xsrc/leap/crypto/tests/fake_provider.py29
-rw-r--r--src/leap/crypto/tests/test.txt1
-rw-r--r--src/leap/crypto/tests/test_srpregister.py2
6 files changed, 37 insertions, 13 deletions
diff --git a/run_tests.sh b/run_tests.sh
index d11da01a..fccf6b3f 100755
--- a/run_tests.sh
+++ b/run_tests.sh
@@ -93,7 +93,7 @@ function run_tests {
function run_pep8 {
echo "Running pep8 ..."
- srcfiles="src/leap tests"
+ srcfiles="src/leap"
# Just run PEP8 in current environment
pep8_opts="--ignore=E202,W602 --exclude=*_rc.py,ui_*,_version.py --repeat"
${wrapper} pep8 ${pep8_opts} ${srcfiles}
diff --git a/src/leap/crypto/srpauth.py b/src/leap/crypto/srpauth.py
index 027ee0d7..8028a6dc 100644
--- a/src/leap/crypto/srpauth.py
+++ b/src/leap/crypto/srpauth.py
@@ -50,6 +50,7 @@ class SRPAuth(QtCore.QObject):
LOGIN_KEY = "login"
A_KEY = "A"
CLIENT_AUTH_KEY = "client_auth"
+ SESSION_ID_KEY = "_session_id"
def __init__(self, provider_config):
"""
@@ -272,8 +273,7 @@ class SRPAuth(QtCore.QObject):
"failed"))
logger.debug("Session verified.")
- SESSION_ID_KEY = "_session_id"
- session_id = self._session.cookies.get(SESSION_ID_KEY, None)
+ session_id = self._session.cookies.get(self.SESSION_ID_KEY, None)
if not session_id:
logger.error("Bad cookie from server (missing _session_id)")
raise SRPAuthenticationError(self.tr("Session cookie "
diff --git a/src/leap/crypto/srpregister.py b/src/leap/crypto/srpregister.py
index dc137aeb..59aaf257 100644
--- a/src/leap/crypto/srpregister.py
+++ b/src/leap/crypto/srpregister.py
@@ -125,6 +125,7 @@ class SRPRegister(QtCore.QObject):
logger.debug("Will try to register user = %s" % (username,))
logger.debug("user_data => %r" % (user_data,))
+ ok = None
try:
req = self._session.post(uri,
data=user_data,
@@ -134,15 +135,12 @@ class SRPRegister(QtCore.QObject):
except requests.exceptions.SSLError as exc:
logger.error("SSLError: %s" % exc.message)
- _ok = False
req = None
-
+ ok = False
else:
- _ok = req.ok
-
- self.registration_finished.emit(_ok, req)
-
- return _ok
+ ok = req.ok
+ self.registration_finished.emit(ok, req)
+ return ok
if __name__ == "__main__":
diff --git a/src/leap/crypto/tests/fake_provider.py b/src/leap/crypto/tests/fake_provider.py
index d3e05812..d533b82b 100755
--- a/src/leap/crypto/tests/fake_provider.py
+++ b/src/leap/crypto/tests/fake_provider.py
@@ -78,6 +78,9 @@ safe_unhexlify = lambda x: binascii.unhexlify(x) \
class IUser(Interface):
+ """
+ Defines the User Interface
+ """
login = Attribute("User login.")
salt = Attribute("Password salt.")
verifier = Attribute("Password verifier.")
@@ -86,6 +89,10 @@ class IUser(Interface):
class User(object):
+ """
+ User object.
+ We store it in our simple session mocks
+ """
implements(IUser)
@@ -94,20 +101,37 @@ class User(object):
self.salt = salt
self.verifier = verifier
self.session = None
+ self.svr = None
def set_server_verifier(self, svr):
+ """
+ Adds a svr verifier object to this
+ User instance
+ """
self.svr = svr
def set_session(self, session):
+ """
+ Adds this instance of User to the
+ global session dict
+ """
_SESSIONDB[session] = self
self.session = session
class FakeUsers(Resource):
+ """
+ Resource that handles user registration.
+ """
+
def __init__(self, name):
self.name = name
def render_POST(self, request):
+ """
+ Handles POST to the users api resource
+ Simulates a login.
+ """
args = request.args
login = args['user[login]'][0]
@@ -268,11 +292,14 @@ class FakeSession(Resource):
class API_Sessions(Resource):
+ """
+ Top resource for the API v1
+ """
def getChild(self, name, request):
return FakeSession(name)
-class OpenSSLServerContextFactory:
+class OpenSSLServerContextFactory(object):
def getContext(self):
"""
diff --git a/src/leap/crypto/tests/test.txt b/src/leap/crypto/tests/test.txt
deleted file mode 100644
index d6406617..00000000
--- a/src/leap/crypto/tests/test.txt
+++ /dev/null
@@ -1 +0,0 @@
-OK!
diff --git a/src/leap/crypto/tests/test_srpregister.py b/src/leap/crypto/tests/test_srpregister.py
index a59f71cb..5ba7306f 100644
--- a/src/leap/crypto/tests/test_srpregister.py
+++ b/src/leap/crypto/tests/test_srpregister.py
@@ -20,7 +20,7 @@ Tests for:
* leap/crypto/srpauth.py
"""
try:
- import unittest
+ import unittest2 as unittest
except ImportError:
import unittest
import os