diff --git a/swh/auth/tests/conftest.py b/swh/auth/tests/conftest.py index d34c344d4c3b0d9860c5b4f1a44e5cdababfe668..a89e3ebc4e86280eaf8fa3eb200964b8f508a409 100644 --- a/swh/auth/tests/conftest.py +++ b/swh/auth/tests/conftest.py @@ -7,7 +7,7 @@ import pytest from swh.auth import KeycloakOpenIDConnect -from .sample_data import OIDC_PROFILE, REALM, SERVER_URL, WELL_KNOWN +from .sample_data import OIDC_PROFILE, REALM, SERVER_URL, USER_INFO, WELL_KNOWN @pytest.fixture @@ -24,6 +24,7 @@ def mock_keycloak(requests_mock): """ requests_mock.get(WELL_KNOWN["well-known"], json=WELL_KNOWN) requests_mock.post(WELL_KNOWN["token_endpoint"], json=OIDC_PROFILE) + requests_mock.get(WELL_KNOWN["userinfo_endpoint"], json=USER_INFO) return requests_mock diff --git a/swh/auth/tests/sample_data.py b/swh/auth/tests/sample_data.py index 06993849932b2c65ec4ec7e39c2768ea497ca5b3..77e4602f98b009fa6ee62632cba3b7106a3c24d5 100644 --- a/swh/auth/tests/sample_data.py +++ b/swh/auth/tests/sample_data.py @@ -270,3 +270,15 @@ OIDC_PROFILE = { "session_state": "d82b90d1-0a94-4e74-ad66-dd95341c7b6d", "token_type": "bearer", } + + +USER_INFO = { + "email": "john.doe@example.com", + "email_verified": False, + "family_name": "Doe", + "given_name": "John", + "groups": ["/staff"], + "name": "John Doe", + "preferred_username": "johndoe", + "sub": "feacd344-b468-4a65-a236-14f61e6b7200", +} diff --git a/swh/auth/tests/test_auth.py b/swh/auth/tests/test_auth.py index 0222b15859cdca20a2eebf50244c6ec62b4091d9..673b5158fff8e22f7e56ed8e1a065fd8a267ea07 100644 --- a/swh/auth/tests/test_auth.py +++ b/swh/auth/tests/test_auth.py @@ -8,7 +8,7 @@ from urllib.parse import parse_qs, urlparse from keycloak.exceptions import KeycloakAuthenticationError, KeycloakConnectionError import pytest -from .sample_data import OIDC_PROFILE, WELL_KNOWN +from .sample_data import OIDC_PROFILE, USER_INFO, WELL_KNOWN def test_auth_connection_failure(keycloak_open_id_connect): @@ -68,3 +68,10 @@ def test_auth_refresh_token(mock_keycloak, keycloak_open_id_connect): assert actual_result is not None assert mock_keycloak.called + + +def test_auth_userinfo(mock_keycloak, keycloak_open_id_connect): + actual_user_info = keycloak_open_id_connect.userinfo("refresh-token") + assert actual_user_info == USER_INFO + + assert mock_keycloak.called