Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Jens Langhammer <[email protected]>
  • Loading branch information
BeryJu committed Nov 25, 2024
1 parent 24eb2ae commit 281fc44
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
13 changes: 11 additions & 2 deletions authentik/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,19 @@ def app_entitlements(self, app: "Application | None") -> QuerySet["ApplicationEn
if not app:
return []

Check warning on line 320 in authentik/core/models.py

View check run for this annotation

Codecov / codecov/patch

authentik/core/models.py#L320

Added line #L320 was not covered by tests
all_groups = self.all_groups()
return app.applicationentitlement_set.filter(
Q(bindings__user=self) | Q(bindings__group__in=all_groups),
qs = app.applicationentitlement_set.filter(
Q(
Q(bindings__user=self) | Q(bindings__group__in=all_groups),
bindings__negate=False,
)
| Q(
Q(~Q(bindings__user=self), bindings__user__isnull=False)
| Q(~Q(bindings__group__in=all_groups), bindings__group__isnull=False),
bindings__negate=True,
),
bindings__enabled=True,
)
return qs

@property
def serializer(self) -> Serializer:
Expand Down
20 changes: 17 additions & 3 deletions authentik/core/tests/test_application_entitlements.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,13 @@ def setUp(self) -> None:
self.other_user = create_test_user()
self.provider = OAuth2Provider.objects.create(

Check warning on line 18 in authentik/core/tests/test_application_entitlements.py

View check run for this annotation

Codecov / codecov/patch

authentik/core/tests/test_application_entitlements.py#L15-L18

Added lines #L15 - L18 were not covered by tests
name="test",
redirect_uris="http://some-other-domain",
authorization_flow=create_test_flow(),
)
self.app: Application = Application.objects.create(

Check warning on line 22 in authentik/core/tests/test_application_entitlements.py

View check run for this annotation

Codecov / codecov/patch

authentik/core/tests/test_application_entitlements.py#L22

Added line #L22 was not covered by tests
name=generate_id(),
slug=generate_id(),
provider=self.provider,
)
ent = ApplicationEntitlement.objects.create(app=self.app, name=generate_id())
PolicyBinding.objects.create(target=ent, user=self.other_user, order=0)

def test_user(self):

Check warning on line 28 in authentik/core/tests/test_application_entitlements.py

View check run for this annotation

Codecov / codecov/patch

authentik/core/tests/test_application_entitlements.py#L28

Added line #L28 was not covered by tests
"""Test user-direct assignment"""
Expand Down Expand Up @@ -56,3 +53,20 @@ def test_group_indirect(self):
ents = self.user.app_entitlements(self.app)
self.assertEqual(len(ents), 1)
self.assertEqual(ents[0].name, ent.name)

Check warning on line 55 in authentik/core/tests/test_application_entitlements.py

View check run for this annotation

Codecov / codecov/patch

authentik/core/tests/test_application_entitlements.py#L48-L55

Added lines #L48 - L55 were not covered by tests

def test_negate_user(self):

Check warning on line 57 in authentik/core/tests/test_application_entitlements.py

View check run for this annotation

Codecov / codecov/patch

authentik/core/tests/test_application_entitlements.py#L57

Added line #L57 was not covered by tests
"""Test with negate flag"""
ent = ApplicationEntitlement.objects.create(app=self.app, name=generate_id())
PolicyBinding.objects.create(target=ent, user=self.other_user, order=0, negate=True)
ents = self.user.app_entitlements(self.app)
self.assertEqual(len(ents), 1)
self.assertEqual(ents[0].name, ent.name)

Check warning on line 63 in authentik/core/tests/test_application_entitlements.py

View check run for this annotation

Codecov / codecov/patch

authentik/core/tests/test_application_entitlements.py#L59-L63

Added lines #L59 - L63 were not covered by tests

def test_negate_group(self):

Check warning on line 65 in authentik/core/tests/test_application_entitlements.py

View check run for this annotation

Codecov / codecov/patch

authentik/core/tests/test_application_entitlements.py#L65

Added line #L65 was not covered by tests
"""Test with negate flag"""
other_group = Group.objects.create(name=generate_id())
ent = ApplicationEntitlement.objects.create(app=self.app, name=generate_id())
PolicyBinding.objects.create(target=ent, group=other_group, order=0, negate=True)
ents = self.user.app_entitlements(self.app)
self.assertEqual(len(ents), 1)
self.assertEqual(ents[0].name, ent.name)

Check warning on line 72 in authentik/core/tests/test_application_entitlements.py

View check run for this annotation

Codecov / codecov/patch

authentik/core/tests/test_application_entitlements.py#L67-L72

Added lines #L67 - L72 were not covered by tests

0 comments on commit 281fc44

Please sign in to comment.