diff --git a/horizon/dashboards/nova/overview/tests.py b/horizon/dashboards/nova/overview/tests.py index 36d924bbec..9dcf470abb 100644 --- a/horizon/dashboards/nova/overview/tests.py +++ b/horizon/dashboards/nova/overview/tests.py @@ -49,6 +49,20 @@ class UsageViewTests(test.TestCase): self.assertTrue(isinstance(res.context['usage'], usage.TenantUsage)) self.assertContains(res, 'form-horizontal') + def test_unauthorized(self): + exc = self.exceptions.keystone_unauthorized + now = timezone.now() + self.mox.StubOutWithMock(api, 'usage_get') + api.usage_get(IsA(http.HttpRequest), self.tenant.id, + datetime.datetime(now.year, now.month, 1, 0, 0, 0), + Func(usage.almost_now)) \ + .AndRaise(exc) + self.mox.ReplayAll() + + url = reverse('horizon:nova:overview:index') + res = self.client.get(url) + self.assertRedirects(res, reverse("login") + "?next=" + url) + def test_usage_csv(self): now = timezone.now() usage_obj = api.nova.Usage(self.usages.first()) diff --git a/horizon/exceptions.py b/horizon/exceptions.py index f31455bb2a..18303e9f97 100644 --- a/horizon/exceptions.py +++ b/horizon/exceptions.py @@ -23,6 +23,7 @@ import os import sys from django.conf import settings +from django.contrib.auth import logout from django.http import HttpRequest from django.utils import termcolors from django.utils.translation import ugettext as _ @@ -260,7 +261,7 @@ def handle(request, message=None, redirect=None, ignore=False, if issubclass(exc_type, UNAUTHORIZED): if ignore: return NotAuthorized - request.user_logout() + logout(request) if not force_silence and not handled: log_method(error_color("Unauthorized: %s" % exc_value)) if not handled: diff --git a/horizon/tests/test_data/exceptions.py b/horizon/tests/test_data/exceptions.py index a5a856dec8..93009edeeb 100644 --- a/horizon/tests/test_data/exceptions.py +++ b/horizon/tests/test_data/exceptions.py @@ -23,6 +23,10 @@ def data(TEST): TEST.exceptions = TestDataContainer() msg = "Expected failure." + keystone_unauthorized = keystone_exceptions.Unauthorized(401) + keystone_unauthorized.silence_logging = True + TEST.exceptions.keystone_unauthorized = keystone_unauthorized + keystone_exception = keystone_exceptions.ClientException(500, message=msg) keystone_exception.silence_logging = True TEST.exceptions.keystone = keystone_exception