From c39921ef6ba7ed299a125b530b770b0e1ec16203 Mon Sep 17 00:00:00 2001 From: Roald de Vries Date: Thu, 24 Nov 2016 10:56:59 +0100 Subject: add test for unauthorized resource --- service/test/unit/resources/test_auth.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'service/test/unit') 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 -- cgit v1.2.3