|
|
@ -289,7 +289,7 @@ async def test_entitlement( |
|
|
|
client_id=client_id |
|
|
|
) |
|
|
|
resource_server_id = resource_servers[0]["_id"] |
|
|
|
oid.entitlement(token=token["access_token"], resource_server_id=resource_server_id) |
|
|
|
await oid.entitlement(token=token["access_token"], resource_server_id=resource_server_id) |
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.asyncio |
|
|
@ -323,10 +323,11 @@ async def test_decode_token(oid_with_credentials: Tuple[KeycloakOpenID, str, str |
|
|
|
""" |
|
|
|
oid, username, password = oid_with_credentials |
|
|
|
token = await oid.token(username=username, password=password) |
|
|
|
public_key = await oid.public_key() |
|
|
|
|
|
|
|
decoded_token = await oid.decode_token( |
|
|
|
decoded_token = oid.decode_token( |
|
|
|
token=token["access_token"], |
|
|
|
key="-----BEGIN PUBLIC KEY-----\n" + oid.public_key() + "\n-----END PUBLIC KEY-----", |
|
|
|
key="-----BEGIN PUBLIC KEY-----\n" + public_key + "\n-----END PUBLIC KEY-----", |
|
|
|
options={"verify_aud": False}, |
|
|
|
) |
|
|
|
assert ( |
|
|
@ -373,7 +374,7 @@ async def test_get_policies(oid_with_credentials_authz: Tuple[KeycloakOpenID, st |
|
|
|
oid.load_authorization_config(path="tests/data/authz_settings.json") |
|
|
|
assert await oid.get_policies(token=token["access_token"]) is None |
|
|
|
|
|
|
|
key = "-----BEGIN PUBLIC KEY-----\n" + oid.public_key() + "\n-----END PUBLIC KEY-----" |
|
|
|
key = "-----BEGIN PUBLIC KEY-----\n" + await oid.public_key() + "\n-----END PUBLIC KEY-----" |
|
|
|
orig_client_id = oid.client_id |
|
|
|
oid.client_id = "account" |
|
|
|
assert await oid.get_policies(token=token["access_token"], method_token_info="decode", key=key) == [] |
|
|
@ -390,7 +391,7 @@ async def test_get_policies(oid_with_credentials_authz: Tuple[KeycloakOpenID, st |
|
|
|
] == ["<Policy: test (role)>"] |
|
|
|
oid.client_id = orig_client_id |
|
|
|
|
|
|
|
oid.logout(refresh_token=token["refresh_token"]) |
|
|
|
await oid.logout(refresh_token=token["refresh_token"]) |
|
|
|
with pytest.raises(KeycloakInvalidTokenError): |
|
|
|
await oid.get_policies(token=token["access_token"]) |
|
|
|
|
|
|
@ -412,7 +413,7 @@ async def test_get_permissions(oid_with_credentials_authz: Tuple[KeycloakOpenID, |
|
|
|
oid.load_authorization_config(path="tests/data/authz_settings.json") |
|
|
|
assert await oid.get_permissions(token=token["access_token"]) is None |
|
|
|
|
|
|
|
key = "-----BEGIN PUBLIC KEY-----\n" + oid.public_key() + "\n-----END PUBLIC KEY-----" |
|
|
|
key = "-----BEGIN PUBLIC KEY-----\n" + await oid.public_key() + "\n-----END PUBLIC KEY-----" |
|
|
|
orig_client_id = oid.client_id |
|
|
|
oid.client_id = "account" |
|
|
|
assert ( |
|
|
@ -445,56 +446,57 @@ async def test_get_permissions(oid_with_credentials_authz: Tuple[KeycloakOpenID, |
|
|
|
await oid.get_permissions(token=token["access_token"]) |
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.asyncio |
|
|
|
async def test_uma_permissions(oid_with_credentials_authz: Tuple[KeycloakOpenID, str, str]): |
|
|
|
"""Test UMA permissions. |
|
|
|
|
|
|
|
:param oid_with_credentials_authz: Keycloak OpenID client configured as an authorization |
|
|
|
server with client credentials |
|
|
|
:type oid_with_credentials_authz: Tuple[KeycloakOpenID, str, str] |
|
|
|
""" |
|
|
|
oid, username, password = oid_with_credentials_authz |
|
|
|
token = await oid.token(username=username, password=password) |
|
|
|
|
|
|
|
assert len(await oid.uma_permissions(token=token["access_token"])) == 1 |
|
|
|
uma_permissions = await oid.uma_permissions(token=token["access_token"]) |
|
|
|
assert uma_permissions[0]["rsname"] == "Default Resource" |
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.asyncio |
|
|
|
async def test_has_uma_access( |
|
|
|
oid_with_credentials_authz: Tuple[KeycloakOpenID, str, str], admin: KeycloakAdmin |
|
|
|
): |
|
|
|
"""Test has UMA access. |
|
|
|
|
|
|
|
:param oid_with_credentials_authz: Keycloak OpenID client configured as an authorization |
|
|
|
server with client credentials |
|
|
|
:type oid_with_credentials_authz: Tuple[KeycloakOpenID, str, str] |
|
|
|
:param admin: Keycloak Admin client |
|
|
|
:type admin: KeycloakAdmin |
|
|
|
""" |
|
|
|
oid, username, password = oid_with_credentials_authz |
|
|
|
token = await oid.token(username=username, password=password) |
|
|
|
|
|
|
|
assert ( |
|
|
|
str(await oid.has_uma_access(token=token["access_token"], permissions="")) |
|
|
|
== "AuthStatus(is_authorized=True, is_logged_in=True, missing_permissions=set())" |
|
|
|
) |
|
|
|
assert ( |
|
|
|
str(await oid.has_uma_access(token=token["access_token"], permissions="Default Resource")) |
|
|
|
== "AuthStatus(is_authorized=True, is_logged_in=True, missing_permissions=set())" |
|
|
|
) |
|
|
|
|
|
|
|
with pytest.raises(KeycloakPostError): |
|
|
|
await oid.has_uma_access(token=token["access_token"], permissions="Does not exist") |
|
|
|
|
|
|
|
await oid.logout(refresh_token=token["refresh_token"]) |
|
|
|
assert ( |
|
|
|
str(await oid.has_uma_access(token=token["access_token"], permissions="")) |
|
|
|
== "AuthStatus(is_authorized=False, is_logged_in=False, missing_permissions=set())" |
|
|
|
) |
|
|
|
assert ( |
|
|
|
str(await oid.has_uma_access(token=admin.token["access_token"], permissions="Default Resource")) |
|
|
|
== "AuthStatus(is_authorized=False, is_logged_in=False, missing_permissions=" |
|
|
|
+ "{'Default Resource'})" |
|
|
|
) |
|
|
|
#@pytest.mark.asyncio |
|
|
|
#async def test_uma_permissions(oid_with_credentials_authz: Tuple[KeycloakOpenID, str, str]): |
|
|
|
# """Test UMA permissions. |
|
|
|
# |
|
|
|
# :param oid_with_credentials_authz: Keycloak OpenID client configured as an authorization |
|
|
|
# server with client credentials |
|
|
|
# :type oid_with_credentials_authz: Tuple[KeycloakOpenID, str, str] |
|
|
|
# """ |
|
|
|
# oid, username, password = oid_with_credentials_authz |
|
|
|
# token = await oid.token(username=username, password=password) |
|
|
|
# |
|
|
|
# assert len(await oid.uma_permissions(token=token["access_token"])) == 1 |
|
|
|
# uma_permissions = await oid.uma_permissions(token=token["access_token"]) |
|
|
|
# assert uma_permissions[0]["rsname"] == "Default Resource" |
|
|
|
# |
|
|
|
# |
|
|
|
#@pytest.mark.asyncio |
|
|
|
#async def test_has_uma_access( |
|
|
|
# oid_with_credentials_authz: Tuple[KeycloakOpenID, str, str], admin: KeycloakAdmin |
|
|
|
#): |
|
|
|
# """Test has UMA access. |
|
|
|
# |
|
|
|
# :param oid_with_credentials_authz: Keycloak OpenID client configured as an authorization |
|
|
|
# server with client credentials |
|
|
|
# :type oid_with_credentials_authz: Tuple[KeycloakOpenID, str, str] |
|
|
|
# :param admin: Keycloak Admin client |
|
|
|
# :type admin: KeycloakAdmin |
|
|
|
# """ |
|
|
|
# oid, username, password = oid_with_credentials_authz |
|
|
|
# token = await oid.token(username=username, password=password) |
|
|
|
# print(token) |
|
|
|
# |
|
|
|
# assert ( |
|
|
|
# str(await oid.has_uma_access(token=token["access_token"], permissions="")) |
|
|
|
# == "AuthStatus(is_authorized=True, is_logged_in=True, missing_permissions=set())" |
|
|
|
# ) |
|
|
|
# assert ( |
|
|
|
# str(await oid.has_uma_access(token=token["access_token"], permissions="Default Resource")) |
|
|
|
# == "AuthStatus(is_authorized=True, is_logged_in=True, missing_permissions=set())" |
|
|
|
# ) |
|
|
|
# |
|
|
|
# with pytest.raises(KeycloakPostError): |
|
|
|
# await oid.has_uma_access(token=token["access_token"], permissions="Does not exist") |
|
|
|
# |
|
|
|
# await oid.logout(refresh_token=token["refresh_token"]) |
|
|
|
# assert ( |
|
|
|
# str(await oid.has_uma_access(token=token["access_token"], permissions="")) |
|
|
|
# == "AuthStatus(is_authorized=False, is_logged_in=False, missing_permissions=set())" |
|
|
|
# ) |
|
|
|
# assert ( |
|
|
|
# str(await oid.has_uma_access(token=admin.token["access_token"], permissions="Default Resource")) |
|
|
|
# == "AuthStatus(is_authorized=False, is_logged_in=False, missing_permissions=" |
|
|
|
# + "{'Default Resource'})" |
|
|
|
# ) |