Browse Source

feat: add tests and logic for getting client authz resource

pull/435/head
Raspreet Singh 3 years ago
parent
commit
b7a6338802
  1. 23
      src/keycloak/keycloak_admin.py
  2. 7
      tests/test_keycloak_admin.py

23
src/keycloak/keycloak_admin.py

@ -1561,6 +1561,29 @@ class KeycloakAdmin:
)
return raise_error_from_response(data_raw, KeycloakGetError)
def get_client_authz_resource(self, client_id: str, resource_id: str):
"""Get a client resource.
:param client_id: id in ClientRepresentation
https://www.keycloak.org/docs-api/18.0/rest-api/index.html#_clientrepresentation
:type client_id: str
:param resource_id: id in ResourceRepresentation
https://www.keycloak.org/docs-api/18.0/rest-api/index.html#_resourcerepresentation
:type resource_id: str
:return: Keycloak server response
:rtype: bytes
"""
params_path = {
"realm-name": self.connection.realm_name,
"id": client_id,
"resource-id": resource_id,
}
data_raw = self.connection.raw_get(
urls_patterns.URL_ADMIN_CLIENT_AUTHZ_RESOURCE.format(**params_path)
)
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[200])
def create_client_authz_role_based_policy(self, client_id, payload, skip_exists=False):
"""Create role-based policy of client.

7
tests/test_keycloak_admin.py

@ -790,6 +790,10 @@ def test_clients(admin: KeycloakAdmin, realm: str):
assert res["name"] == "test-resource", res
test_resource_id = res["_id"]
res = admin.get_client_authz_resource(client_id=auth_client_id, resource_id=test_resource_id)
assert res["_id"] == test_resource_id, res
assert res["name"] == "test-resource", res
with pytest.raises(KeycloakPostError) as err:
admin.create_client_authz_resource(
client_id=auth_client_id, payload={"name": "test-resource"}
@ -809,6 +813,9 @@ def test_clients(admin: KeycloakAdmin, realm: str):
assert res["name"] == "temp-resource", res
temp_resource_id = res["_id"]
admin.delete_client_authz_resource(client_id=auth_client_id, resource_id=temp_resource_id)
with pytest.raises(KeycloakGetError) as err:
admin.get_client_authz_resource(client_id=auth_client_id, resource_id=temp_resource_id)
assert err.match("404: b''")
# Authz policies
res = admin.get_client_authz_policies(client_id=auth_client_id)

Loading…
Cancel
Save