From b863fbd5df370143160a098f0804fee53cb047ee Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Wed, 6 Dec 2023 16:03:17 -0500 Subject: [PATCH] fix: didexchange manager tests Signed-off-by: Daniel Bluhm --- .../connections/tests/test_base_manager.py | 11 + .../protocols/didexchange/v1_0/manager.py | 72 +----- .../didexchange/v1_0/tests/test_manager.py | 230 +++++------------- 3 files changed, 90 insertions(+), 223 deletions(-) diff --git a/aries_cloudagent/connections/tests/test_base_manager.py b/aries_cloudagent/connections/tests/test_base_manager.py index 39437d9a74..8ce3cad699 100644 --- a/aries_cloudagent/connections/tests/test_base_manager.py +++ b/aries_cloudagent/connections/tests/test_base_manager.py @@ -1727,3 +1727,14 @@ async def test_get_endpoints(self): "localhost:8020", "10.20.30.40:5060", ) + + async def test_diddoc_connection_targets_diddoc(self): + did_doc = self.make_did_doc( + self.test_target_did, + self.test_target_verkey, + ) + targets = self.manager.diddoc_connection_targets( + did_doc, + self.test_verkey, + ) + assert isinstance(targets[0], ConnectionTarget) diff --git a/aries_cloudagent/protocols/didexchange/v1_0/manager.py b/aries_cloudagent/protocols/didexchange/v1_0/manager.py index 80e95b25cf..08787ec8c6 100644 --- a/aries_cloudagent/protocols/didexchange/v1_0/manager.py +++ b/aries_cloudagent/protocols/didexchange/v1_0/manager.py @@ -4,9 +4,6 @@ import logging from typing import Optional -import pydid -from pydid import BaseDIDDocument as ResolvedDocument -from pydid import DIDCommService from ....connections.base_manager import BaseConnectionManager from ....connections.models.conn_record import ConnRecord @@ -16,8 +13,6 @@ from ....did.did_key import DIDKey from ....messaging.decorators.attach_decorator import AttachDecorator from ....messaging.responder import BaseResponder -from ....resolver.base import ResolverError -from ....resolver.did_resolver import DIDResolver from ....storage.error import StorageNotFoundError from ....transport.inbound.receipt import MessageReceipt from ....wallet.base import BaseWallet @@ -142,12 +137,10 @@ async def receive_invitation( # Save the invitation for later processing await conn_rec.attach_invitation(session, invitation) if not conn_rec.invitation_key and conn_rec.their_public_did: - did_document = await self.get_resolved_did_document( + targets = await self.resolve_connection_targets( conn_rec.their_public_did ) - conn_rec.invitation_key = did_document.verification_method[ - 0 - ].public_key_base58 + conn_rec.invitation_key = targets[0].recipient_keys[0] await self._route_manager.save_mediator_for_connection( self.profile, conn_rec, mediation_id=mediation_id @@ -335,12 +328,11 @@ async def create_request( await attach.data.sign(my_info.verkey, wallet) did = conn_rec.my_did + did_url = None if conn_rec.their_public_did is not None: - qualified_did = conn_rec.their_public_did - did_document = await self.get_resolved_did_document(qualified_did) - did_url = await self.get_first_applicable_didcomm_service(did_document) - else: - did_url = None + services = await self.resolve_didcomm_services(conn_rec.their_public_did) + if services: + did_url = services[0].id pthid = conn_rec.invitation_msg_id or did_url @@ -760,17 +752,19 @@ async def accept_response( ) their_did = response.did - # Special case: legacy DIDs were unqualified in response, qualified in doc - if their_did and not their_did.startswith("did:"): - their_did = f"did:sov:{their_did}" - if response.did_doc_attach: async with self.profile.session() as session: wallet = session.inject(BaseWallet) conn_did_doc = await self.verify_diddoc( wallet, response.did_doc_attach, conn_rec.invitation_key ) - if their_did != conn_did_doc["id"]: + # Special case: legacy DIDs were unqualified in response, qualified in doc + if their_did and not their_did.startswith("did:"): + did_to_check = f"did:sov:{their_did}" + else: + did_to_check = their_did + + if did_to_check != conn_did_doc["id"]: raise DIDXManagerError( f"Connection DID {their_did} " f"does not match DID doc id {conn_did_doc['id']}" @@ -951,43 +945,3 @@ async def verify_diddoc( raise DIDXManagerError("DID doc attachment signature failed verification") return json.loads(signed_diddoc_bytes.decode()) - - async def get_resolved_did_document(self, qualified_did: str) -> ResolvedDocument: - """Return resolved DID document.""" - resolver = self._profile.inject(DIDResolver) - if not qualified_did.startswith("did:"): - qualified_did = f"did:sov:{qualified_did}" - try: - doc_dict: dict = await resolver.resolve(self._profile, qualified_did) - doc = pydid.deserialize_document(doc_dict, strict=True) - return doc - except ResolverError as error: - raise DIDXManagerError( - "Failed to resolve public DID in invitation" - ) from error - - async def get_first_applicable_didcomm_service( - self, did_doc: ResolvedDocument - ) -> str: - """Return first applicable DIDComm service url with highest priority.""" - if not did_doc.service: - raise DIDXManagerError( - "Cannot connect via public DID that has no associated services" - ) - - didcomm_services = sorted( - [ - service - for service in did_doc.service - if isinstance(service, DIDCommService) - ], - key=lambda service: service.priority, - ) - - if not didcomm_services: - raise DIDXManagerError( - "Cannot connect via public DID that has no associated DIDComm services" - ) - - first_didcomm_service, *_ = didcomm_services - return first_didcomm_service.id diff --git a/aries_cloudagent/protocols/didexchange/v1_0/tests/test_manager.py b/aries_cloudagent/protocols/didexchange/v1_0/tests/test_manager.py index d6511ee48a..cedb58ca0b 100644 --- a/aries_cloudagent/protocols/didexchange/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/didexchange/v1_0/tests/test_manager.py @@ -7,9 +7,7 @@ from .. import manager as test_module from .....cache.base import BaseCache from .....cache.in_memory import InMemoryCache -from .....connections.base_manager import BaseConnectionManagerError from .....connections.models.conn_record import ConnRecord -from .....connections.models.connection_target import ConnectionTarget from .....connections.models.diddoc import DIDDoc, PublicKey, PublicKeyType, Service from .....core.in_memory import InMemoryProfile from .....core.oob_processor import OobMessageProcessor @@ -19,7 +17,6 @@ from .....messaging.responder import BaseResponder, MockResponder from .....multitenant.base import BaseMultitenantManager from .....multitenant.manager import MultitenantManager -from .....resolver.base import ResolverError from .....resolver.did_resolver import DIDResolver from .....resolver.tests import DOC from .....storage.error import StorageNotFoundError @@ -208,7 +205,12 @@ async def test_receive_invitation_oob_public_did(self): test_module, "AttachDecorator", autospec=True ) as mock_attach_deco, mock.patch.object( self.multitenant_mgr, "get_default_mediator" - ) as mock_get_default_mediator: + ) as mock_get_default_mediator, mock.patch.object( + self.manager, "resolve_connection_targets", mock.CoroutineMock() + ) as mock_resolve_targets: + mock_resolve_targets.return_value = [ + mock.MagicMock(recipient_keys=["test"]) + ] mock_get_default_mediator.return_value = None invi_rec = await self.oob_manager.create_invitation( my_endpoint="testendpoint", @@ -572,8 +574,6 @@ async def test_receive_request_explicit_public_did(self): with mock.patch.object( test_module, "ConnRecord", mock.MagicMock() ) as mock_conn_rec_cls, mock.patch.object( - test_module, "DIDDoc", autospec=True - ) as mock_did_doc, mock.patch.object( test_module, "DIDPosture", autospec=True ) as mock_did_posture, mock.patch.object( test_module, "AttachDecorator", autospec=True @@ -582,12 +582,16 @@ async def test_receive_request_explicit_public_did(self): ) as mock_response, mock.patch.object( self.manager, "verify_diddoc", - mock.CoroutineMock(return_value=DIDDoc(TestConfig.test_did)), + mock.CoroutineMock( + return_value={"id": "did:sov:" + TestConfig.test_did} + ), ), mock.patch.object( self.manager, "create_did_document", mock.CoroutineMock() ) as mock_create_did_doc, mock.patch.object( MediationManager, "prepare_request", autospec=True - ) as mock_mediation_mgr_prep_req: + ) as mock_mediation_mgr_prep_req, mock.patch.object( + self.manager, "store_did_document", mock.CoroutineMock() + ): mock_create_did_doc.return_value = mock.MagicMock( serialize=mock.MagicMock(return_value={}) ) @@ -622,9 +626,6 @@ async def test_receive_request_explicit_public_did(self): return_value=test_module.DIDPosture.PUBLIC ) - mock_did_doc.from_json = mock.MagicMock( - return_value=mock.MagicMock(did=TestConfig.test_did) - ) mock_attach_deco.data_base64 = mock.MagicMock( return_value=mock.MagicMock( data=mock.MagicMock(sign=mock.CoroutineMock()) @@ -710,8 +711,6 @@ async def test_receive_request_public_did_no_did_doc_attachment(self): with mock.patch.object( test_module, "ConnRecord", mock.MagicMock() ) as mock_conn_rec_cls, mock.patch.object( - test_module, "DIDDoc", autospec=True - ) as mock_did_doc, mock.patch.object( test_module, "DIDPosture", autospec=True ) as mock_did_posture, mock.patch.object( test_module, "AttachDecorator", autospec=True @@ -720,7 +719,7 @@ async def test_receive_request_public_did_no_did_doc_attachment(self): ) as mock_response, mock.patch.object( self.manager, "verify_diddoc", - mock.CoroutineMock(return_value=DIDDoc(TestConfig.test_did)), + mock.CoroutineMock(return_value={"id": TestConfig.test_did}), ), mock.patch.object( self.manager, "create_did_document", mock.CoroutineMock() ) as mock_create_did_doc, mock.patch.object( @@ -762,9 +761,6 @@ async def test_receive_request_public_did_no_did_doc_attachment(self): return_value=test_module.DIDPosture.PUBLIC ) - mock_did_doc.from_json = mock.MagicMock( - return_value=mock.MagicMock(did=TestConfig.test_did) - ) mock_attach_deco.data_base64 = mock.MagicMock( return_value=mock.MagicMock( data=mock.MagicMock(sign=mock.CoroutineMock()) @@ -919,11 +915,11 @@ async def test_receive_request_public_did_x_wrong_did(self): ) as mock_conn_rec_cls, mock.patch.object( test_module, "DIDPosture", autospec=True ) as mock_did_posture, mock.patch.object( - test_module.DIDDoc, "from_json", mock.MagicMock() - ) as mock_did_doc_from_json, mock.patch.object( self.manager, "verify_diddoc", - mock.CoroutineMock(return_value=DIDDoc("LjgpST2rjsoxYegQDRm7EL")), + mock.CoroutineMock(return_value={"id": "LjgpST2rjsoxYegQDRm7EL"}), + ), mock.patch.object( + self.manager, "store_did_document", mock.CoroutineMock() ): mock_conn_record = mock.MagicMock( accept=ConnRecord.ACCEPT_MANUAL, @@ -938,7 +934,6 @@ async def test_receive_request_public_did_x_wrong_did(self): mock_conn_rec_cls.retrieve_by_invitation_msg_id = mock.CoroutineMock( return_value=mock_conn_record ) - mock_did_doc_from_json.return_value = mock.MagicMock(did="wrong-did") mock_did_posture.get = mock.MagicMock( return_value=test_module.DIDPosture.PUBLIC @@ -1047,12 +1042,7 @@ async def test_receive_request_public_did_no_public_invites(self): test_module, "DIDXResponse", autospec=True ) as mock_response, mock.patch.object( self.manager, "create_did_document", mock.CoroutineMock() - ) as mock_create_did_doc, mock.patch.object( - test_module.DIDDoc, "from_json", mock.MagicMock() - ) as mock_did_doc_from_json: - mock_did_doc_from_json.return_value = mock.MagicMock( - did=TestConfig.test_did - ) + ) as mock_create_did_doc: with self.assertRaises(DIDXManagerError) as context: await self.manager.receive_request( request=mock_request, @@ -1092,8 +1082,6 @@ async def test_receive_request_public_did_no_auto_accept(self): with mock.patch.object( test_module, "ConnRecord", mock.MagicMock() ) as mock_conn_rec_cls, mock.patch.object( - test_module, "DIDDoc", autospec=True - ) as mock_did_doc, mock.patch.object( test_module, "DIDPosture", autospec=True ) as mock_did_posture, mock.patch.object( test_module, "AttachDecorator", autospec=True @@ -1104,7 +1092,11 @@ async def test_receive_request_public_did_no_auto_accept(self): ) as mock_create_did_doc, mock.patch.object( self.manager, "verify_diddoc", - mock.CoroutineMock(return_value=DIDDoc(TestConfig.test_did)), + mock.CoroutineMock( + return_value={"id": "did:sov:" + TestConfig.test_did} + ), + ), mock.patch.object( + self.manager, "store_did_document", mock.CoroutineMock() ): mock_conn_record = mock.MagicMock( accept=ConnRecord.ACCEPT_MANUAL, @@ -1124,9 +1116,6 @@ async def test_receive_request_public_did_no_auto_accept(self): return_value=test_module.DIDPosture.PUBLIC ) - mock_did_doc.from_json = mock.MagicMock( - return_value=mock.MagicMock(did=TestConfig.test_did) - ) conn_rec = await self.manager.receive_request( request=mock_request, recipient_did=TestConfig.test_did, @@ -1175,13 +1164,15 @@ async def test_receive_request_implicit_public_did_not_enabled(self): with mock.patch.object( test_module, "ConnRecord", mock.MagicMock() ) as mock_conn_rec_cls, mock.patch.object( - test_module, "DIDDoc", autospec=True - ) as mock_did_doc, mock.patch.object( test_module, "DIDPosture", autospec=True ) as mock_did_posture, mock.patch.object( self.manager, "verify_diddoc", - mock.CoroutineMock(return_value=DIDDoc(TestConfig.test_did)), + mock.CoroutineMock( + return_value={"id": "did:sov:" + TestConfig.test_did} + ), + ), mock.patch.object( + self.manager, "store_did_document", mock.CoroutineMock() ): mock_did_posture.get = mock.MagicMock( return_value=test_module.DIDPosture.PUBLIC @@ -1241,13 +1232,15 @@ async def test_receive_request_implicit_public_did(self): with mock.patch.object( test_module, "ConnRecord", mock.MagicMock() ) as mock_conn_rec_cls, mock.patch.object( - test_module, "DIDDoc", autospec=True - ) as mock_did_doc, mock.patch.object( test_module, "DIDPosture", autospec=True ) as mock_did_posture, mock.patch.object( self.manager, "verify_diddoc", - mock.CoroutineMock(return_value=DIDDoc(TestConfig.test_did)), + mock.CoroutineMock( + return_value={"id": "did:sov:" + TestConfig.test_did} + ), + ), mock.patch.object( + self.manager, "store_did_document", mock.CoroutineMock() ): mock_did_posture.get = mock.MagicMock( return_value=test_module.DIDPosture.PUBLIC @@ -1325,15 +1318,17 @@ async def test_receive_request_peer_did(self): with mock.patch.object( test_module, "ConnRecord", mock.MagicMock() ) as mock_conn_rec_cls, mock.patch.object( - test_module, "DIDDoc", autospec=True - ) as mock_did_doc, mock.patch.object( test_module, "AttachDecorator", autospec=True ) as mock_attach_deco, mock.patch.object( test_module, "DIDXResponse", autospec=True ) as mock_response, mock.patch.object( self.manager, "verify_diddoc", - mock.CoroutineMock(return_value=DIDDoc(TestConfig.test_did)), + mock.CoroutineMock( + return_value={"id": "did:sov:" + TestConfig.test_did} + ), + ), mock.patch.object( + self.manager, "store_did_document", mock.CoroutineMock() ): mock_conn_rec_cls.retrieve_by_invitation_key = mock.CoroutineMock( return_value=mock_conn @@ -1347,9 +1342,6 @@ async def test_receive_request_peer_did(self): save=mock.CoroutineMock(), metadata_set=mock.CoroutineMock(), ) - mock_did_doc.from_json = mock.MagicMock( - return_value=mock.MagicMock(did=TestConfig.test_did) - ) mock_attach_deco.data_base64 = mock.MagicMock( return_value=mock.MagicMock( data=mock.MagicMock(sign=mock.CoroutineMock()) @@ -1421,8 +1413,6 @@ async def test_create_response(self): ) as mock_retrieve_req, mock.patch.object( conn_rec, "save", mock.CoroutineMock() ) as mock_save, mock.patch.object( - test_module, "DIDDoc", autospec=True - ) as mock_did_doc, mock.patch.object( test_module, "AttachDecorator", autospec=True ) as mock_attach_deco, mock.patch.object( test_module, "DIDXResponse", autospec=True @@ -1590,8 +1580,6 @@ async def test_create_response_conn_rec_my_did(self): ) as mock_retrieve_req, mock.patch.object( conn_rec, "save", mock.CoroutineMock() ) as mock_save, mock.patch.object( - test_module, "DIDDoc", autospec=True - ) as mock_did_doc, mock.patch.object( test_module, "AttachDecorator", autospec=True ) as mock_attach_deco, mock.patch.object( test_module, "DIDXResponse", autospec=True @@ -1640,8 +1628,6 @@ async def test_create_response_use_public_did(self): ) as mock_retrieve_req, mock.patch.object( conn_rec, "save", mock.CoroutineMock() ) as mock_save, mock.patch.object( - test_module, "DIDDoc", autospec=True - ) as mock_did_doc, mock.patch.object( test_module, "AttachDecorator", autospec=True ) as mock_attach_deco, mock.patch.object( test_module, "DIDXResponse", autospec=True @@ -1671,8 +1657,6 @@ async def test_create_response_use_public_did_x_no_public_did(self): ) as mock_retrieve_req, mock.patch.object( conn_rec, "save", mock.CoroutineMock() ) as mock_save, mock.patch.object( - test_module, "DIDDoc", autospec=True - ) as mock_did_doc, mock.patch.object( test_module, "AttachDecorator", autospec=True ) as mock_attach_deco, mock.patch.object( test_module, "DIDXResponse", autospec=True @@ -1702,7 +1686,11 @@ async def test_accept_response_find_by_thread_id(self): data=mock.MagicMock( verify=mock.CoroutineMock(return_value=True), signed=mock.MagicMock( - decode=mock.MagicMock(return_value=json.dumps({"dummy": "did-doc"})) + decode=mock.MagicMock( + return_value=json.dumps( + {"id": "did:sov:" + TestConfig.test_target_did} + ) + ) ), ) ) @@ -1719,11 +1707,8 @@ async def test_accept_response_find_by_thread_id(self): ) as mock_conn_retrieve_by_req_id, mock.patch.object( ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_id, mock.patch.object( - DIDDoc, "deserialize", mock.MagicMock() - ) as mock_did_doc_deser: - mock_did_doc_deser.return_value = mock.MagicMock( - did=TestConfig.test_target_did - ) + self.manager, "store_did_document", mock.CoroutineMock() + ): mock_conn_retrieve_by_req_id.return_value = mock.MagicMock( did=TestConfig.test_target_did, did_doc_attach=mock.MagicMock( @@ -1758,7 +1743,11 @@ async def test_accept_response_find_by_thread_id_auto_disclose_features(self): data=mock.MagicMock( verify=mock.CoroutineMock(return_value=True), signed=mock.MagicMock( - decode=mock.MagicMock(return_value=json.dumps({"dummy": "did-doc"})) + decode=mock.MagicMock( + return_value=json.dumps( + {"id": "did:sov:" + TestConfig.test_target_did} + ) + ) ), ) ) @@ -1776,13 +1765,10 @@ async def test_accept_response_find_by_thread_id_auto_disclose_features(self): ) as mock_conn_retrieve_by_req_id, mock.patch.object( ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_id, mock.patch.object( - DIDDoc, "deserialize", mock.MagicMock() - ) as mock_did_doc_deser, mock.patch.object( V20DiscoveryMgr, "proactive_disclose_features", mock.CoroutineMock() - ) as mock_proactive_disclose_features: - mock_did_doc_deser.return_value = mock.MagicMock( - did=TestConfig.test_target_did - ) + ) as mock_proactive_disclose_features, mock.patch.object( + self.manager, "store_did_document", mock.CoroutineMock() + ): mock_conn_retrieve_by_req_id.return_value = mock.MagicMock( did=TestConfig.test_target_did, did_doc_attach=mock.MagicMock( @@ -1818,7 +1804,11 @@ async def test_accept_response_not_found_by_thread_id_receipt_has_sender_did(sel data=mock.MagicMock( verify=mock.CoroutineMock(return_value=True), signed=mock.MagicMock( - decode=mock.MagicMock(return_value=json.dumps({"dummy": "did-doc"})) + decode=mock.MagicMock( + return_value=json.dumps( + {"id": "did:sov:" + TestConfig.test_target_did} + ) + ) ), ) ) @@ -1832,11 +1822,8 @@ async def test_accept_response_not_found_by_thread_id_receipt_has_sender_did(sel ) as mock_conn_retrieve_by_req_id, mock.patch.object( ConnRecord, "retrieve_by_did", mock.CoroutineMock() ) as mock_conn_retrieve_by_did, mock.patch.object( - DIDDoc, "deserialize", mock.MagicMock() - ) as mock_did_doc_deser: - mock_did_doc_deser.return_value = mock.MagicMock( - did=TestConfig.test_target_did - ) + self.manager, "store_did_document", mock.CoroutineMock() + ): mock_conn_retrieve_by_req_id.side_effect = StorageNotFoundError() mock_conn_retrieve_by_did.return_value = mock.MagicMock( did=TestConfig.test_target_did, @@ -1933,13 +1920,8 @@ async def test_accept_response_find_by_thread_id_no_did_doc_attached(self): ) as mock_conn_retrieve_by_req_id, mock.patch.object( ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_id, mock.patch.object( - DIDDoc, "deserialize", mock.MagicMock() - ) as mock_did_doc_deser, mock.patch.object( self.manager, "record_did", mock.CoroutineMock() ): - mock_did_doc_deser.return_value = mock.MagicMock( - did=TestConfig.test_target_did - ) mock_conn_retrieve_by_req_id.return_value = mock.MagicMock( did=TestConfig.test_target_did, state=ConnRecord.State.REQUEST.rfc23, @@ -1974,13 +1956,8 @@ async def test_accept_response_find_by_thread_id_no_did_doc_attached_no_did(self ) as mock_conn_retrieve_by_req_id, mock.patch.object( ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_id, mock.patch.object( - DIDDoc, "deserialize", mock.MagicMock() - ) as mock_did_doc_deser, mock.patch.object( self.manager, "record_did", mock.CoroutineMock() ): - mock_did_doc_deser.return_value = mock.MagicMock( - did=TestConfig.test_target_did - ) mock_conn_retrieve_by_req_id.return_value = mock.MagicMock( did=TestConfig.test_target_did, state=ConnRecord.State.REQUEST.rfc23, @@ -2005,7 +1982,11 @@ async def test_accept_response_find_by_thread_id_did_mismatch(self): data=mock.MagicMock( verify=mock.CoroutineMock(return_value=True), signed=mock.MagicMock( - decode=mock.MagicMock(return_value=json.dumps({"dummy": "did-doc"})) + decode=mock.MagicMock( + return_value=json.dumps( + {"id": "did:sov:" + TestConfig.test_did} + ) + ) ), ) ) @@ -2019,9 +2000,8 @@ async def test_accept_response_find_by_thread_id_did_mismatch(self): ) as mock_conn_retrieve_by_req_id, mock.patch.object( ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_id, mock.patch.object( - DIDDoc, "deserialize", mock.MagicMock() - ) as mock_did_doc_deser: - mock_did_doc_deser.return_value = mock.MagicMock(did=TestConfig.test_did) + self.manager, "store_did_document", mock.CoroutineMock() + ): mock_conn_retrieve_by_req_id.return_value = mock.MagicMock( did=TestConfig.test_target_did, did_doc_attach=mock.MagicMock( @@ -2162,81 +2142,3 @@ async def test_receive_problem_report_x_unrecognized_code(self): with self.assertRaises(DIDXManagerError) as context: await self.manager.receive_problem_report(mock_conn, report) assert "unrecognized problem report" in str(context.exception) - - async def test_create_did_document(self): - did_info = DIDInfo( - TestConfig.test_did, - TestConfig.test_verkey, - None, - method=SOV, - key_type=ED25519, - ) - - did_doc = await self.manager.create_did_document( - did_info=did_info, - svc_endpoints=[TestConfig.test_endpoint], - ) - - async def test_did_key_storage(self): - did_info = DIDInfo( - TestConfig.test_did, - TestConfig.test_verkey, - None, - method=SOV, - key_type=ED25519, - ) - - did_doc = self.make_did_doc( - did=TestConfig.test_target_did, verkey=TestConfig.test_target_verkey - ) - - await self.manager.add_key_for_did( - did=TestConfig.test_target_did, key=TestConfig.test_target_verkey - ) - - did = await self.manager.find_did_for_key(key=TestConfig.test_target_verkey) - assert did == TestConfig.test_target_did - await self.manager.remove_keys_for_did(TestConfig.test_target_did) - - async def test_diddoc_connection_targets_diddoc(self): - did_doc = self.make_did_doc( - TestConfig.test_target_did, - TestConfig.test_target_verkey, - ) - targets = self.manager.diddoc_connection_targets( - did_doc, - TestConfig.test_verkey, - ) - assert isinstance(targets[0], ConnectionTarget) - - async def test_diddoc_connection_targets_diddoc_underspecified(self): - with self.assertRaises(BaseConnectionManagerError): - self.manager.diddoc_connection_targets(None, TestConfig.test_verkey) - - x_did_doc = DIDDoc(did=None) - with self.assertRaises(BaseConnectionManagerError): - self.manager.diddoc_connection_targets(x_did_doc, TestConfig.test_verkey) - - x_did_doc = self.make_did_doc( - did=TestConfig.test_target_did, verkey=TestConfig.test_target_verkey - ) - x_did_doc._service = {} - with self.assertRaises(BaseConnectionManagerError): - self.manager.diddoc_connection_targets(x_did_doc, TestConfig.test_verkey) - - async def test_resolve_did_document_error(self): - public_did_info = None - async with self.profile.session() as session: - await session.wallet.create_public_did( - SOV, - ED25519, - ) - public_did_info = await session.wallet.get_public_did() - with mock.patch.object( - self.resolver, - "resolve", - mock.CoroutineMock(side_effect=ResolverError()), - ): - with self.assertRaises(DIDXManagerError) as ctx: - await self.manager.get_resolved_did_document(public_did_info.did) - assert "Failed to resolve public DID in invitation" in str(ctx.exception)