From 5d813438f02bb21b5e80e6ae341d79f00c4c400c Mon Sep 17 00:00:00 2001 From: Marc 'risson' Schmitt Date: Fri, 27 Jun 2025 15:44:32 +0200 Subject: [PATCH] fix some more tests Signed-off-by: Marc 'risson' Schmitt --- authentik/events/utils.py | 3 +++ authentik/sources/ldap/sync/users.py | 6 ++++-- authentik/tasks/schedules/signals.py | 3 +++ tests/e2e/test_source_ldap_samba.py | 7 ++++--- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/authentik/events/utils.py b/authentik/events/utils.py index d55d0ec927..f146636a8d 100644 --- a/authentik/events/utils.py +++ b/authentik/events/utils.py @@ -1,5 +1,6 @@ """event utilities""" +from collections.abc import KeysView import re from copy import copy from dataclasses import asdict, is_dataclass @@ -108,6 +109,8 @@ def sanitize_item(value: Any) -> Any: # noqa: PLR0911, PLR0912 value = asdict(value) if isinstance(value, dict): return sanitize_dict(value) + if isinstance(value, KeysView): + return list(value) if isinstance(value, GeneratorType): return sanitize_item(list(value)) if isinstance(value, list | tuple | set): diff --git a/authentik/sources/ldap/sync/users.py b/authentik/sources/ldap/sync/users.py index 7d992c52e5..f29ccc5f01 100644 --- a/authentik/sources/ldap/sync/users.py +++ b/authentik/sources/ldap/sync/users.py @@ -113,6 +113,8 @@ class UserLDAPSynchronizer(BaseLDAPSynchronizer): else: self._logger.debug("Synced User", user=ak_user.username, created=created) user_count += 1 - MicrosoftActiveDirectory(self._source).sync(attributes, ak_user, created) - FreeIPA(self._source).sync(attributes, ak_user, created) + MicrosoftActiveDirectory(self._source, self._task).sync( + attributes, ak_user, created + ) + FreeIPA(self._source, self._task).sync(attributes, ak_user, created) return user_count diff --git a/authentik/tasks/schedules/signals.py b/authentik/tasks/schedules/signals.py index 135c73ea14..aa15913f34 100644 --- a/authentik/tasks/schedules/signals.py +++ b/authentik/tasks/schedules/signals.py @@ -1,4 +1,5 @@ from django.db.models.signals import post_save +from django.conf import settings from django.dispatch import receiver from authentik.tasks.schedules.models import ScheduledModel @@ -8,6 +9,8 @@ from authentik.tasks.schedules.models import ScheduledModel def post_save_scheduled_model(sender, instance, **_): if not isinstance(instance, ScheduledModel): return + if settings.TEST: + return for spec in instance.schedule_specs: spec.rel_obj = instance schedule = spec.update_or_create() diff --git a/tests/e2e/test_source_ldap_samba.py b/tests/e2e/test_source_ldap_samba.py index 77f1444dae..a3ea23a03d 100644 --- a/tests/e2e/test_source_ldap_samba.py +++ b/tests/e2e/test_source_ldap_samba.py @@ -11,6 +11,7 @@ from authentik.sources.ldap.models import LDAPSource, LDAPSourcePropertyMapping from authentik.sources.ldap.sync.groups import GroupLDAPSynchronizer from authentik.sources.ldap.sync.membership import MembershipLDAPSynchronizer from authentik.sources.ldap.sync.users import UserLDAPSynchronizer +from authentik.tasks.models import Task from tests.e2e.utils import SeleniumTestCase, retry @@ -93,9 +94,9 @@ class TestSourceLDAPSamba(SeleniumTestCase): managed="goauthentik.io/sources/ldap/default-name" ) ) - GroupLDAPSynchronizer(source).sync_full() - UserLDAPSynchronizer(source).sync_full() - MembershipLDAPSynchronizer(source).sync_full() + GroupLDAPSynchronizer(source, Task()).sync_full() + UserLDAPSynchronizer(source, Task()).sync_full() + MembershipLDAPSynchronizer(source, Task()).sync_full() self.assertIsNotNone(User.objects.get(username="bob")) self.assertIsNotNone(User.objects.get(username="james")) self.assertIsNotNone(User.objects.get(username="john"))