From 7ae0442370a86c821e1bf8f2e2f4c2f6abe55e16 Mon Sep 17 00:00:00 2001 From: Richard Nemeth Date: Thu, 19 May 2022 14:45:21 +0200 Subject: [PATCH] test: test authenticator and configurations --- keycloak/urls_patterns.py | 6 ++++++ tests/test_keycloak_admin.py | 40 ++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/keycloak/urls_patterns.py b/keycloak/urls_patterns.py index 7450f2e..071c733 100644 --- a/keycloak/urls_patterns.py +++ b/keycloak/urls_patterns.py @@ -148,6 +148,12 @@ URL_ADMIN_FLOWS_EXECUTIONS_EXECUTION = ( URL_ADMIN_FLOWS_EXECUTIONS_FLOW = ( "admin/realms/{realm-name}/authentication/flows/{flow-alias}/executions/flow" ) +URL_ADMIN_AUTHENTICATOR_PROVIDERS = ( + "admin/realms/{realm-name}/authentication/authenticator-providers" +) +URL_ADMIN_AUTHENTICATOR_CONFIG_DESCRIPTION = ( + "admin/realms/{realm-name}/authentication/config-description/{provider-id}" +) URL_ADMIN_AUTHENTICATOR_CONFIG = "admin/realms/{realm-name}/authentication/config/{id}" URL_ADMIN_COMPONENTS = "admin/realms/{realm-name}/components" diff --git a/tests/test_keycloak_admin.py b/tests/test_keycloak_admin.py index 29d3b15..6b04af7 100644 --- a/tests/test_keycloak_admin.py +++ b/tests/test_keycloak_admin.py @@ -1199,3 +1199,43 @@ def test_auth_flows(admin: KeycloakAdmin, realm: str): with pytest.raises(KeycloakDeleteError) as err: admin.delete_authentication_flow(flow_id=flow_id) assert err.match('404: b\'{"error":"Could not find flow with id"}\'') + + +def test_authentication_configs(admin: KeycloakAdmin, realm: str): + admin.realm_name = realm + + # Test list of auth providers + res = admin.get_authenticator_providers() + assert len(res) == 39 + + res = admin.get_authenticator_provider_config_description(provider_id="auth-cookie") + assert res == { + "helpText": "Validates the SSO cookie set by the auth server.", + "name": "Cookie", + "properties": [], + "providerId": "auth-cookie", + } + + # Test authenticator config + # Currently unable to find a sustainable way to fetch the config id, + # therefore testing only failures + with pytest.raises(KeycloakGetError) as err: + admin.get_authenticator_config(config_id="bad") + assert err.match('404: b\'{"error":"Could not find authenticator config"}\'') + + with pytest.raises(KeycloakPutError) as err: + admin.update_authenticator_config(payload=dict(), config_id="bad") + assert err.match('404: b\'{"error":"Could not find authenticator config"}\'') + + with pytest.raises(KeycloakDeleteError) as err: + admin.delete_authenticator_config(config_id="bad") + assert err.match('404: b\'{"error":"Could not find authenticator config"}\'') + + +def test_sync_users(admin: KeycloakAdmin, realm: str): + admin.realm_name = realm + + # Only testing the error message + with pytest.raises(KeycloakPostError) as err: + admin.sync_users(storage_id="does-not-exist", action="triggerFullSync") + assert err.match('404: b\'{"error":"Could not find component"}\'')