From 4a415e5e2c545da015db17dbde7cbc17b4fde6f0 Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Wed, 25 Oct 2023 15:07:08 -0400 Subject: [PATCH] fix: dif format handler tests Signed-off-by: Daniel Bluhm --- .../v2_0/formats/dif/tests/test_handler.py | 47 +++++-------------- aries_cloudagent/vc/vc_ld/models/options.py | 2 +- .../vc/vc_ld/models/presentation.py | 2 + .../vc/vc_ld/tests/test_manager.py | 14 ++++++ 4 files changed, 30 insertions(+), 35 deletions(-) diff --git a/aries_cloudagent/protocols/present_proof/v2_0/formats/dif/tests/test_handler.py b/aries_cloudagent/protocols/present_proof/v2_0/formats/dif/tests/test_handler.py index 8986ff42ac..6a3b365c8b 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/formats/dif/tests/test_handler.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/formats/dif/tests/test_handler.py @@ -1,49 +1,40 @@ from copy import deepcopy + from asynctest import TestCase as AsyncTestCase from asynctest import mock as async_mock from marshmallow import ValidationError from pyld import jsonld -from aries_cloudagent.protocols.present_proof.dif.pres_exch import SchemaInputDescriptor - +from .. import handler as test_module from .......core.in_memory import InMemoryProfile from .......messaging.decorators.attach_decorator import AttachDecorator -from .......messaging.responder import MockResponder, BaseResponder +from .......messaging.responder import BaseResponder, MockResponder from .......storage.vc_holder.base import VCHolder from .......storage.vc_holder.vc_record import VCRecord -from .......vc.ld_proofs import ( - DocumentLoader, - Ed25519Signature2018, - Ed25519Signature2020, - BbsBlsSignature2020, - BbsBlsSignatureProof2020, -) +from .......vc.ld_proofs import DocumentLoader from .......vc.tests.document_loader import custom_document_loader +from .......vc.vc_ld.manager import VcLdpManager from .......vc.vc_ld.validation_result import PresentationVerificationResult from .......wallet.base import BaseWallet - -from .....dif.pres_exch_handler import DIFPresExchHandler, DIFPresExchError +from .....dif.pres_exch import SchemaInputDescriptor +from .....dif.pres_exch_handler import DIFPresExchError, DIFPresExchHandler from .....dif.tests.test_data import ( - TEST_CRED_DICT, EXPANDED_CRED_FHIR_TYPE_1, EXPANDED_CRED_FHIR_TYPE_2, + TEST_CRED_DICT, ) - from ....message_types import ( ATTACHMENT_FORMAT, - PRES_20_REQUEST, PRES_20, PRES_20_PROPOSAL, + PRES_20_REQUEST, ) from ....messages.pres import V20Pres +from ....messages.pres_format import V20PresFormat from ....messages.pres_proposal import V20PresProposal from ....messages.pres_request import V20PresRequest -from ....messages.pres_format import V20PresFormat from ....models.pres_exchange import V20PresExRecord - from ...handler import V20PresFormatHandlerError - -from .. import handler as test_module from ..handler import DIFPresFormatHandler TEST_DID_SOV = "did:sov:LjgpST2rjsoxYegQDRm7EL" @@ -395,18 +386,6 @@ def test_validate_fields(self): incorrect_pres.pop("@context") self.handler.validate_fields(PRES_20, incorrect_pres) - async def test_get_all_suites(self): - suites = await self.handler._get_all_suites() - assert len(suites) == 4 - types = [ - Ed25519Signature2018, - Ed25519Signature2020, - BbsBlsSignature2020, - BbsBlsSignatureProof2020, - ] - for suite in suites: - assert type(suite) in types - async def test_create_bound_request_a(self): dif_proposal_dict = { "input_descriptors": [ @@ -1164,7 +1143,7 @@ async def test_verify_pres_sequence(self): ) with async_mock.patch.object( - test_module, + VcLdpManager, "verify_presentation", async_mock.CoroutineMock( return_value=PresentationVerificationResult(verified=True) @@ -1174,7 +1153,7 @@ async def test_verify_pres_sequence(self): assert output.verified with async_mock.patch.object( - test_module, + VcLdpManager, "verify_presentation", async_mock.CoroutineMock( return_value=PresentationVerificationResult(verified=False) @@ -1221,7 +1200,7 @@ async def test_verify_pres(self): ) with async_mock.patch.object( - test_module, + VcLdpManager, "verify_presentation", async_mock.CoroutineMock( return_value=PresentationVerificationResult(verified=True) diff --git a/aries_cloudagent/vc/vc_ld/models/options.py b/aries_cloudagent/vc/vc_ld/models/options.py index 949759b3c6..f34ef3c5ab 100644 --- a/aries_cloudagent/vc/vc_ld/models/options.py +++ b/aries_cloudagent/vc/vc_ld/models/options.py @@ -101,7 +101,7 @@ class Meta: proof_type = fields.Str( data_key="proofType", - required=True, + required=False, metadata={ "description": ( "The proof type used for the proof. Should match suites registered in" diff --git a/aries_cloudagent/vc/vc_ld/models/presentation.py b/aries_cloudagent/vc/vc_ld/models/presentation.py index 627001e451..0e467c9fa5 100644 --- a/aries_cloudagent/vc/vc_ld/models/presentation.py +++ b/aries_cloudagent/vc/vc_ld/models/presentation.py @@ -25,8 +25,10 @@ def __init__( types: Optional[Sequence[str]] = None, credentials: Optional[Sequence[dict]] = None, proof: Optional[Sequence[dict]] = None, + **kwargs, ): """Initialize VerifiablePresentation.""" + super().__init__() self.id = id self.contexts = contexts self.types = types diff --git a/aries_cloudagent/vc/vc_ld/tests/test_manager.py b/aries_cloudagent/vc/vc_ld/tests/test_manager.py index e1cf05171d..ebe8957e84 100644 --- a/aries_cloudagent/vc/vc_ld/tests/test_manager.py +++ b/aries_cloudagent/vc/vc_ld/tests/test_manager.py @@ -20,6 +20,7 @@ ) from ...ld_proofs.purposes.credential_issuance_purpose import CredentialIssuancePurpose from ...ld_proofs.suites.bbs_bls_signature_2020 import BbsBlsSignature2020 +from ...ld_proofs.suites.bbs_bls_signature_proof_2020 import BbsBlsSignatureProof2020 from ...ld_proofs.suites.ed25519_signature_2018 import Ed25519Signature2018 from ...ld_proofs.suites.ed25519_signature_2020 import Ed25519Signature2020 from ..manager import VcLdpManager, VcLdpManagerError @@ -281,3 +282,16 @@ async def test_issue_ed25519_2020(): async def test_issue_bbs(): """Ensure BBS context is added to issued cred.""" raise NotImplementedError() + + +async def test_get_all_suites(manager: VcLdpManager): + suites = await manager._get_all_suites() + assert len(suites) == 4 + types = ( + Ed25519Signature2018, + Ed25519Signature2020, + BbsBlsSignature2020, + BbsBlsSignatureProof2020, + ) + for suite in suites: + assert isinstance(suite, types)