From 0be9c60a71581e97a6b4e72989ce6f829bff3fcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcelo=20Elizeche=20Land=C3=B3?= Date: Tue, 20 May 2025 08:40:43 -0400 Subject: [PATCH] core: bump django-guardian from 2.4.0 to v3.0.0 (#14453) * core: bump django-guardian from 2.4.0 to v3.0.0 * Use GUARDIAN_MONKEY_PATCH_USER instead of deprecated GUARDIAN_MONKEY_PATCH * ??? Signed-off-by: Jens Langhammer * fix issue in outpost tests Signed-off-by: Jens Langhammer * patch all outpost tests Signed-off-by: Jens Langhammer * fixup guardian lock Signed-off-by: Jens Langhammer --------- Signed-off-by: Jens Langhammer Co-authored-by: Jens Langhammer --- authentik/outposts/tests/test_ws.py | 10 ++++++++++ .../0004_alter_ldapprovider_options_and_more.py | 2 -- authentik/root/settings.py | 2 +- pyproject.toml | 2 +- tests/e2e/test_provider_ldap.py | 3 +++ tests/e2e/test_provider_proxy.py | 3 +++ tests/e2e/test_provider_proxy_forward.py | 3 +++ tests/e2e/test_provider_radius.py | 3 +++ uv.lock | 8 ++++---- 9 files changed, 28 insertions(+), 8 deletions(-) diff --git a/authentik/outposts/tests/test_ws.py b/authentik/outposts/tests/test_ws.py index 7ce50eb799..76357f30df 100644 --- a/authentik/outposts/tests/test_ws.py +++ b/authentik/outposts/tests/test_ws.py @@ -1,9 +1,11 @@ """Websocket tests""" from dataclasses import asdict +from unittest.mock import patch from channels.routing import URLRouter from channels.testing import WebsocketCommunicator +from django.contrib.contenttypes.models import ContentType from django.test import TransactionTestCase from authentik import __version__ @@ -14,6 +16,12 @@ from authentik.providers.proxy.models import ProxyProvider from authentik.root import websocket +def patched__get_ct_cached(app_label, codename): + """Caches `ContentType` instances like its `QuerySet` does.""" + return ContentType.objects.get(app_label=app_label, permission__codename=codename) + + +@patch("guardian.shortcuts._get_ct_cached", patched__get_ct_cached) class TestOutpostWS(TransactionTestCase): """Websocket tests""" @@ -38,6 +46,7 @@ class TestOutpostWS(TransactionTestCase): ) connected, _ = await communicator.connect() self.assertFalse(connected) + await communicator.disconnect() async def test_auth_valid(self): """Test auth with token""" @@ -48,6 +57,7 @@ class TestOutpostWS(TransactionTestCase): ) connected, _ = await communicator.connect() self.assertTrue(connected) + await communicator.disconnect() async def test_send(self): """Test sending of Hello""" diff --git a/authentik/providers/ldap/migrations/0004_alter_ldapprovider_options_and_more.py b/authentik/providers/ldap/migrations/0004_alter_ldapprovider_options_and_more.py index 8a29cfc38c..61719657d7 100644 --- a/authentik/providers/ldap/migrations/0004_alter_ldapprovider_options_and_more.py +++ b/authentik/providers/ldap/migrations/0004_alter_ldapprovider_options_and_more.py @@ -7,10 +7,8 @@ from django.db import migrations def migrate_search_group(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): - from authentik.core.models import User from django.apps import apps as real_apps from django.contrib.auth.management import create_permissions - from guardian.shortcuts import UserObjectPermission db_alias = schema_editor.connection.alias diff --git a/authentik/root/settings.py b/authentik/root/settings.py index dd90c2d670..7886d9be10 100644 --- a/authentik/root/settings.py +++ b/authentik/root/settings.py @@ -132,7 +132,7 @@ TENANT_CREATION_FAKES_MIGRATIONS = True TENANT_BASE_SCHEMA = "template" PUBLIC_SCHEMA_NAME = CONFIG.get("postgresql.default_schema") -GUARDIAN_MONKEY_PATCH = False +GUARDIAN_MONKEY_PATCH_USER = False SPECTACULAR_SETTINGS = { "TITLE": "authentik", diff --git a/pyproject.toml b/pyproject.toml index 5497adfefa..f639ecbca0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,7 +17,7 @@ dependencies = [ "django-countries==7.6.1", "django-cte==1.3.3", "django-filter==25.1", - "django-guardian<3.0.0", + "django-guardian==3.0.0", "django-model-utils==5.0.0", "django-pglock==1.7.2", "django-prometheus==2.3.1", diff --git a/tests/e2e/test_provider_ldap.py b/tests/e2e/test_provider_ldap.py index 4eb163797c..06ea7f9685 100644 --- a/tests/e2e/test_provider_ldap.py +++ b/tests/e2e/test_provider_ldap.py @@ -2,6 +2,7 @@ from dataclasses import asdict from time import sleep +from unittest.mock import patch from guardian.shortcuts import assign_perm from ldap3 import ALL, ALL_ATTRIBUTES, ALL_OPERATIONAL_ATTRIBUTES, SUBTREE, Connection, Server @@ -15,10 +16,12 @@ from authentik.flows.models import Flow from authentik.lib.generators import generate_id from authentik.outposts.apps import MANAGED_OUTPOST from authentik.outposts.models import Outpost, OutpostConfig, OutpostType +from authentik.outposts.tests.test_ws import patched__get_ct_cached from authentik.providers.ldap.models import APIAccessMode, LDAPProvider from tests.e2e.utils import SeleniumTestCase, retry +@patch("guardian.shortcuts._get_ct_cached", patched__get_ct_cached) class TestProviderLDAP(SeleniumTestCase): """LDAP and Outpost e2e tests""" diff --git a/tests/e2e/test_provider_proxy.py b/tests/e2e/test_provider_proxy.py index 0ac9300e6f..a5838c401a 100644 --- a/tests/e2e/test_provider_proxy.py +++ b/tests/e2e/test_provider_proxy.py @@ -6,6 +6,7 @@ from json import loads from sys import platform from time import sleep from unittest.case import skip, skipUnless +from unittest.mock import patch from channels.testing import ChannelsLiveServerTestCase from jwt import decode @@ -17,10 +18,12 @@ from authentik.flows.models import Flow from authentik.lib.generators import generate_id from authentik.outposts.models import DockerServiceConnection, Outpost, OutpostConfig, OutpostType from authentik.outposts.tasks import outpost_connection_discovery +from authentik.outposts.tests.test_ws import patched__get_ct_cached from authentik.providers.proxy.models import ProxyProvider from tests.e2e.utils import SeleniumTestCase, retry +@patch("guardian.shortcuts._get_ct_cached", patched__get_ct_cached) class TestProviderProxy(SeleniumTestCase): """Proxy and Outpost e2e tests""" diff --git a/tests/e2e/test_provider_proxy_forward.py b/tests/e2e/test_provider_proxy_forward.py index 8060d8c520..74336bd842 100644 --- a/tests/e2e/test_provider_proxy_forward.py +++ b/tests/e2e/test_provider_proxy_forward.py @@ -4,6 +4,7 @@ from json import loads from pathlib import Path from time import sleep from unittest import skip +from unittest.mock import patch from selenium.webdriver.common.by import By @@ -12,10 +13,12 @@ from authentik.core.models import Application from authentik.flows.models import Flow from authentik.lib.generators import generate_id from authentik.outposts.models import Outpost, OutpostType +from authentik.outposts.tests.test_ws import patched__get_ct_cached from authentik.providers.proxy.models import ProxyMode, ProxyProvider from tests.e2e.utils import SeleniumTestCase, retry +@patch("guardian.shortcuts._get_ct_cached", patched__get_ct_cached) class TestProviderProxyForward(SeleniumTestCase): """Proxy and Outpost e2e tests""" diff --git a/tests/e2e/test_provider_radius.py b/tests/e2e/test_provider_radius.py index 0392a77372..94a73a3bdc 100644 --- a/tests/e2e/test_provider_radius.py +++ b/tests/e2e/test_provider_radius.py @@ -2,6 +2,7 @@ from dataclasses import asdict from time import sleep +from unittest.mock import patch from pyrad.client import Client from pyrad.dictionary import Dictionary @@ -12,10 +13,12 @@ from authentik.core.models import Application, User from authentik.flows.models import Flow from authentik.lib.generators import generate_id, generate_key from authentik.outposts.models import Outpost, OutpostConfig, OutpostType +from authentik.outposts.tests.test_ws import patched__get_ct_cached from authentik.providers.radius.models import RadiusProvider from tests.e2e.utils import SeleniumTestCase, retry +@patch("guardian.shortcuts._get_ct_cached", patched__get_ct_cached) class TestProviderRadius(SeleniumTestCase): """Radius Outpost e2e tests""" diff --git a/uv.lock b/uv.lock index 47cf7c870d..287fbb7997 100644 --- a/uv.lock +++ b/uv.lock @@ -277,7 +277,7 @@ requires-dist = [ { name = "django-countries", specifier = "==7.6.1" }, { name = "django-cte", specifier = "==1.3.3" }, { name = "django-filter", specifier = "==25.1" }, - { name = "django-guardian", specifier = "<3.0.0" }, + { name = "django-guardian", specifier = "==3.0.0" }, { name = "django-model-utils", specifier = "==5.0.0" }, { name = "django-pglock", specifier = "==1.7.2" }, { name = "django-prometheus", specifier = "==2.3.1" }, @@ -1027,14 +1027,14 @@ wheels = [ [[package]] name = "django-guardian" -version = "2.4.0" +version = "3.0.0" source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "django" }, ] -sdist = { url = "https://files.pythonhosted.org/packages/6f/4c/d1f6923a0ad7f16c403a54c09e94acb76ac6c3765e02523fb09b2b03e1a8/django-guardian-2.4.0.tar.gz", hash = "sha256:c58a68ae76922d33e6bdc0e69af1892097838de56e93e78a8361090bcd9f89a0", size = 159008, upload-time = "2021-05-23T22:11:26.23Z" } +sdist = { url = "https://files.pythonhosted.org/packages/30/82/2c76cdf77eae3cb0c3df394686daf8f84bcd604c0da7a26fa19f5fe74ed4/django_guardian-3.0.0.tar.gz", hash = "sha256:0c79d55c4af2cfc14fbd19539846a1ebfed2a38198b7697e0f5177b7f654e1cd", size = 79895, upload-time = "2025-05-07T19:33:23.328Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/a2/25/869df12e544b51f583254aadbba6c1a95e11d2d08edeb9e58dd715112db5/django_guardian-2.4.0-py3-none-any.whl", hash = "sha256:440ca61358427e575323648b25f8384739e54c38b3d655c81d75e0cd0d61b697", size = 106107, upload-time = "2021-05-23T22:11:22.75Z" }, + { url = "https://files.pythonhosted.org/packages/a5/81/a2f3d3245d1f4cf446d78863526fba0b1b140d60784095a5cc2d4e8ac709/django_guardian-3.0.0-py3-none-any.whl", hash = "sha256:f3ebe3cc7f486e267041b780c3429ad5db72c909df40c2f74adb1b059582a3cd", size = 112672, upload-time = "2025-05-07T19:33:21.719Z" }, ] [[package]]