1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-11 12:46:49 +00:00

test(migrate): the worker refuses a migration whose user may no longer migrate

The worker checks again, before it migrates, that the job's user is
still an active superuser; no test removed either while the job was
queued, so the check could go unnoticed, as it is tested for clones and
new VMs.

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:53:45 +03:00
parent 9a4a201dac
commit 6dab3b210c

View file

@ -5,6 +5,7 @@ from types import SimpleNamespace
from unittest.mock import MagicMock, patch
from django.contrib.auth import get_user_model
from django.core.exceptions import PermissionDenied
from django.test import TransactionTestCase
from django.urls import reverse
@ -67,6 +68,15 @@ class MigrateJobTestCase(TransactionTestCase):
self.vm.refresh_from_db()
self.assertEqual(self.vm.compute, self.dest)
def test_the_worker_refuses_a_migration_whose_user_may_no_longer_migrate(self):
op = self.queue(live_migrate="true")
for change in ({"is_superuser": False}, {"is_active": False}):
with self.subTest(change=change):
get_user_model().objects.filter(pk=op.user_id).update(**{"is_superuser": True, "is_active": True, **change})
op.refresh_from_db()
with self.assertRaises(PermissionDenied):
MigrateInstance().precheck(op, None)
def test_recovery_reads_where_the_vm_is(self):
op = Operation(params={"instance": self.vm.pk, "target": self.dest.pk},
intent={"compute": self.source.pk, "uuid": UUID})