events: fix infinite loop in unittests

This commit is contained in:
Jens Langhammer 2021-01-15 00:18:39 +01:00
parent 8684d106d5
commit da59e7c4a7
3 changed files with 10 additions and 10 deletions

View file

@ -11,6 +11,7 @@ from authentik.events.models import (
) )
from authentik.lib.tasks import MonitoredTask, TaskResult, TaskResultStatus from authentik.lib.tasks import MonitoredTask, TaskResult, TaskResultStatus
from authentik.policies.engine import PolicyEngine, PolicyEngineMode from authentik.policies.engine import PolicyEngine, PolicyEngineMode
from authentik.policies.models import PolicyBinding
from authentik.root.celery import CELERY_APP from authentik.root.celery import CELERY_APP
LOGGER = get_logger() 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) LOGGER.debug("e(trigger): trigger has no group", trigger=trigger)
return return
LOGGER.debug("e(trigger): checking if trigger applies", trigger=trigger)
policy_engine = PolicyEngine(trigger, get_anonymous_user()) policy_engine = PolicyEngine(trigger, get_anonymous_user())
policy_engine.mode = PolicyEngineMode.MODE_OR policy_engine.mode = PolicyEngineMode.MODE_OR
policy_engine.empty_result = False policy_engine.empty_result = False

View file

@ -69,6 +69,7 @@ class TestEventsNotifications(TestCase):
def test_policy_error_recursive(self): def test_policy_error_recursive(self):
"""Test Policy error which would cause recursion""" """Test Policy error which would cause recursion"""
transport = NotificationTransport.objects.create(name="transport") transport = NotificationTransport.objects.create(name="transport")
NotificationTrigger.objects.filter(name__startswith="default").delete()
trigger = NotificationTrigger.objects.create(name="trigger", group=self.group) trigger = NotificationTrigger.objects.create(name="trigger", group=self.group)
trigger.transports.add(transport) trigger.transports.add(transport)
trigger.save() trigger.save()

View file

@ -74,16 +74,13 @@ class EventMatcherPolicy(Policy):
if "event" not in request.context: if "event" not in request.context:
return PolicyResult(False) return PolicyResult(False)
event: Event = request.context["event"] event: Event = request.context["event"]
if self.action != "": if event.action != self.action:
if event.action != self.action: return PolicyResult(True, "Action matchede.")
return PolicyResult(False, "Action did not match.") if event.client_ip != self.client_ip:
if self.client_ip != "": return PolicyResult(True, "Client IP matchede.")
if event.client_ip != self.client_ip: if event.app != self.app:
return PolicyResult(False, "Client IP did not match.") return PolicyResult(True, "App matchede.")
if self.app != "": return PolicyResult(False)
if event.app != self.app:
return PolicyResult(False, "App did not match.")
return PolicyResult(True)
class Meta: class Meta: