Skip to content

Commit

Permalink
Restore --base-wallet-extra-routes argument functionality
Browse files Browse the repository at this point in the history
Signed-off-by: Emiliano Suñé <emiliano.sune@gmail.com>
  • Loading branch information
esune committed Nov 21, 2024
1 parent 9a56d99 commit 5916c81
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
11 changes: 5 additions & 6 deletions acapy_agent/admin/decorators/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import functools
import re
from typing import Optional, Pattern, Sequence, cast
from typing import Optional, Pattern

from aiohttp import web

Expand Down Expand Up @@ -95,11 +95,10 @@ def _base_wallet_route_access(additional_routes: str, request_path: str) -> bool


def _build_additional_routes_pattern(pattern_string: str) -> Optional[Pattern]:
"""Build pattern from string."""
base_wallet_routes = cast(Sequence[str], pattern_string)
if base_wallet_routes:
return re.compile("^(?:" + "|".join(base_wallet_routes) + ")")
return None
"""Build pattern from space delimited list of paths."""
# create array and add word boundary to avoid false positives
paths = pattern_string.split(" ")
return re.compile("^((?:)" + "|".join(paths) + ")$")


def _matches_additional_routes(pattern: Pattern, path: str) -> bool:
Expand Down
4 changes: 2 additions & 2 deletions acapy_agent/admin/tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,12 @@ async def test_base_wallet_additional_route_allowed(self):
self.decorated_handler.assert_called_once_with(self.request)

async def test_base_wallet_additional_route_denied(self):
self.profile.settings["multitenant.base_wallet_routes"] = "/wrong-extra-route"
self.profile.settings["multitenant.base_wallet_routes"] = "/extra-route"
self.request = mock.MagicMock(
__getitem__=lambda _, k: self.request_dict[k],
headers={"x-api-key": "admin_api_key"},
method="POST",
path="/extra-route",
path="/extra-route-wrong",
)
decor_func = tenant_authentication(self.decorated_handler)
with self.assertRaises(web.HTTPUnauthorized):
Expand Down

0 comments on commit 5916c81

Please sign in to comment.