From 90911684a319f9223d0972bb474f8bb64f6fd454 Mon Sep 17 00:00:00 2001 From: Amit Kumar Date: Thu, 11 Jul 2024 14:48:26 +0100 Subject: [PATCH] add test for keycloak roles --- tests/tests_deployment/keycloak_utils.py | 8 ++++++++ tests/tests_deployment/test_jupyterhub_api.py | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/tests/tests_deployment/keycloak_utils.py b/tests/tests_deployment/keycloak_utils.py index 6e6f6c21e..b11c64b93 100644 --- a/tests/tests_deployment/keycloak_utils.py +++ b/tests/tests_deployment/keycloak_utils.py @@ -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( diff --git a/tests/tests_deployment/test_jupyterhub_api.py b/tests/tests_deployment/test_jupyterhub_api.py index fef6fe28a..f7a145479 100644 --- a/tests/tests_deployment/test_jupyterhub_api.py +++ b/tests/tests_deployment/test_jupyterhub_api.py @@ -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 @@ -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", (