Skip to content

Commit

Permalink
[IMP] auth_oidc: test possible token values more extensively
Browse files Browse the repository at this point in the history
  • Loading branch information
OdyX committed Feb 12, 2025
1 parent cf144d0 commit cc0e726
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions auth_oidc/tests/test_auth_oidc_auth_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,23 @@ def test_login_with_jwk_format(self):
self.assertEqual(token, "122/3")
self.assertEqual(login, user.login)

def test_group_expression(self):
"""Test that group expressions evaluate correctly"""
def test_group_expression_empty_token(self):
"""Test that group expression with an empty token evaluate correctly"""
group_line = self.env.ref("auth_oidc.local_keycloak").group_line_ids[:1]
group_line.expression = 'token["test"]["test"] == 1'
self.assertFalse(group_line._eval_expression(self.env.user, {}))

def test_group_expressions_with_token(self):
"""Test that group expression with token with groups evaluate correctly"""
group_line = self.env.ref("auth_oidc.local_keycloak").group_line_ids[:1]

group_line.expression = "'group-a' in token['groups']"
self.assertFalse(group_line._eval_expression(self.env.user, {}))
self.assertTrue(
group_line._eval_expression(
self.env.user, {"groups": ["group-a", "group-b"]}
)
)
self.assertFalse(
group_line._eval_expression(self.env.user, {"groups": ["group-c"]})
)

0 comments on commit cc0e726

Please sign in to comment.