1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-01 08:26:03 +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

@ -11,8 +11,7 @@ from unittest.mock import patch
from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.sessions.backends.db import SessionStore
from django.test import TestCase, override_settings
from django.test import Client, TestCase, override_settings
from accounts.models import UserInstance
from computes.models import Compute
@ -38,10 +37,9 @@ class Base(TestCase):
def signed_in(self, user=None):
"""The environ of a request with a session of user (the owner)."""
session = SessionStore()
session["_auth_user_id"] = str((user or self.user).pk)
session.create()
return {"HTTP_COOKIE": f"{settings.SESSION_COOKIE_NAME}={session.session_key}"}
client = Client()
client.force_login(user or self.user)
return {"HTTP_COOKIE": f"{settings.SESSION_COOKIE_NAME}={client.session.session_key}"}
def token(self, user=None, vm=None):
vm = vm or self.vm