Skip to content

Commit

Permalink
Merge pull request openwallet-foundation#86 from sicpa-dlab/fix/resol…
Browse files Browse the repository at this point in the history
…ution

Fix/resolution
  • Loading branch information
dbluhm authored May 15, 2021
2 parents 43a0575 + 5b15baf commit 31271a6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion aries_cloudagent/resolver/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ async def resolve_with_metadata(py_did):

py_did = DID(did) if isinstance(did, str) else did

if not await self.supports(profile, py_did.method):
if not await self.supports(profile, py_did):
raise DIDMethodNotSupported(
f"{self.__class__.__name__} does not support DID method {py_did.method}"
)
Expand Down
3 changes: 2 additions & 1 deletion aries_cloudagent/resolver/did_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ async def resolve(
resolution: ResolutionResult = await resolver.resolve(
profile,
py_did,
retrieve_metadata
)
if resolution.metadata:
LOGGER.debug(
Expand All @@ -52,7 +53,7 @@ async def resolve(
resolution.metadata._asdict(),
)
return resolution
except DIDNotFound:
except (DIDNotFound, DIDMethodNotSupported):
LOGGER.debug("DID %s not found by resolver %s", did, resolver)

raise DIDNotFound(f"DID {did} could not be resolved")
Expand Down
4 changes: 3 additions & 1 deletion aries_cloudagent/resolver/tests/test_base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Test Base DID Resolver methods."""

from typing import Union
from unittest.mock import MagicMock

import pytest
from pydid import DID, DIDDocument
Expand Down Expand Up @@ -50,7 +51,8 @@ def test_native_on_non_native(non_native_resolver):


@pytest.mark.asyncio
async def test_supports(profile: Profile, native_resolver):
async def test_supports(native_resolver):
profile = MagicMock()
assert await native_resolver.supports(profile, "did:test:123") is True
assert await native_resolver.supports(profile, "not supported") is False

Expand Down
22 changes: 14 additions & 8 deletions aries_cloudagent/resolver/tests/test_did_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,29 +107,35 @@ def test_create_resolver(resolver):
@pytest.mark.asyncio
@pytest.mark.parametrize("did, method", zip(TEST_DIDS, TEST_DID_METHODS))
async def test_match_did_to_resolver(profile, resolver, did, method):
base_resolver, *_ = resolver._match_did_to_resolver(DID(did))
base_resolver, *_ = await resolver._match_did_to_resolver(profile, DID(did))
assert await base_resolver.supports(profile, did)


def test_match_did_to_resolver_x_not_supported(resolver):
@pytest.mark.asyncio
async def test_match_did_to_resolver_x_not_supported(profile, resolver):
# TODO: FIX
py_did = DID("did:cowsay:EiDahaOGH-liLLdDtTxEAdc8i-cfCz-WUcQdRJheMVNn3A")
with pytest.raises(DIDMethodNotSupported):
resolver._match_did_to_resolver(py_did)
await resolver._match_did_to_resolver(profile, py_did)


def test_match_did_to_resolver_native_priority(profile):
@pytest.mark.asyncio
async def test_match_did_to_resolver_native_priority(profile):
registry = DIDResolverRegistry()
native = MockResolver(["sov"], native=True)
non_native = MockResolver(["sov"], native=False)
registry.register(non_native)
registry.register(native)
resolver = DIDResolver(registry)
assert [native, non_native] == resolver._match_did_to_resolver(

result = await resolver._match_did_to_resolver(
profile, DID(TEST_DID0)
)
assert [native, non_native] == result


def test_match_did_to_resolver_registration_order(profile):
@pytest.mark.asyncio
async def test_match_did_to_resolver_registration_order(profile):
registry = DIDResolverRegistry()
native1 = MockResolver(["sov"], native=True)
registry.register(native1)
Expand All @@ -140,7 +146,7 @@ def test_match_did_to_resolver_registration_order(profile):
native4 = MockResolver(["sov"], native=True)
registry.register(native4)
resolver = DIDResolver(registry)
assert [native1, native2, native4, non_native3] == resolver._match_did_to_resolver(
assert [native1, native2, native4, non_native3] == await resolver._match_did_to_resolver(
profile, DID(TEST_DID0)
)

Expand Down Expand Up @@ -177,7 +183,7 @@ async def test_resolve_did(resolver, profile, did):
@pytest.mark.asyncio
async def test_resolve_did_x_not_supported(resolver, profile):
py_did = DID("did:cowsay:EiDahaOGH-liLLdDtTxEAdc8i-cfCz-WUcQdRJheMVNn3A")
with pytest.raises(DIDMethodNotSupported):
with pytest.raises(DIDNotFound):
await resolver.resolve(profile, py_did)


Expand Down

0 comments on commit 31271a6

Please sign in to comment.