Skip to content

Commit

Permalink
feat: add matchingUri support for listing resources with wildcards (#592
Browse files Browse the repository at this point in the history
)

* feat: add matchingUri support for listing resources with wildcards

* fix: change formatting
  • Loading branch information
Tarick authored Sep 14, 2024
1 parent 78a0aa1 commit 14051de
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/keycloak/keycloak_uma.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ def resource_set_list_ids(
owner: str = "",
resource_type: str = "",
scope: str = "",
matchingUri: bool = False,
first: int = 0,
maximum: int = -1,
):
Expand All @@ -230,6 +231,8 @@ def resource_set_list_ids(
:type resource_type: str
:param scope: query resource scope
:type scope: str
:param matchingUri: enable URI matching
:type matchingUri: bool
:param first: index of first matching resource to return
:type first: int
:param maximum: maximum number of resources to return (-1 for all)
Expand All @@ -250,6 +253,8 @@ def resource_set_list_ids(
query["type"] = resource_type
if scope:
query["scope"] = scope
if matchingUri:
query["matchingUri"] = "true"
if first > 0:
query["first"] = first
if maximum >= 0:
Expand Down Expand Up @@ -544,6 +549,7 @@ async def a_resource_set_list_ids(
owner: str = "",
resource_type: str = "",
scope: str = "",
matchingUri: bool = False,
first: int = 0,
maximum: int = -1,
):
Expand All @@ -565,6 +571,8 @@ async def a_resource_set_list_ids(
:param scope: query resource scope
:type scope: str
:param first: index of first matching resource to return
:param matchingUri: enable URI matching
:type matchingUri: bool
:type first: int
:param maximum: maximum number of resources to return (-1 for all)
:type maximum: int
Expand All @@ -584,6 +592,8 @@ async def a_resource_set_list_ids(
query["type"] = resource_type
if scope:
query["scope"] = scope
if matchingUri:
query["matchingUri"] = "true"
if first > 0:
query["first"] = first
if maximum >= 0:
Expand Down
22 changes: 22 additions & 0 deletions tests/test_keycloak_uma.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,23 @@ def test_uma_resource_sets(uma: KeycloakUMA):
"name": "mytest",
"scopes": ["test:read", "test:write"],
"type": "urn:test",
"uris": ["/some_resources/*"],
}
created_resource = uma.resource_set_create(resource_to_create)
assert created_resource
assert created_resource["_id"], created_resource
assert set(resource_to_create).issubset(set(created_resource)), created_resource

# Test getting resource with wildcard
# Without matchingUri query option
resource_set_list_ids = uma.resource_set_list_ids(uri="/some_resources/resource")
assert len(resource_set_list_ids) == 0
# With matchingUri query option
resource_set_list_ids = uma.resource_set_list_ids(
uri="/some_resources/resource", matchingUri=True
)
assert len(resource_set_list_ids) == 1

# Test create the same resource set
with pytest.raises(KeycloakPostError) as err:
uma.resource_set_create(resource_to_create)
Expand Down Expand Up @@ -382,12 +393,23 @@ async def test_a_uma_resource_sets(uma: KeycloakUMA):
"name": "mytest",
"scopes": ["test:read", "test:write"],
"type": "urn:test",
"uris": ["/some_resources/*"],
}
created_resource = await uma.a_resource_set_create(resource_to_create)
assert created_resource
assert created_resource["_id"], created_resource
assert set(resource_to_create).issubset(set(created_resource)), created_resource

# Test getting resource with wildcard
# Without matchingUri query option
resource_set_list_ids = await uma.a_resource_set_list_ids(uri="/some_resources/resource")
assert len(resource_set_list_ids) == 0
# With matchingUri query option
resource_set_list_ids = await uma.a_resource_set_list_ids(
uri="/some_resources/resource", matchingUri=True
)
assert len(resource_set_list_ids) == 1

# Test create the same resource set
with pytest.raises(KeycloakPostError) as err:
await uma.a_resource_set_create(resource_to_create)
Expand Down

0 comments on commit 14051de

Please sign in to comment.