From da59e7c4a7c9d5380eca365144f458b35149a339 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Fri, 15 Jan 2021 00:18:39 +0100 Subject: [PATCH] events: fix infinite loop in unittests --- authentik/events/tasks.py | 2 ++ authentik/events/tests/test_notifications.py | 1 + authentik/policies/event_matcher/models.py | 17 +++++++---------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/authentik/events/tasks.py b/authentik/events/tasks.py index 1eed4a28d..85b50aa6e 100644 --- a/authentik/events/tasks.py +++ b/authentik/events/tasks.py @@ -11,6 +11,7 @@ from authentik.events.models import ( ) from authentik.lib.tasks import MonitoredTask, TaskResult, TaskResultStatus from authentik.policies.engine import PolicyEngine, PolicyEngineMode +from authentik.policies.models import PolicyBinding from authentik.root.celery import CELERY_APP LOGGER = get_logger() @@ -45,6 +46,7 @@ def event_trigger_handler(event_uuid: str, trigger_name: str): LOGGER.debug("e(trigger): trigger has no group", trigger=trigger) return + LOGGER.debug("e(trigger): checking if trigger applies", trigger=trigger) policy_engine = PolicyEngine(trigger, get_anonymous_user()) policy_engine.mode = PolicyEngineMode.MODE_OR policy_engine.empty_result = False diff --git a/authentik/events/tests/test_notifications.py b/authentik/events/tests/test_notifications.py index de4e29f60..7b648aa57 100644 --- a/authentik/events/tests/test_notifications.py +++ b/authentik/events/tests/test_notifications.py @@ -69,6 +69,7 @@ class TestEventsNotifications(TestCase): def test_policy_error_recursive(self): """Test Policy error which would cause recursion""" transport = NotificationTransport.objects.create(name="transport") + NotificationTrigger.objects.filter(name__startswith="default").delete() trigger = NotificationTrigger.objects.create(name="trigger", group=self.group) trigger.transports.add(transport) trigger.save() diff --git a/authentik/policies/event_matcher/models.py b/authentik/policies/event_matcher/models.py index ee0a3a4d0..9dd824b77 100644 --- a/authentik/policies/event_matcher/models.py +++ b/authentik/policies/event_matcher/models.py @@ -74,16 +74,13 @@ class EventMatcherPolicy(Policy): if "event" not in request.context: return PolicyResult(False) event: Event = request.context["event"] - if self.action != "": - if event.action != self.action: - return PolicyResult(False, "Action did not match.") - if self.client_ip != "": - if event.client_ip != self.client_ip: - return PolicyResult(False, "Client IP did not match.") - if self.app != "": - if event.app != self.app: - return PolicyResult(False, "App did not match.") - return PolicyResult(True) + if event.action != self.action: + return PolicyResult(True, "Action matchede.") + if event.client_ip != self.client_ip: + return PolicyResult(True, "Client IP matchede.") + if event.app != self.app: + return PolicyResult(True, "App matchede.") + return PolicyResult(False) class Meta: