fix: persist preview admin access
This commit is contained in:
@@ -76,6 +76,24 @@ class EnsureSuperuserCommandTests(TestCase):
|
||||
user.refresh_from_db()
|
||||
self.assertTrue(user.check_password("changed-in-admin"))
|
||||
|
||||
def test_existing_user_regains_admin_access_without_password_reset(self):
|
||||
user = get_user_model().objects.create_user(
|
||||
username="admin", email="admin@com2care.com", password="existing-password"
|
||||
)
|
||||
user.is_active = False
|
||||
user.save(update_fields=["is_active"])
|
||||
environment = {
|
||||
"DJANGO_SUPERUSER_USERNAME": "admin",
|
||||
"DJANGO_SUPERUSER_PASSWORD": "different-password",
|
||||
"DJANGO_SUPERUSER_SYNC_PASSWORD": "False",
|
||||
}
|
||||
with patch.dict(os.environ, environment, clear=False):
|
||||
call_command("ensure_superuser", verbosity=0)
|
||||
|
||||
user.refresh_from_db()
|
||||
self.assertTrue(user.is_active and user.is_staff and user.is_superuser)
|
||||
self.assertTrue(user.check_password("existing-password"))
|
||||
|
||||
def test_server_operator_can_explicitly_rotate_password(self):
|
||||
user = get_user_model().objects.create_superuser(
|
||||
username="admin",
|
||||
|
||||
Reference in New Issue
Block a user