summaryrefslogtreecommitdiff
path: root/testing/tests/server/test_auth.py
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2017-02-01 19:44:03 -0200
committerKali Kaneko <kali@leap.se>2017-02-09 17:41:43 +0100
commitc9cb1a814b6bfaa40de3c35a590f39d5fb0ce18e (patch)
tree23ea75a31f08df5f0bead3b11d4e68536a32622a /testing/tests/server/test_auth.py
parent911695e59ab60d2abaef3013330a6d41283cc733 (diff)
[test] fix session and auth tests
Diffstat (limited to 'testing/tests/server/test_auth.py')
-rw-r--r--testing/tests/server/test_auth.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/testing/tests/server/test_auth.py b/testing/tests/server/test_auth.py
index 0e6baba3..5b215650 100644
--- a/testing/tests/server/test_auth.py
+++ b/testing/tests/server/test_auth.py
@@ -19,6 +19,8 @@ Tests for auth pieces.
"""
import collections
+from contextlib import contextmanager
+
from twisted.cred.credentials import UsernamePassword
from twisted.cred.error import UnauthorizedLogin
from twisted.internet.defer import inlineCallbacks
@@ -54,13 +56,18 @@ class DummyServer(object):
return self._token
+@contextmanager
+def dummy_server(token):
+ yield collections.defaultdict(lambda: DummyServer(token))
+
+
class TokenCheckerTestCase(unittest.TestCase):
@inlineCallbacks
def test_good_creds(self):
# set up a dummy server which always return a *valid* token document
token = {'user_id': 'user', 'type': 'Token'}
- server = collections.defaultdict(lambda: DummyServer(token))
+ server = dummy_server(token)
# setup the checker with the custom server
checker = TokenChecker(server=server)
# assert the checker *can* verify the creds
@@ -72,7 +79,7 @@ class TokenCheckerTestCase(unittest.TestCase):
def test_bad_creds(self):
# set up a dummy server which always return an *invalid* token document
token = None
- server = collections.defaultdict(lambda: DummyServer(token))
+ server = dummy_server(token)
# setup the checker with the custom server
checker = TokenChecker(server=server)
# assert the checker *cannot* verify the creds