remove colons as well when checking wildcard permissions and updated test to ensure it works as expected

This commit is contained in:
jasquat 2023-10-11 10:25:02 -04:00
parent 5fb4171508
commit db4e9292f6
2 changed files with 7 additions and 3 deletions

View File

@ -164,9 +164,8 @@ class AuthorizationService:
@classmethod
def target_uri_matches_actual_uri(cls, target_uri: str, actual_uri: str) -> bool:
if target_uri.endswith("%"):
return actual_uri.startswith(target_uri.removesuffix("%")) or actual_uri == target_uri.removesuffix(
"%"
).removesuffix("/")
target_uri_without_suffix = target_uri.removesuffix("%").removesuffix(":").removesuffix("/")
return actual_uri.startswith(target_uri_without_suffix) or actual_uri == target_uri_without_suffix
return actual_uri == target_uri
@classmethod

View File

@ -106,15 +106,20 @@ class TestProcessApi(BaseTest):
principal = group.principal
UserService.add_user_to_group(user, group)
self.add_permissions_to_principal(principal, target_uri="/v1.0/process-groups/%", permission_names=["read"])
self.add_permissions_to_principal(
principal, target_uri="/v1.0/process-groups/test_group:%", permission_names=["create"]
)
request_body = {
"requests_to_check": {
"/v1.0/process-groups": ["GET", "POST"],
"/v1.0/process-groups/test_group": ["GET", "POST"],
"/v1.0/process-models": ["GET"],
}
}
expected_response_body = {
"results": {
"/v1.0/process-groups": {"GET": True, "POST": False},
"/v1.0/process-groups/test_group": {"GET": True, "POST": True},
"/v1.0/process-models": {"GET": False},
}
}