summaryrefslogtreecommitdiff
path: root/testing/tests/server/test_session.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_session.py
parent911695e59ab60d2abaef3013330a6d41283cc733 (diff)
[test] fix session and auth tests
Diffstat (limited to 'testing/tests/server/test_session.py')
-rw-r--r--testing/tests/server/test_session.py45
1 files changed, 10 insertions, 35 deletions
diff --git a/testing/tests/server/test_session.py b/testing/tests/server/test_session.py
index 7883ef4a..8131ddb3 100644
--- a/testing/tests/server/test_session.py
+++ b/testing/tests/server/test_session.py
@@ -17,24 +17,20 @@
"""
Tests for server session entrypoint.
"""
-from twisted.cred.checkers import InMemoryUsernamePasswordDatabaseDontUse
+from twisted.trial import unittest
+
from twisted.cred import portal
+from twisted.cred.checkers import InMemoryUsernamePasswordDatabaseDontUse
+from twisted.cred.credentials import IUsernamePassword
+from twisted.web.resource import getChildForRequest
+from twisted.web.static import Data
+from twisted.web.test.requesthelper import DummyRequest
from twisted.web.test.test_httpauth import b64encode
from twisted.web.test.test_httpauth import Realm
-from twisted.web.test.requesthelper import DummyRequest
-from twisted.web.resource import getChildForRequest
-
-from twisted.web.resource import Resource
-
-from twisted.trial import unittest
+from twisted.web._auth.wrapper import UnauthorizedResource
from leap.soledad.server.session import SoledadSession
-from twisted.web.static import Data
-from twisted.web._auth.wrapper import UnauthorizedResource
-from twisted.cred.credentials import IUsernamePassword
-from twisted.cred.checkers import ANONYMOUS, AllowAnonymousAccess
-
class SoledadSessionTestCase(unittest.TestCase):
"""
@@ -168,6 +164,7 @@ class SoledadSessionTestCase(unittest.TestCase):
child = getChildForRequest(self.wrapper, request)
request.render(child)
self.assertEqual(request.responseCode, 500)
+ self.assertEqual(len(self.flushLoggedErrors(UnexpectedException)), 1)
def test_unexpectedLoginError(self):
class UnexpectedException(Exception):
@@ -184,26 +181,4 @@ class SoledadSessionTestCase(unittest.TestCase):
child = self._authorizedTokenLogin(request)
request.render(child)
self.assertEqual(request.responseCode, 500)
-
- def test_anonymousAccess(self):
- """
- Anonymous requests are allowed if a L{Portal} has an anonymous checker
- registered.
- """
- unprotectedContents = b"contents of the unprotected child resource"
-
- self.avatars[ANONYMOUS] = Resource()
- self.avatars[ANONYMOUS].putChild(
- self.childName, Data(unprotectedContents, 'text/plain'))
- self.portal.registerChecker(AllowAnonymousAccess())
-
- request = self.makeRequest([self.childName])
- child = getChildForRequest(self.wrapper, request)
- d = request.notifyFinish()
-
- def cbFinished(ignored):
- self.assertEqual(request.written, [unprotectedContents])
-
- d.addCallback(cbFinished)
- request.render(child)
- return d
+ self.assertEqual(len(self.flushLoggedErrors(UnexpectedException)), 1)