1ccf6dcf6f
* events: initial alerting implementation * policies: move error handling to process, ensure policy UUID is saved * policies: add tests for error handling in PolicyProcess * events: improve loop detection * events: add API for action and trigger * policies: ensure http_request is not used in context * events: adjust unittests for user handling * policies/event_matcher: add policy type * events: add API tests * events: add middleware tests * core: make application's provider not required * outposts: allow blank kubeconfig * outposts: validate kubeconfig before saving * api: fix formatting * stages/invitation: remove invitation_created signal as model_created functions the same * stages/invitation: ensure created_by is set when creating from API * events: rebase migrations on master * events: fix missing Alerts from API * policies: fix unittests * events: add tests for alerts * events: rename from alerting to notifications * events: add ability to specify severity of notification created * policies/event_matcher: Add app field to match on event app * policies/event_matcher: fix EventMatcher not being included in API * core: use objects.none() when get_queryset is used * events: use m2m for multiple transports, create notification object in task * events: add default triggers * events: fix migrations return value * events: fix notification_transport not being in the correct queue * stages/email: allow sending of email without backend * events: implement sending via webhook + slack/discord + email
45 lines
1.8 KiB
Python
45 lines
1.8 KiB
Python
"""event tests"""
|
|
|
|
from django.contrib.contenttypes.models import ContentType
|
|
from django.test import TestCase
|
|
from guardian.shortcuts import get_anonymous_user
|
|
|
|
from authentik.core.models import Group
|
|
from authentik.events.models import Event
|
|
from authentik.policies.dummy.models import DummyPolicy
|
|
|
|
|
|
class TestEvents(TestCase):
|
|
"""Test Event"""
|
|
|
|
def test_new_with_model(self):
|
|
"""Create a new Event passing a model as kwarg"""
|
|
test_model = Group.objects.create(name="test")
|
|
event = Event.new("unittest", test={"model": test_model})
|
|
event.save() # We save to ensure nothing is un-saveable
|
|
model_content_type = ContentType.objects.get_for_model(test_model)
|
|
self.assertEqual(
|
|
event.context.get("test").get("model").get("app"),
|
|
model_content_type.app_label,
|
|
)
|
|
|
|
def test_new_with_user(self):
|
|
"""Create a new Event passing a user as kwarg"""
|
|
event = Event.new("unittest", test={"model": get_anonymous_user()})
|
|
event.save() # We save to ensure nothing is un-saveable
|
|
self.assertEqual(
|
|
event.context.get("test").get("model").get("username"),
|
|
get_anonymous_user().username,
|
|
)
|
|
|
|
def test_new_with_uuid_model(self):
|
|
"""Create a new Event passing a model (with UUID PK) as kwarg"""
|
|
temp_model = DummyPolicy.objects.create(name="test", result=True)
|
|
event = Event.new("unittest", model=temp_model)
|
|
event.save() # We save to ensure nothing is un-saveable
|
|
model_content_type = ContentType.objects.get_for_model(temp_model)
|
|
self.assertEqual(
|
|
event.context.get("model").get("app"), model_content_type.app_label
|
|
)
|
|
self.assertEqual(event.context.get("model").get("pk"), temp_model.pk.hex)
|