Skip to content

Commit 799cd64

Browse files
authored
Fix/universal resolver (openwallet-foundation#3354)
* Update universal resolver response handling Signed-off-by: jamshale <[email protected]> * Update universal resolver unit test Signed-off-by: jamshale <[email protected]> * Add reverse compatibility handling Signed-off-by: jamshale <[email protected]> --------- Signed-off-by: jamshale <[email protected]>
1 parent 2d4212a commit 799cd64

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

acapy_agent/resolver/default/tests/test_universal.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ async def test_fetch_resolver_props(mock_client_session: MockClientSession):
119119

120120
@pytest.mark.asyncio
121121
async def test_get_supported_did_regex():
122+
# Old response format
122123
props = {"example": {"http": {"pattern": "match a test string"}}}
123124
with mock.patch.object(
124125
UniversalResolver,
@@ -128,6 +129,29 @@ async def test_get_supported_did_regex():
128129
pattern = await UniversalResolver()._get_supported_did_regex()
129130
assert pattern.fullmatch("match a test string")
130131

132+
# Example response from dev universal resolver 1.0
133+
props = {
134+
"^(did:sov:(?:(?:\\w[-\\w]*(?::\\w[-\\w]*)*):)?(?:[1-9A-HJ-NP-Za-km-z]{21,22}))$": {
135+
"libIndyPath": "",
136+
"openParallel": "false",
137+
"poolVersions": "_;2;test;2;builder;2;danube;2;idunion;2;idunion:test;2;indicio;2;indicio:test;2;indicio:demo;2;nxd;2;findy:test;2;bcovrin;2;bcovrin:test;2;bcovrin:dev;2;candy;2;candy:test;2;candy:dev;2",
138+
"submitterDidSeeds": "_;_;test;_;builder;_;danube;_;idunion;_;idunion:test;_;indicio;_;indicio:test;_;indicio:demo;_;nxd;_;findy:test;_;bcovrin;_;bcovrin:test;_;bcovrin:dev;_;candy;_;candy:test;_;candy:dev;_",
139+
"http": {
140+
"resolveUri": "http://driver-did-sov:8080/1.0/identifiers/",
141+
"propertiesUri": "http://driver-did-sov:8080/1.0/properties",
142+
},
143+
"walletNames": "_;w1;test;w2;builder;w3;danube;w4;idunion;w5;idunion:test;w6;indicio;w7;indicio:test;w8;indicio:demo;w9;nxd;w11;findy:test;w12;bcovrin;w13;bcovrin:test;w14;bcovrin:dev;w15;candy;w16;candy:test;w17;candy:dev;w18",
144+
"poolConfigs": "_;./sovrin/_.txn;test;./sovrin/test.txn;builder;./sovrin/builder.txn;danube;./sovrin/danube.txn;idunion;./sovrin/idunion.txn;idunion:test;./sovrin/idunion-test.txn;indicio;./sovrin/indicio.txn;indicio:test;./sovrin/indicio-test.txn;indicio:demo;./sovrin/indicio-demo.txn;nxd;./sovrin/nxd.txn;bcovrin:test;./sovrin/bcovrin-test.txn;candy;./sovrin/candy.txn;candy:test;./sovrin/candy-test.txn;candy:dev;./sovrin/candy-dev.txn",
145+
}
146+
}
147+
with mock.patch.object(
148+
UniversalResolver,
149+
"_fetch_resolver_props",
150+
mock.CoroutineMock(return_value=props),
151+
):
152+
pattern = await UniversalResolver()._get_supported_did_regex()
153+
assert pattern.match("did:sov:WRfXPg8dantKVubE3HX8pw")
154+
131155

132156
def test_compile_supported_did_regex():
133157
patterns = ["one", "two", "three"]

acapy_agent/resolver/default/universal.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,16 @@ async def _fetch_resolver_props(self) -> dict:
110110
"Failed to retrieve resolver properties: " + await resp.text()
111111
)
112112

113-
async def _get_supported_did_regex(self) -> Pattern:
113+
async def _get_supported_did_regex(self):
114114
props = await self._fetch_resolver_props()
115-
return _compile_supported_did_regex(
116-
driver["http"]["pattern"] for driver in props.values()
117-
)
115+
116+
def _get_patterns():
117+
"""Handle both old and new properties responses."""
118+
patterns = list(props.values())[0].get("http", {}).get("pattern")
119+
if not patterns:
120+
return props.keys()
121+
else:
122+
return [driver["http"]["pattern"] for driver in props.values()]
123+
124+
patterns = _get_patterns()
125+
return _compile_supported_did_regex(patterns)

0 commit comments

Comments
 (0)