Skip to content

Commit

Permalink
Add reverse compatibility handling
Browse files Browse the repository at this point in the history
Signed-off-by: jamshale <[email protected]>
  • Loading branch information
jamshale committed Nov 25, 2024
1 parent d2171fc commit 69be89f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
10 changes: 10 additions & 0 deletions acapy_agent/resolver/default/tests/test_universal.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ async def test_fetch_resolver_props(mock_client_session: MockClientSession):

@pytest.mark.asyncio
async def test_get_supported_did_regex():
# Old response format
props = {"example": {"http": {"pattern": "match a test string"}}}
with mock.patch.object(
UniversalResolver,
"_fetch_resolver_props",
mock.CoroutineMock(return_value=props),
):
pattern = await UniversalResolver()._get_supported_did_regex()
assert pattern.fullmatch("match a test string")

# Example response from dev universal resolver 1.0
props = {
"^(did:sov:(?:(?:\\w[-\\w]*(?::\\w[-\\w]*)*):)?(?:[1-9A-HJ-NP-Za-km-z]{21,22}))$": {
Expand Down
14 changes: 12 additions & 2 deletions acapy_agent/resolver/default/universal.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,16 @@ async def _fetch_resolver_props(self) -> dict:
"Failed to retrieve resolver properties: " + await resp.text()
)

async def _get_supported_did_regex(self) -> Pattern:
async def _get_supported_did_regex(self):
props = await self._fetch_resolver_props()
return _compile_supported_did_regex(driver for driver in props.keys())

def _get_patterns():
"""Handle both old and new properties responses."""
patterns = list(props.values())[0].get("http", {}).get("pattern")
if not patterns:
return props.keys()
else:
return [driver["http"]["pattern"] for driver in props.values()]

patterns = _get_patterns()
return _compile_supported_did_regex(patterns)

0 comments on commit 69be89f

Please sign in to comment.