events: fix infinite loop in unittests
This commit is contained in:
parent
8684d106d5
commit
da59e7c4a7
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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 != "":
|
||||
return PolicyResult(True, "Action matchede.")
|
||||
if event.client_ip != self.client_ip:
|
||||
return PolicyResult(False, "Client IP did not match.")
|
||||
if self.app != "":
|
||||
return PolicyResult(True, "Client IP matchede.")
|
||||
if event.app != self.app:
|
||||
return PolicyResult(False, "App did not match.")
|
||||
return PolicyResult(True)
|
||||
return PolicyResult(True, "App matchede.")
|
||||
return PolicyResult(False)
|
||||
|
||||
class Meta:
|
||||
|
||||
|
|
Reference in New Issue