1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-01 16:36:06 +00:00

fix(console): a session that a password change ended opens no console

session_user_id read the user id out of the session row as it was, so a
session cookie that Django no longer accepts (the user's password changed,
or the user was deactivated) still matched a console token of its user in
novncd and socketiod. It now asks django.contrib.auth.get_user, which checks
the session's password hash and that the user may sign in.

The serial console tests built sessions by hand with only the user id;
they now sign in with force_login, as the panel does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea
This commit is contained in:
catborise 2026-11-08 20:47:27 +03:00
parent fe553a2d65
commit 8eb619114c
3 changed files with 25 additions and 10 deletions

View file

@ -262,6 +262,21 @@ class NovncdDaemonLogicTestCase(TestCase):
self.assertIsNone(tokens.session_user_id(f"{settings.SESSION_COOKIE_NAME}={SessionStore().session_key}"))
self.assertIsNone(tokens.session_user_id(None))
def test_a_session_that_a_password_change_or_a_deactivation_ended_names_no_one(self):
user = get_user_model().objects.create_user("vnc-old-session", password="pw")
for change in ({"password": "new"}, {"is_active": False}):
with self.subTest(change=change):
self.client.force_login(user)
cookie = f"{settings.SESSION_COOKIE_NAME}={self.client.session.session_key}"
if "password" in change:
user.set_password(change["password"])
else:
user.is_active = False
user.save()
self.assertIsNone(tokens.session_user_id(cookie))
user.is_active = True
user.save()
def test_a_vnc_session_ends_when_its_user_may_no_longer_open_it(self):
tsock, ended = MagicMock(), MagicMock()
ended.wait.return_value = False # ACCESS_CHECK passed, the session still open