Browse Source

feat: add tests

pull/632/head
Aleksey Kuznetsov 1 day ago
parent
commit
fff924b4c1
Failed to extract signature
  1. 4
      src/keycloak/keycloak_admin.py
  2. 6
      src/keycloak/urls_patterns.py
  3. 56
      tests/test_keycloak_admin.py

4
src/keycloak/keycloak_admin.py

@ -3652,7 +3652,7 @@ class KeycloakAdmin:
urls_patterns.URL_ADMIN_FLOW.format(**params_path), data=json.dumps(payload),
)
return raise_error_from_response(
data_raw, KeycloakPutError, expected_codes=[HTTP_ACCEPTED],
data_raw, KeycloakPutError, expected_codes=[HTTP_ACCEPTED, HTTP_NO_CONTENT],
)
def copy_authentication_flow(self, payload: dict, flow_alias: str) -> bytes:
@ -10664,5 +10664,5 @@ class KeycloakAdmin:
urls_patterns.URL_ADMIN_FLOW.format(**params_path), data=json.dumps(payload),
)
return raise_error_from_response(
data_raw, KeycloakPutError, expected_codes=[HTTP_ACCEPTED],
data_raw, KeycloakPutError, expected_codes=[HTTP_ACCEPTED, HTTP_NO_CONTENT],
)

6
src/keycloak/urls_patterns.py

@ -231,10 +231,10 @@ URL_ADMIN_CLEAR_USER_CACHE = URL_ADMIN_REALM + "/clear-user-cache"
URL_UMA_WELL_KNOWN = URL_WELL_KNOWN_BASE + "/uma2-configuration"
URL_AUTHENTICATION_EXECUTION_RAISE_PRIORITY = (
"realms/{realm-name}/authentication/executions/{id}/raise-priority"
"admin/realms/{realm-name}/authentication/executions/{id}/raise-priority"
)
URL_AUTHENTICATION_EXECUTION_LOWER_PRIORITY = (
"realms/{realm-name}/authentication/executions/{id}/lower-priority"
"admin/realms/{realm-name}/authentication/executions/{id}/lower-priority"
)
URL_ADMIN_FLOWS_EXECUTION_CONFIG = URL_ADMIN_FLOWS_EXECUTION + "{id}/config"
URL_ADMIN_FLOWS_EXECUTION_CONFIG = URL_ADMIN_FLOWS_EXECUTION + "/config"

56
tests/test_keycloak_admin.py

@ -2449,6 +2449,19 @@ def test_auth_flows(admin: KeycloakAdmin, realm: str) -> None:
skip_exists=True,
) == {"msg": "Already exists"}
# Update
res = admin.get_authentication_flows()
browser_flow_id = next(x for x in res if x["alias"] == "browser")["id"]
flow = admin.get_authentication_flow_for_id(flow_id=browser_flow_id)
del flow["authenticationExecutions"]
del flow["id"]
flow["description"] = "test description"
res = admin.update_authentication_flow(
flow_id=browser_flow_id,
payload=flow)
res = admin.get_authentication_flow_for_id(flow_id=browser_flow_id)
assert res["description"] == "test description"
# Test flow executions
res = admin.get_authentication_flow_executions(flow_alias="browser")
assert len(res) in [8, 12], res
@ -2550,6 +2563,33 @@ def test_auth_flows(admin: KeycloakAdmin, realm: str) -> None:
)
def test_auth_flow_execution_priority(admin: KeycloakAdmin, realm: str) -> None:
"""
Test execution priority.
:param admin: Keycloak Admin client
:type admin: KeycloakAdmin
:param realm: Keycloak realm
:type realm: str
"""
admin.change_current_realm(realm)
_ = admin.create_authentication_flow(
payload={"alias": "test-create", "providerId": "basic-flow"},
)
_ = admin.create_authentication_flow_execution(
payload={"provider": "auth-cookie"},
flow_alias="test-create",
)
_ = admin.create_authentication_flow_execution(
payload={"provider": "auth-cookie"},
flow_alias="test-create",
)
executions = admin.get_authentication_flow_executions(flow_alias="test-create")
priority_list = [ex["id"] for ex in executions]
_ = admin.change_execution_priority(priority_list[1], 1)
new_executions = admin.get_authentication_flow_executions(flow_alias="test-create")
assert executions != new_executions
def test_authentication_configs(admin: KeycloakAdmin, realm: str) -> None:
"""
Test authentication configs.
@ -2572,10 +2612,20 @@ def test_authentication_configs(admin: KeycloakAdmin, realm: str) -> None:
"properties": [],
"providerId": "auth-cookie",
}
# Test authenticator config
# Currently unable to find a sustainable way to fetch the config id,
# therefore testing only failures
executions = admin.get_authentication_flow_executions(flow_alias="browser")
execution = next(ex for ex in executions if ex["configurable"])
_ = admin.create_execution_config(
execution["id"], {
"alias": "test.provisioning.property",
"config": {
"test.provisioning.property": "value2"}})
executions = admin.get_authentication_flow_executions(flow_alias="browser")
execution_config_id = next(
ex for ex in executions if ex.get("id") == execution["id"])["authenticationConfig"]
res = admin.get_authenticator_config(config_id=execution_config_id)
assert res["config"]["test.provisioning.property"] == "value2"
with pytest.raises(KeycloakGetError) as err:
admin.get_authenticator_config(config_id="bad")
assert err.match('404: b\'{"error":"Could not find authenticator config".*}\'')

Loading…
Cancel
Save