Skip to content

Commit

Permalink
add test for keycloak roles
Browse files Browse the repository at this point in the history
  • Loading branch information
aktech committed Jul 11, 2024
1 parent 6aeaf41 commit 9091168
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/tests_deployment/keycloak_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ def create_keycloak_role(client_name: str, role_name: str, scopes: str, componen
)


def get_keycloak_client_roles(client_name):
keycloak_admin = get_keycloak_admin()
client_details = get_keycloak_client_details_by_name(
client_name=client_name, keycloak_admin=keycloak_admin
)
return keycloak_admin.get_client_roles(client_id=client_details["id"])


def delete_client_keycloak_test_roles(client_name):
keycloak_admin = get_keycloak_admin()
client_details = get_keycloak_client_details_by_name(
Expand Down
11 changes: 11 additions & 0 deletions tests/tests_deployment/test_jupyterhub_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from tests.tests_deployment.keycloak_utils import (
assign_keycloak_client_role_to_user,
create_keycloak_role,
get_keycloak_client_roles,
)
from tests.tests_deployment.utils import create_jupyterhub_token, get_jupyterhub_session

Expand Down Expand Up @@ -43,6 +44,16 @@ def test_default_user_role_scopes():
assert "read:services" in token_scopes


@pytest.mark.filterwarnings(
"ignore:.*auto_refresh_token is deprecated:DeprecationWarning"
)
def test_check_default_roles_added_in_keycloak():
client_roles = get_keycloak_client_roles(client_name="jupyterhub")
role_names = [role["name"] for role in client_roles]
assert "allow-app-sharing-role" in role_names
assert "allow-read-access-to-services-role" in role_names


@pytest.mark.parametrize(
"component,scopes,expected_scopes_difference",
(
Expand Down

0 comments on commit 9091168

Please sign in to comment.