summaryrefslogtreecommitdiff
path: root/service/test/unit
diff options
context:
space:
mode:
authorRoald de Vries <rdevries@thoughtworks.com>2016-11-24 10:56:59 +0100
committerRoald de Vries <rdevries@thoughtworks.com>2016-11-24 10:56:59 +0100
commitc39921ef6ba7ed299a125b530b770b0e1ec16203 (patch)
tree3da38e1d699b22f56b84b29b135d20bece73c170 /service/test/unit
parent2884195e96728c0432a8e8d0d2f747ae2baefd06 (diff)
add test for unauthorized resource
Diffstat (limited to 'service/test/unit')
-rw-r--r--service/test/unit/resources/test_auth.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/service/test/unit/resources/test_auth.py b/service/test/unit/resources/test_auth.py
index adff1083..80f1ebb0 100644
--- a/service/test/unit/resources/test_auth.py
+++ b/service/test/unit/resources/test_auth.py
@@ -3,9 +3,12 @@ from pixelated.resources.auth import PixelatedAuthSessionWrapper
from pixelated.resources.login_resource import LoginResource
from pixelated.resources.root_resource import RootResource
from test.unit.resources import DummySite
+from twisted.cred import error
from twisted.cred.checkers import ANONYMOUS
-from twisted.internet.defer import succeed
+from twisted.internet.defer import succeed, fail
+from twisted.python import failure
from twisted.trial import unittest
+from twisted.web._auth.wrapper import UnauthorizedResource
from twisted.web.resource import IResource
from twisted.web.test.requesthelper import DummyRequest
@@ -47,3 +50,15 @@ class TestPixelatedAuthSessionWrapper(unittest.TestCase):
d.addCallback(assert_root_resource)
return d
+
+ def test_should_proxy_to_unauthorized_resource_when_login_fails(self):
+ when(self.portal_mock).login(ANY(), None, IResource).thenReturn(fail(failure.Failure(error.UnhandledCredentials('dummy message'))))
+
+ deferred_resource = self.session_wrapper.getChildWithDefault('/', self.request)
+ d = deferred_resource.d
+
+ def assert_unauthorized_resource(resource):
+ self.assertIsInstance(resource, UnauthorizedResource)
+
+ d.addCallback(assert_unauthorized_resource)
+ return d