|
|
|
@ -57,6 +57,7 @@ def test_keycloak_admin_init(env: KeycloakTestEnv) -> None: |
|
|
|
server_url=f"http://{env.keycloak_host}:{env.keycloak_port}", |
|
|
|
username=env.keycloak_admin, |
|
|
|
password=env.keycloak_admin_password, |
|
|
|
pool_maxsize=5, |
|
|
|
) |
|
|
|
assert admin.connection.server_url == f"http://{env.keycloak_host}:{env.keycloak_port}", ( |
|
|
|
admin.connection.server_url |
|
|
|
@ -72,6 +73,7 @@ def test_keycloak_admin_init(env: KeycloakTestEnv) -> None: |
|
|
|
assert admin.connection.token is None, admin.connection.token |
|
|
|
assert admin.connection.user_realm_name is None, admin.connection.user_realm_name |
|
|
|
assert admin.connection.custom_headers is None, admin.connection.custom_headers |
|
|
|
assert admin.connection.pool_maxsize == 5, admin.connection.pool_maxsize |
|
|
|
|
|
|
|
admin = KeycloakAdmin( |
|
|
|
server_url=f"http://{env.keycloak_host}:{env.keycloak_port}", |
|
|
|
@ -2645,7 +2647,7 @@ def test_auth_flows(admin: KeycloakAdmin, realm: str) -> None: |
|
|
|
|
|
|
|
# Test flow executions |
|
|
|
res = admin.get_authentication_flow_executions(flow_alias="browser") |
|
|
|
assert len(res) in [8, 12, 14], res |
|
|
|
assert len(res) in [8, 12, 14, 15], res |
|
|
|
|
|
|
|
with pytest.raises(KeycloakGetError) as err: |
|
|
|
admin.get_authentication_flow_executions(flow_alias="bad") |
|
|
|
@ -2788,7 +2790,7 @@ def test_authentication_configs(admin: KeycloakAdmin, realm: str) -> None: |
|
|
|
|
|
|
|
# Test list of auth providers |
|
|
|
res = admin.get_authenticator_providers() |
|
|
|
assert len(res) <= 41 |
|
|
|
assert len(res) <= 42 |
|
|
|
|
|
|
|
res = admin.get_authenticator_provider_config_description(provider_id="auth-cookie") |
|
|
|
assert res == { |
|
|
|
@ -3310,6 +3312,48 @@ def test_get_role_client_level_children( |
|
|
|
assert child["id"] in [x["id"] for x in res] |
|
|
|
|
|
|
|
|
|
|
|
def test_get_role_composites_by_id( |
|
|
|
admin: KeycloakAdmin, |
|
|
|
realm: str, |
|
|
|
client: str, |
|
|
|
composite_client_role: str, |
|
|
|
client_role: str, |
|
|
|
) -> None: |
|
|
|
""" |
|
|
|
Test get role's children by role ID. |
|
|
|
|
|
|
|
:param admin: Keycloak Admin client |
|
|
|
:type admin: KeycloakAdmin |
|
|
|
:param realm: Keycloak realm |
|
|
|
:type realm: str |
|
|
|
:param client: Keycloak client |
|
|
|
:type client: str |
|
|
|
:param composite_client_role: Composite client role |
|
|
|
:type composite_client_role: str |
|
|
|
:param client_role: Client role |
|
|
|
:type client_role: str |
|
|
|
""" |
|
|
|
admin.change_current_realm(realm) |
|
|
|
|
|
|
|
parent_role = admin.get_client_role(client, composite_client_role) |
|
|
|
child_role = admin.get_client_role(client, client_role) |
|
|
|
|
|
|
|
composites = admin.get_role_composites_by_id(parent_role["id"]) |
|
|
|
assert len(composites) > 0 |
|
|
|
assert child_role["id"] in [x["id"] for x in composites] |
|
|
|
|
|
|
|
composites_paginated = admin.get_role_composites_by_id( |
|
|
|
parent_role["id"], query={"first": 0, "max": 10} |
|
|
|
) |
|
|
|
assert len(composites_paginated) > 0 |
|
|
|
assert child_role["id"] in [x["id"] for x in composites_paginated] |
|
|
|
|
|
|
|
composites_searched = admin.get_role_composites_by_id( |
|
|
|
parent_role["id"], query={"search": client_role[:3]} |
|
|
|
) |
|
|
|
assert len(composites_searched) > 0 |
|
|
|
|
|
|
|
|
|
|
|
def test_upload_certificate( |
|
|
|
admin: KeycloakAdmin, |
|
|
|
realm: str, |
|
|
|
@ -3351,7 +3395,7 @@ def test_get_bruteforce_status_for_user( |
|
|
|
:param realm: Keycloak realm |
|
|
|
:type realm: str |
|
|
|
""" |
|
|
|
oid, username, password = oid_with_credentials |
|
|
|
oid, username, _ = oid_with_credentials |
|
|
|
admin.change_current_realm(realm) |
|
|
|
|
|
|
|
# Turn on bruteforce protection |
|
|
|
@ -3389,7 +3433,7 @@ def test_clear_bruteforce_attempts_for_user( |
|
|
|
:param realm: Keycloak realm |
|
|
|
:type realm: str |
|
|
|
""" |
|
|
|
oid, username, password = oid_with_credentials |
|
|
|
oid, username, _ = oid_with_credentials |
|
|
|
admin.change_current_realm(realm) |
|
|
|
|
|
|
|
# Turn on bruteforce protection |
|
|
|
@ -3430,7 +3474,7 @@ def test_clear_bruteforce_attempts_for_all_users( |
|
|
|
:param realm: Keycloak realm |
|
|
|
:type realm: str |
|
|
|
""" |
|
|
|
oid, username, password = oid_with_credentials |
|
|
|
oid, username, _ = oid_with_credentials |
|
|
|
admin.change_current_realm(realm) |
|
|
|
|
|
|
|
# Turn on bruteforce protection |
|
|
|
@ -3591,7 +3635,7 @@ def test_initial_access_token( |
|
|
|
assert res["count"] == 2 |
|
|
|
assert res["expiration"] == 3 |
|
|
|
|
|
|
|
oid, username, password = oid_with_credentials |
|
|
|
oid, _, _ = oid_with_credentials |
|
|
|
|
|
|
|
client = str(uuid.uuid4()) |
|
|
|
secret = str(uuid.uuid4()) |
|
|
|
@ -6376,7 +6420,7 @@ async def test_a_auth_flows(admin: KeycloakAdmin, realm: str) -> None: |
|
|
|
|
|
|
|
# Test flow executions |
|
|
|
res = await admin.a_get_authentication_flow_executions(flow_alias="browser") |
|
|
|
assert len(res) in [8, 12, 14], res |
|
|
|
assert len(res) in [8, 12, 14, 15], res |
|
|
|
|
|
|
|
with pytest.raises(KeycloakGetError) as err: |
|
|
|
await admin.a_get_authentication_flow_executions(flow_alias="bad") |
|
|
|
@ -6524,7 +6568,7 @@ async def test_a_authentication_configs(admin: KeycloakAdmin, realm: str) -> Non |
|
|
|
|
|
|
|
# Test list of auth providers |
|
|
|
res = await admin.a_get_authenticator_providers() |
|
|
|
assert len(res) <= 41 |
|
|
|
assert len(res) <= 42 |
|
|
|
|
|
|
|
res = await admin.a_get_authenticator_provider_config_description(provider_id="auth-cookie") |
|
|
|
assert res == { |
|
|
|
@ -7067,6 +7111,49 @@ async def test_a_get_role_client_level_children( |
|
|
|
assert child["id"] in [x["id"] for x in res] |
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.asyncio |
|
|
|
async def test_a_get_role_composites_by_id( |
|
|
|
admin: KeycloakAdmin, |
|
|
|
realm: str, |
|
|
|
client: str, |
|
|
|
composite_client_role: str, |
|
|
|
client_role: str, |
|
|
|
) -> None: |
|
|
|
""" |
|
|
|
Test get all composite roles by role id asynchronously. |
|
|
|
|
|
|
|
:param admin: Keycloak Admin client |
|
|
|
:type admin: KeycloakAdmin |
|
|
|
:param realm: Keycloak realm |
|
|
|
:type realm: str |
|
|
|
:param client: Keycloak client |
|
|
|
:type client: str |
|
|
|
:param composite_client_role: Composite client role |
|
|
|
:type composite_client_role: str |
|
|
|
:param client_role: Client role |
|
|
|
:type client_role: str |
|
|
|
""" |
|
|
|
await admin.a_change_current_realm(realm) |
|
|
|
|
|
|
|
parent_role = await admin.a_get_client_role(client, composite_client_role) |
|
|
|
child_role = await admin.a_get_client_role(client, client_role) |
|
|
|
|
|
|
|
composites = await admin.a_get_role_composites_by_id(parent_role["id"]) |
|
|
|
assert len(composites) > 0 |
|
|
|
assert child_role["id"] in [x["id"] for x in composites] |
|
|
|
|
|
|
|
composites_paginated = await admin.a_get_role_composites_by_id( |
|
|
|
parent_role["id"], query={"first": 0, "max": 10} |
|
|
|
) |
|
|
|
assert len(composites_paginated) > 0 |
|
|
|
assert child_role["id"] in [x["id"] for x in composites_paginated] |
|
|
|
|
|
|
|
composites_searched = await admin.a_get_role_composites_by_id( |
|
|
|
parent_role["id"], query={"search": client_role[:3]} |
|
|
|
) |
|
|
|
assert len(composites_searched) > 0 |
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.asyncio |
|
|
|
async def test_a_upload_certificate( |
|
|
|
admin: KeycloakAdmin, |
|
|
|
@ -7110,7 +7197,7 @@ async def test_a_get_bruteforce_status_for_user( |
|
|
|
:param realm: Keycloak realm |
|
|
|
:type realm: str |
|
|
|
""" |
|
|
|
oid, username, password = oid_with_credentials |
|
|
|
oid, username, _ = oid_with_credentials |
|
|
|
await admin.a_change_current_realm(realm) |
|
|
|
|
|
|
|
# Turn on bruteforce protection |
|
|
|
@ -7149,7 +7236,7 @@ async def test_a_clear_bruteforce_attempts_for_user( |
|
|
|
:param realm: Keycloak realm |
|
|
|
:type realm: str |
|
|
|
""" |
|
|
|
oid, username, password = oid_with_credentials |
|
|
|
oid, username, _ = oid_with_credentials |
|
|
|
await admin.a_change_current_realm(realm) |
|
|
|
|
|
|
|
# Turn on bruteforce protection |
|
|
|
@ -7191,7 +7278,7 @@ async def test_a_clear_bruteforce_attempts_for_all_users( |
|
|
|
:param realm: Keycloak realm |
|
|
|
:type realm: str |
|
|
|
""" |
|
|
|
oid, username, password = oid_with_credentials |
|
|
|
oid, username, _ = oid_with_credentials |
|
|
|
await admin.a_change_current_realm(realm) |
|
|
|
|
|
|
|
# Turn on bruteforce protection |
|
|
|
@ -7365,7 +7452,7 @@ async def test_a_initial_access_token( |
|
|
|
assert res["count"] == 2 |
|
|
|
assert res["expiration"] == 3 |
|
|
|
|
|
|
|
oid, username, password = oid_with_credentials |
|
|
|
oid, _, _ = oid_with_credentials |
|
|
|
|
|
|
|
client = str(uuid.uuid4()) |
|
|
|
secret = str(uuid.uuid4()) |
|
|
|
|