1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 17:36:05 +00:00
webvirtcloud/accounts/tests/test_checks.py
catborise 7359fbb147 fix(accounts): a page whose session ended says so; a form sent then is not lost in a 405
A session that ended while a page was open went unnoticed: the VM list,
the VM page and the job panel kept asking, were sent to the sign-in
page, and showed what they had as if it were current. A button pressed
then sent the user to sign in and, after it, to the form's own address
by GET, where its view answered an empty 405 and the action was lost.

The panel's LoginRequiredMiddleware (webvirtcloud.middleware) answers a
page's script 401, upon which session_end.js says the user was signed
out, with a link to sign in and come back, and the page stops asking
and reloading. A form sent after the end (or with a token a sign-in
elsewhere replaced) goes back, after the sign-in, to the page it was on,
and the sign-in page says it was not done. accounts.E002 asks for this
middleware; Django's own is a warning (W002), so an update keeps a
panel whose local settings name it running.
2026-11-21 23:48:34 +03:00

28 lines
1.2 KiB
Python

from django.conf import settings
from django.test import SimpleTestCase, override_settings
from accounts.checks import login_required_middleware_check
OLD = "login_required.middleware.LoginRequiredMiddleware"
NEW = "webvirtcloud.middleware.LoginRequiredMiddleware"
DJANGO = "django.contrib.auth.middleware.LoginRequiredMiddleware"
class LoginRequiredMiddlewareCheckTestCase(SimpleTestCase):
def ids(self, middleware):
with override_settings(MIDDLEWARE=middleware):
return [e.id for e in login_required_middleware_check(None)]
def test_current_settings_pass(self):
self.assertEqual(self.ids(settings.MIDDLEWARE), [])
def test_settings_from_before_django_5_2_are_rejected(self):
old = [OLD if m == NEW else m for m in settings.MIDDLEWARE]
self.assertEqual(self.ids(old), ["accounts.E002"])
def test_django_s_own_is_warned_of(self):
# it signs in too: an update with it in data/local_settings.py still starts the panel
self.assertEqual(self.ids([DJANGO if m == NEW else m for m in settings.MIDDLEWARE]), ["accounts.W002"])
def test_missing_login_middleware_is_rejected(self):
self.assertEqual(self.ids([m for m in settings.MIDDLEWARE if m != NEW]), ["accounts.E002"])