Skip to content

Commit

Permalink
Fix regex in policies
Browse files Browse the repository at this point in the history
  • Loading branch information
eray-inuits committed Mar 28, 2024
1 parent 2074035 commit 8c1e195
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ def authorize(
self, policy_context: PolicyContext, user_context: UserContext, request_context
):
request: Request = request_context.http_request
if not regex.match("^(/[^/]+)?/[^/]+/(filter|filter_v2)$", request.path):
if not regex.match(
"^(/[^/]+/v[0-9]+)?/[^/]+/(filter|filter_v2)$", request.path
):
return policy_context

if not isinstance(user_context.access_restrictions.filters, list):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def authorize(
):
request: Request = request_context.http_request
if not regex.match(
"^(/[^/]+)?/[^/]+/[^/]+$|^/ngsi-ld/v1/entities/[^/]+$", request.path
"^(/[^/]+/v[0-9]+)?/[^/]+/[^/]+$|^/ngsi-ld/v1/entities/[^/]+$", request.path
):
return policy_context

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def authorize(
self, policy_context: PolicyContext, user_context: UserContext, request_context
):
request: Request = request_context.http_request
if not regex.match("^(/[^/]+)?/[^/]+/[^/]+/metadata$", request.path):
if not regex.match("^(/[^/]+/v[0-9]+)?/[^/]+/[^/]+/metadata$", request.path):
return policy_context

view_args = request.view_args or {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def authorize(
self, policy_context: PolicyContext, user_context: UserContext, request_context
):
request: Request = request_context.http_request
if not regex.match("^(/[^/]+)?/[^/]+/[^/]+/relations$", request.path):
if not regex.match("^(/[^/]+/v[0-9]+)?/[^/]+/[^/]+/relations$", request.path):
return policy_context

view_args = request.view_args or {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ def authorize(
self, policy_context: PolicyContext, user_context: UserContext, request_context
):
request: Request = request_context.http_request
if not regex.match("^(/[^/]+)?/[^/]+$|^/ngsi-ld/v1/entities$", request.path):
if not regex.match(
"^(/[^/]+/v[0-9]+)?/[^/]+$|^/ngsi-ld/v1/entities$", request.path
):
return policy_context

for role in user_context.x_tenant.roles:
Expand Down
2 changes: 1 addition & 1 deletion src/elody/policies/authorization/tenant_request_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class TenantRequestPolicy(BaseAuthorizationPolicy):
def authorize(self, policy_context, user_context, request_context):
request: Request = request_context.http_request
if not regex.match("^(/[^/]+)?/tenants$", request.path):
if not regex.match("^(/[^/]+/v[0-9]+)?/tenants$", request.path):
return policy_context

set_restricting_filter = True
Expand Down

0 comments on commit 8c1e195

Please sign in to comment.