diff --git a/aries_cloudagent/multitenant/askar_profile_manager.py b/aries_cloudagent/multitenant/askar_profile_manager.py index 93f2456609..22a118cf24 100644 --- a/aries_cloudagent/multitenant/askar_profile_manager.py +++ b/aries_cloudagent/multitenant/askar_profile_manager.py @@ -2,6 +2,7 @@ from typing import Iterable, Optional, cast +from ..askar.profile_anon import AskarAnoncredsProfile from ..askar.profile import AskarProfile from ..config.injection_context import InjectionContext from ..config.wallet import wallet_config @@ -104,6 +105,14 @@ async def get_wallet_profile( assert self._multitenant_profile.opened + # return anoncreds profile if explicitly set as wallet type + if profile_context.settings.get("wallet.type") == "askar-anoncreds": + return AskarAnoncredsProfile( + self._multitenant_profile.opened, + profile_context, + profile_id=wallet_record.wallet_id, + ) + return AskarProfile( self._multitenant_profile.opened, profile_context, diff --git a/aries_cloudagent/multitenant/tests/test_askar_profile_manager.py b/aries_cloudagent/multitenant/tests/test_askar_profile_manager.py index 2070f835ab..30892c1b2b 100644 --- a/aries_cloudagent/multitenant/tests/test_askar_profile_manager.py +++ b/aries_cloudagent/multitenant/tests/test_askar_profile_manager.py @@ -99,6 +99,42 @@ def side_effect(context, provision): == wallet_record.wallet_id ) + async def test_get_anoncreds_wallet_profile_should_open_store_and_return_anoncreds_profile( + self, + ): + askar_profile_mock_name = "AskarProfile" + wallet_record = WalletRecord( + wallet_id="test", + settings={ + "wallet.recreate": True, + "wallet.seed": "test_seed", + "wallet.name": "test_name", + "wallet.type": "askar-anoncreds", + "wallet.rekey": "test_rekey", + }, + ) + + with mock.patch( + "aries_cloudagent.multitenant.askar_profile_manager.wallet_config" + ) as wallet_config, mock.patch( + "aries_cloudagent.multitenant.askar_profile_manager.AskarAnoncredsProfile", + ) as AskarAnoncredsProfile: + sub_wallet_profile_context = InjectionContext() + sub_wallet_profile = AskarAnoncredsProfile(None, None) + sub_wallet_profile.context.copy.return_value = sub_wallet_profile_context + + def side_effect(context, provision): + sub_wallet_profile.name = askar_profile_mock_name + return sub_wallet_profile, None + + wallet_config.side_effect = side_effect + + await self.manager.get_wallet_profile(self.profile.context, wallet_record) + + AskarAnoncredsProfile.assert_called_with( + sub_wallet_profile.opened, sub_wallet_profile_context, profile_id="test" + ) + async def test_get_wallet_profile_should_create_profile(self): wallet_record = WalletRecord(wallet_id="test", settings={}) create_profile_stub = asyncio.Future()