Skip to content

Commit

Permalink
Add a couple of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yuvipanda committed May 2, 2024
1 parent db9b5a1 commit 8eb9304
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions oauthenticator/tests/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,35 @@ async def test_generic_claim_groups_key_nested_strings(
assert auth_model["admin"]


async def test_generic_auth_model_groups_key_callable(get_authenticator, generic_client):
c = Config()
c.GenericOAuthenticator.auth_model_groups_key = lambda r: r["auth_state"]["oauth_user"]["policies"]["roles"]
c.GenericOAuthenticator.allowed_groups = ["super_user"]
authenticator = get_authenticator(config=c)

handled_user_model = user_model("user1", policies={"roles": ["super_user"]})
handler = generic_client.handler_for_user(handled_user_model)
auth_model = await authenticator.get_authenticated_user(handler, None)

assert auth_model


async def test_generic_auth_model_groups_key_nested_strings(
get_authenticator, generic_client
):
c = Config()
c.GenericOAuthenticator.auth_model_groups_key = "auth_state.oauth_user.permissions.groups"
c.GenericOAuthenticator.admin_groups = ["super_user"]
authenticator = get_authenticator(config=c)

handled_user_model = user_model("user1", permissions={"groups": ["super_user"]})
handler = generic_client.handler_for_user(handled_user_model)
auth_model = await authenticator.get_authenticated_user(handler, None)

assert auth_model
assert auth_model["admin"]


@mark.parametrize(
"name, allowed",
[
Expand Down

0 comments on commit 8eb9304

Please sign in to comment.