def test_uniresolver_docs(caplog, doc): caplog.set_level(logging.INFO) LOGGER.info("Doc\n%s", json.dumps(doc, indent=2)) DIDDocument.deserialize( doc, options={ doc_allow_public_key, doc_insert_missing_ids, vm_allow_controller_list, vm_allow_missing_controller, vm_allow_type_list, }, )
async def _resolve(self, profile: Profile, did: str) -> dict: """Resolve did:web DIDs.""" url = self.__transform_to_url(did) async with aiohttp.ClientSession() as session: async with session.get(url) as response: if response.status == 200: try: # Validate DIDDoc with pyDID did_doc = DIDDocument.from_json(await response.text()) return did_doc.serialize() except Exception as err: raise ResolverError( "Response was incorrectly formatted") from err if response.status == 404: raise DIDNotFound(f"No document found for {did}") raise ResolverError("Could not find doc for {}: {}".format( did, await response.text()))
async def resolve(self, profile: Profile, did: Union[str, DID]) -> DIDDocument: """Resolve a DID using this resolver.""" py_did = DID(did) if isinstance(did, str) else did if not self.supports(py_did.method): raise DIDMethodNotSupported( f"{self.__class__.__name__} does not support DID method {py_did.method}" ) did_document = await self._resolve(profile, str(py_did)) result = DIDDocument.deserialize( did_document, options={ doc_insert_missing_ids, doc_allow_public_key, vm_allow_controller_list, vm_allow_missing_controller, vm_allow_type_list, }, ) return result
async def resolve(self, profile: Profile, did: Union[str, DID]) -> DIDDocument: """Resolve a DID using this resolver.""" if isinstance(did, DID): did = str(did) else: DID.validate(did) if not await self.supports(profile, did): raise DIDMethodNotSupported( f"{self.__class__.__name__} does not support DID method for: {did}" ) doc_dict = await self._resolve(profile, did) return DIDDocument.deserialize( doc_dict, options={ doc_insert_missing_ids, doc_allow_public_key, vm_allow_controller_list, vm_allow_missing_controller, vm_allow_type_list, }, )
def resolver(): did_resolver_registry = DIDResolverRegistry() for method in TEST_DID_METHODS: resolver = MockResolver([method], DIDDocument.deserialize(DOC)) did_resolver_registry.register(resolver) return DIDResolver(did_resolver_registry)
async def _resolve(self, profile, did) -> DIDDocument: return DIDDocument("did:example:123")
def did_doc(): yield DIDDocument.deserialize(DOC)
from ....resolver.base import DIDMethodNotSupported, DIDNotFound, ResolverError from ....resolver.did_resolver import DIDResolver from ....resolver.tests import DOC from ....wallet.base import BaseWallet from ....wallet.error import WalletError from ....vc.ld_proofs.document_loader import DocumentLoader from .document_loader import custom_document_loader from .. import routes as test_module from ..error import ( BadJWSHeaderError, DroppedAttributeError, MissingVerificationMethodError, ) did_doc = DIDDocument.deserialize(DOC) @pytest.fixture def mock_resolver(): did_resolver = async_mock.MagicMock() did_resolver.resolve = async_mock.CoroutineMock(return_value=did_doc) url = "did:example:1234abcd#4" did_resolver.dereference = async_mock.CoroutineMock( return_value=did_doc.dereference(url) ) yield did_resolver @pytest.fixture def mock_sign_credential():
def test_uniresolver_docs_strict(caplog, doc): caplog.set_level(logging.INFO) LOGGER.info("Doc\n%s", json.dumps(doc, indent=2)) DIDDocument.deserialize(doc)