summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRuben Pollan <meskio@sindominio.net>2015-08-07 12:50:36 +0200
committerIvan Alejandro <ivanalejandro0@gmail.com>2015-08-07 16:59:51 -0300
commit877e92d8698510b243b32d45e9c46f25e6f04615 (patch)
treef62fc45e08a1c5d8fd3f88f6d8b1613c18991164 /src
parentc063a253a4ea12d19844dcf8d368f8b50789d3f1 (diff)
[test] fix SRP tests
The tests where using deferToThread to run without need, I remove it and now it's easier to debug when one test fails. - Resolves: #7343
Diffstat (limited to 'src')
-rw-r--r--src/leap/bitmask/crypto/srpregister.py5
-rw-r--r--src/leap/bitmask/crypto/tests/test_srpregister.py64
2 files changed, 26 insertions, 43 deletions
diff --git a/src/leap/bitmask/crypto/srpregister.py b/src/leap/bitmask/crypto/srpregister.py
index baa15244..7a216847 100644
--- a/src/leap/bitmask/crypto/srpregister.py
+++ b/src/leap/bitmask/crypto/srpregister.py
@@ -73,8 +73,9 @@ class SRPRegisterImpl:
:param password: password for this username
:type password: str
- :returns: if the registration went ok or not.
- :rtype: bool
+ :returns: if the registration went ok or not, and the returned status
+ code of of the request
+ :rtype: (bool, int)
"""
username = username.lower().encode('utf-8')
diff --git a/src/leap/bitmask/crypto/tests/test_srpregister.py b/src/leap/bitmask/crypto/tests/test_srpregister.py
index 4d6e7be3..c019a60c 100644
--- a/src/leap/bitmask/crypto/tests/test_srpregister.py
+++ b/src/leap/bitmask/crypto/tests/test_srpregister.py
@@ -26,9 +26,8 @@ import os
import sys
from mock import MagicMock
-from nose.twistedtools import reactor, deferred
+from nose.twistedtools import reactor
from twisted.python import log
-from twisted.internet import threads
from leap.bitmask.config.providerconfig import ProviderConfig
from leap.bitmask.crypto import srpregister, srpauth
@@ -111,10 +110,10 @@ class SRPTestCase(unittest.TestCase):
raise ImproperlyConfiguredError(
"Could not load test provider config")
- register = srpregister.SRPRegister(provider_config=provider)
- self.assertEquals(register._port, "443")
+ register = srpregister.SRPRegister(provider_config=provider,
+ register_path="users")
+ self.assertEquals(register._srp_register._port, "443")
- @deferred()
def test_wrong_cert(self):
provider = ProviderConfig()
loaded = provider.load(path=os.path.join(
@@ -129,13 +128,11 @@ class SRPTestCase(unittest.TestCase):
raise ImproperlyConfiguredError(
"Could not load test provider config")
- register = srpregister.SRPRegister(provider_config=provider)
- d = threads.deferToThread(register.register_user, "foouser_firsttime",
- "barpass")
- d.addCallback(self.assertFalse)
- return d
+ register = srpregister.SRPRegister(provider_config=provider,
+ register_path="users")
+ ok = register.register_user("foouser_firsttime", "barpass")
+ self.assertFalse(ok)
- @deferred()
def test_register_user(self):
"""
Checks if the registration of an unused name works as expected when
@@ -143,31 +140,17 @@ class SRPTestCase(unittest.TestCase):
when we request a user that is taken.
"""
# pristine registration
- d = threads.deferToThread(self.register.register_user,
- "foouser_firsttime",
- "barpass")
- d.addCallback(self.assertTrue)
- return d
+ ok = self.register.register_user("foouser_firsttime", "barpass")
+ self.assertTrue(ok)
- @deferred()
def test_second_register_user(self):
# second registration attempt with the same user should return errors
- d = threads.deferToThread(self.register.register_user,
- "foouser_second",
- "barpass")
- d.addCallback(self.assertTrue)
-
- # FIXME currently we are catching this in an upper layer,
- # we could bring the error validation to the SRPRegister class
- def register_wrapper(_):
- return threads.deferToThread(self.register.register_user,
- "foouser_second",
- "barpass")
- d.addCallback(register_wrapper)
- d.addCallback(self.assertFalse)
- return d
-
- @deferred()
+ ok = self.register.register_user("foouser_second", "barpass")
+ self.assertTrue(ok)
+
+ ok = self.register.register_user("foouser_second", "barpass")
+ self.assertFalse(ok)
+
def test_correct_http_uri(self):
"""
Checks that registration autocorrect http uris to https ones.
@@ -187,15 +170,14 @@ class SRPTestCase(unittest.TestCase):
raise ImproperlyConfiguredError(
"Could not load test provider config")
- register = srpregister.SRPRegister(provider_config=provider)
+ register = srpregister.SRPRegister(provider_config=provider,
+ register_path="users")
# ... and we check that we're correctly taking the HTTPS protocol
# instead
- reg_uri = register._get_registration_uri()
+ reg_uri = register._srp_register._get_registration_uri()
self.assertEquals(reg_uri, HTTPS_URI)
- register._get_registration_uri = MagicMock(return_value=HTTPS_URI)
- d = threads.deferToThread(register.register_user, "test_failhttp",
- "barpass")
- d.addCallback(self.assertTrue)
-
- return d
+ register._srp_register._get_registration_uri = MagicMock(
+ return_value=HTTPS_URI)
+ ok = register.register_user("test_failhttp", "barpass")
+ self.assertTrue(ok)