From 6dab3b210cf7929c1a6888d06168aa29b98a32e2 Mon Sep 17 00:00:00 2001 From: catborise Date: Sun, 8 Nov 2026 20:53:45 +0300 Subject: [PATCH] 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 Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea --- instances/tests/test_migrate_job.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/instances/tests/test_migrate_job.py b/instances/tests/test_migrate_job.py index f7822c6a..41193446 100644 --- a/instances/tests/test_migrate_job.py +++ b/instances/tests/test_migrate_job.py @@ -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})