From 16819d958ef91398137bfbafd44fc07346214030 Mon Sep 17 00:00:00 2001 From: jamshale Date: Thu, 15 Feb 2024 21:12:35 +0000 Subject: [PATCH 1/3] Revert profile inject Signed-off-by: jamshale --- aries_cloudagent/config/provider.py | 10 +++------- aries_cloudagent/core/profile.py | 14 +++----------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/aries_cloudagent/config/provider.py b/aries_cloudagent/config/provider.py index c97c300cec..17a4e22b70 100644 --- a/aries_cloudagent/config/provider.py +++ b/aries_cloudagent/config/provider.py @@ -1,14 +1,12 @@ """Service provider implementations.""" import hashlib - from typing import Optional, Sequence, Union from weakref import ReferenceType from ..utils.classloader import DeferLoad from ..utils.stats import Collector - -from .base import BaseProvider, BaseSettings, BaseInjector, InjectionError +from .base import BaseInjector, BaseProvider, BaseSettings, InjectionError class InstanceProvider(BaseProvider): @@ -52,10 +50,8 @@ def __init__( self._ctor_kwargs = ctor_kwargs self._init_method = init_method if isinstance(instance_cls, str): - cls = DeferLoad(instance_cls) - else: - cls = instance_cls - self._instance_cls: Union[type, DeferLoad] = cls + instance_cls = DeferLoad(instance_cls) + self._instance_cls = instance_cls def provide(self, config: BaseSettings, injector: BaseInjector): """Provide the object instance given a config and injector.""" diff --git a/aries_cloudagent/core/profile.py b/aries_cloudagent/core/profile.py index 395e320d23..7b2b2f50da 100644 --- a/aries_cloudagent/core/profile.py +++ b/aries_cloudagent/core/profile.py @@ -1,20 +1,17 @@ """Classes for managing profile information within a request context.""" import logging - from abc import ABC, abstractmethod from typing import Any, Mapping, Optional, Type -from weakref import ref -from .event_bus import EventBus, Event from ..config.base import InjectionError -from ..config.injector import BaseInjector, InjectType from ..config.injection_context import InjectionContext +from ..config.injector import BaseInjector, InjectType from ..config.provider import BaseProvider from ..config.settings import BaseSettings from ..utils.classloader import ClassLoader, ClassNotFoundError - from .error import ProfileSessionInactiveError +from .event_bus import Event, EventBus LOGGER = logging.getLogger(__name__) @@ -33,14 +30,9 @@ def __init__( created: bool = False, ): """Initialize a base profile.""" - context = context or InjectionContext() - scope = "profile" - if name: - scope += ":" + name - self._context = context.start_scope(scope) + self._context = context or InjectionContext() self._created = created self._name = name or Profile.DEFAULT_NAME - self._context.injector.bind_instance(Profile, ref(self)) @property def backend(self) -> str: From c605494a9f54a74695896071d717ed84a123b417 Mon Sep 17 00:00:00 2001 From: jamshale Date: Thu, 15 Feb 2024 22:47:32 +0000 Subject: [PATCH 2/3] Revert VcLdpManager as plugable usage Signed-off-by: jamshale --- .../issue_credential/v2_0/formats/ld_proof/handler.py | 10 +++++----- .../present_proof/v2_0/formats/dif/handler.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/formats/ld_proof/handler.py b/aries_cloudagent/protocols/issue_credential/v2_0/formats/ld_proof/handler.py index c1949d2486..9640101e5a 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/formats/ld_proof/handler.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/formats/ld_proof/handler.py @@ -132,7 +132,7 @@ async def create_proposal( self, cred_ex_record: V20CredExRecord, proposal_data: Mapping ) -> CredFormatAttachment: """Create linked data proof credential proposal.""" - manager = self.profile.inject(VcLdpManager) + manager = VcLdpManager(self.profile) detail = LDProofVCDetail.deserialize(proposal_data) assert detail.options and isinstance(detail.options, LDProofVCOptions) assert detail.credential and isinstance(detail.credential, VerifiableCredential) @@ -164,7 +164,7 @@ async def create_offer( # but also when we create an offer (manager does some weird stuff) offer_data = cred_proposal_message.attachment(LDProofCredFormatHandler.format) detail = LDProofVCDetail.deserialize(offer_data) - manager = self.profile.inject(VcLdpManager) + manager = VcLdpManager(self.profile) assert detail.options and isinstance(detail.options, LDProofVCOptions) assert detail.credential and isinstance(detail.credential, VerifiableCredential) try: @@ -224,7 +224,7 @@ async def create_request( ) detail = LDProofVCDetail.deserialize(request_data) - manager = self.profile.inject(VcLdpManager) + manager = VcLdpManager(self.profile) assert detail.options and isinstance(detail.options, LDProofVCOptions) assert detail.credential and isinstance(detail.credential, VerifiableCredential) try: @@ -290,7 +290,7 @@ async def issue_credential( LDProofCredFormatHandler.format ) detail = LDProofVCDetail.deserialize(detail_dict) - manager = self.profile.inject(VcLdpManager) + manager = VcLdpManager(self.profile) assert detail.options and isinstance(detail.options, LDProofVCOptions) assert detail.credential and isinstance(detail.credential, VerifiableCredential) try: @@ -381,7 +381,7 @@ async def store_credential( credential = VerifiableCredential.deserialize(cred_dict, unknown=INCLUDE) # Get signature suite, proof purpose and document loader - manager = self.profile.inject(VcLdpManager) + manager = VcLdpManager(self.profile) try: result = await manager.verify_credential(credential) except VcLdpManagerError as err: diff --git a/aries_cloudagent/protocols/present_proof/v2_0/formats/dif/handler.py b/aries_cloudagent/protocols/present_proof/v2_0/formats/dif/handler.py index 207cbca5e0..d7f2b0dd2c 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/formats/dif/handler.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/formats/dif/handler.py @@ -446,7 +446,7 @@ async def verify_pres(self, pres_ex_record: V20PresExRecord) -> V20PresExRecord: pres_request = pres_ex_record.pres_request.attachment( DIFPresFormatHandler.format ) - manager = self.profile.inject(VcLdpManager) + manager = VcLdpManager(self.profile) options = LDProofVCOptions.deserialize(pres_request["options"]) if not options.challenge: From 30543a15676cb68bb756f17aaba0929f6102530f Mon Sep 17 00:00:00 2001 From: jamshale Date: Thu, 15 Feb 2024 23:04:10 +0000 Subject: [PATCH 3/3] Fix unit tests Signed-off-by: jamshale --- .../formats/ld_proof/tests/test_handler.py | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/formats/ld_proof/tests/test_handler.py b/aries_cloudagent/protocols/issue_credential/v2_0/formats/ld_proof/tests/test_handler.py index be1d5c86ec..3472f1f3f5 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/formats/ld_proof/tests/test_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/formats/ld_proof/tests/test_handler.py @@ -1,11 +1,11 @@ from copy import deepcopy -from .......vc.ld_proofs.error import LinkedDataProofException from unittest import IsolatedAsyncioTestCase -from aries_cloudagent.tests import mock from unittest.mock import patch + from marshmallow import ValidationError -from .. import handler as test_module +from aries_cloudagent.tests import mock + from .......core.in_memory import InMemoryProfile from .......messaging.decorators.attach_decorator import AttachDecorator from .......storage.vc_holder.base import VCHolder @@ -15,6 +15,7 @@ SECURITY_CONTEXT_BBS_URL, SECURITY_CONTEXT_ED25519_2020_URL, ) +from .......vc.ld_proofs.error import LinkedDataProofException from .......vc.tests.document_loader import custom_document_loader from .......vc.vc_ld.manager import VcLdpManager from .......vc.vc_ld.models.credential import VerifiableCredential @@ -39,8 +40,9 @@ from ....models.cred_ex_record import V20CredExRecord from ....models.detail.ld_proof import V20CredExRecordLDProof from ...handler import V20CredFormatError -from ..handler import LDProofCredFormatHandler +from .. import handler as test_module from ..handler import LOGGER as LD_PROOF_LOGGER +from ..handler import LDProofCredFormatHandler from ..models.cred_detail import LDProofVCDetail TEST_DID_SOV = "did:sov:LjgpST2rjsoxYegQDRm7EL" @@ -249,7 +251,7 @@ async def test_receive_proposal(self): async def test_create_offer(self): with mock.patch.object( - self.manager, + VcLdpManager, "assert_can_issue_with_id_and_proof_type", mock.CoroutineMock(), ) as mock_can_issue, patch.object( @@ -289,7 +291,7 @@ async def test_create_offer_adds_bbs_context(self): ) with mock.patch.object( - self.manager, + VcLdpManager, "assert_can_issue_with_id_and_proof_type", mock.CoroutineMock(), ), patch.object(test_module, "get_properties_without_context", return_value=[]): @@ -314,7 +316,7 @@ async def test_create_offer_adds_ed25519_2020_context(self): ) with mock.patch.object( - self.manager, + VcLdpManager, "assert_can_issue_with_id_and_proof_type", mock.CoroutineMock(), ), patch.object(test_module, "get_properties_without_context", return_value=[]): @@ -585,7 +587,7 @@ async def test_issue_credential(self): ) with mock.patch.object( - self.manager, + VcLdpManager, "issue", mock.CoroutineMock( return_value=VerifiableCredential.deserialize(LD_PROOF_VC) @@ -843,7 +845,7 @@ async def test_store_credential(self): self.holder.store_credential = mock.CoroutineMock() with mock.patch.object( - self.manager, + VcLdpManager, "verify_credential", mock.CoroutineMock(return_value=DocumentVerificationResult(verified=True)), ) as mock_verify_credential: