Skip to content

Commit

Permalink
policies/event_matcher: fix inconsistent behaviour (#11724)
Browse files Browse the repository at this point in the history
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
  • Loading branch information
BeryJu authored Oct 18, 2024
1 parent 8a2ba1c commit 4888d51
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion authentik/policies/event_matcher/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def passes(self, request: PolicyRequest) -> PolicyResult:
result=result,
)
matches.append(result)
passing = any(x.passing for x in matches)
passing = all(x.passing for x in matches)

Check warning on line 111 in authentik/policies/event_matcher/models.py

View check run for this annotation

Codecov / codecov/patch

authentik/policies/event_matcher/models.py#L111

Added line #L111 was not covered by tests
messages = chain(*[x.messages for x in matches])
result = PolicyResult(passing, *messages)
result.source_results = matches
Expand Down
15 changes: 14 additions & 1 deletion authentik/policies/event_matcher/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,24 @@ def test_drop_multiple(self):
request = PolicyRequest(get_anonymous_user())
request.context["event"] = event
policy: EventMatcherPolicy = EventMatcherPolicy.objects.create(
client_ip="1.2.3.5", app="bar"
client_ip="1.2.3.5", app="foo"
)
response = policy.passes(request)
self.assertFalse(response.passing)

def test_multiple(self):

Check warning on line 85 in authentik/policies/event_matcher/tests.py

View check run for this annotation

Codecov / codecov/patch

authentik/policies/event_matcher/tests.py#L85

Added line #L85 was not covered by tests
"""Test multiple"""
event = Event.new(EventAction.LOGIN)
event.app = "foo"
event.client_ip = "1.2.3.4"
request = PolicyRequest(get_anonymous_user())
request.context["event"] = event
policy: EventMatcherPolicy = EventMatcherPolicy.objects.create(

Check warning on line 92 in authentik/policies/event_matcher/tests.py

View check run for this annotation

Codecov / codecov/patch

authentik/policies/event_matcher/tests.py#L87-L92

Added lines #L87 - L92 were not covered by tests
client_ip="1.2.3.4", app="foo"
)
response = policy.passes(request)
self.assertTrue(response.passing)

Check warning on line 96 in authentik/policies/event_matcher/tests.py

View check run for this annotation

Codecov / codecov/patch

authentik/policies/event_matcher/tests.py#L95-L96

Added lines #L95 - L96 were not covered by tests

def test_invalid(self):
"""Test passing event"""
request = PolicyRequest(get_anonymous_user())
Expand Down

0 comments on commit 4888d51

Please sign in to comment.