From c9d0bef5cce162f10bbd4e4b8cd79371f5f4245c Mon Sep 17 00:00:00 2001 From: Ethan Sung Date: Thu, 25 Nov 2021 11:34:16 +0900 Subject: [PATCH 1/5] Fix error when removing wallet on askar-profile Signed-off-by: Ethan Sung --- aries_cloudagent/multitenant/base.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/aries_cloudagent/multitenant/base.py b/aries_cloudagent/multitenant/base.py index 51b217953d..08c6d4e28e 100644 --- a/aries_cloudagent/multitenant/base.py +++ b/aries_cloudagent/multitenant/base.py @@ -270,7 +270,8 @@ async def remove_wallet(self, wallet_id: str, wallet_key: str = None): {"wallet.key": wallet_key}, ) - del self._instances[wallet_id] + if profile.settings.get("multitenant.wallet_type") != "askar-profile": + del self._instances[wallet_id] await profile.remove() # Remove all routing records associated with wallet From 6a1b1d803bb1da35b393dbe691cc19c1c4695fcd Mon Sep 17 00:00:00 2001 From: Ethan Sung Date: Mon, 29 Nov 2021 14:42:10 +0900 Subject: [PATCH 2/5] Add remove_wallet_profile Signed-off-by: Ethan Sung --- .../multitenant/askar_profile_manager.py | 9 +++++++++ aries_cloudagent/multitenant/base.py | 13 ++++++++++--- aries_cloudagent/multitenant/manager.py | 11 +++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/aries_cloudagent/multitenant/askar_profile_manager.py b/aries_cloudagent/multitenant/askar_profile_manager.py index 96fe137780..c692b04ea8 100644 --- a/aries_cloudagent/multitenant/askar_profile_manager.py +++ b/aries_cloudagent/multitenant/askar_profile_manager.py @@ -83,3 +83,12 @@ async def get_wallet_profile( ).extend(extra_settings) return AskarProfile(multitenant_wallet.opened, profile_context) + + async def remove_wallet_profile(self, profile: Profile): + """Remove the wallet profile instance. + + Args: + profile: The wallet profile instance + + """ + await profile.remove() diff --git a/aries_cloudagent/multitenant/base.py b/aries_cloudagent/multitenant/base.py index 08c6d4e28e..5bdd9a9787 100644 --- a/aries_cloudagent/multitenant/base.py +++ b/aries_cloudagent/multitenant/base.py @@ -270,9 +270,7 @@ async def remove_wallet(self, wallet_id: str, wallet_key: str = None): {"wallet.key": wallet_key}, ) - if profile.settings.get("multitenant.wallet_type") != "askar-profile": - del self._instances[wallet_id] - await profile.remove() + await self.remove_wallet_profile(profile) # Remove all routing records associated with wallet async with self._profile.session() as session: @@ -283,6 +281,15 @@ async def remove_wallet(self, wallet_id: str, wallet_key: str = None): await wallet.delete_record(session) + @abstractmethod + async def remove_wallet_profile(self, profile: Profile): + """Remove the wallet profile instance. + + Args: + profile: The wallet profile instance + + """ + async def add_key( self, wallet_id: str, recipient_key: str, *, skip_if_exists: bool = False ): diff --git a/aries_cloudagent/multitenant/manager.py b/aries_cloudagent/multitenant/manager.py index f52eda7713..5bbbcc6632 100644 --- a/aries_cloudagent/multitenant/manager.py +++ b/aries_cloudagent/multitenant/manager.py @@ -71,3 +71,14 @@ async def get_wallet_profile( self._instances[wallet_id] = profile return self._instances[wallet_id] + + async def remove_wallet_profile(self, profile: Profile): + """Remove the wallet profile instance. + + Args: + profile: The wallet profile instance + + """ + wallet_id = profile.settings.get("wallet.id") + del self._instances[wallet_id] + await profile.remove() From cfd274c7e34a23d523a2525d989d5dc8091644bf Mon Sep 17 00:00:00 2001 From: Ethan Sung Date: Mon, 29 Nov 2021 15:37:32 +0900 Subject: [PATCH 3/5] Update unit test on multitenant base Signed-off-by: Ethan Sung --- aries_cloudagent/multitenant/tests/test_base.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/aries_cloudagent/multitenant/tests/test_base.py b/aries_cloudagent/multitenant/tests/test_base.py index d984c0e4d5..8e29335f77 100644 --- a/aries_cloudagent/multitenant/tests/test_base.py +++ b/aries_cloudagent/multitenant/tests/test_base.py @@ -307,8 +307,8 @@ async def test_remove_wallet_removes_profile_wallet_storage_records(self): ) as retrieve_by_id, async_mock.patch.object( BaseMultitenantManager, "get_wallet_profile" ) as get_wallet_profile, async_mock.patch.object( - InMemoryProfile, "remove" - ) as remove_profile, async_mock.patch.object( + BaseMultitenantManager, "remove_wallet_profile" + ) as remove_wallet_profile, async_mock.patch.object( WalletRecord, "delete_record" ) as wallet_delete_record, async_mock.patch.object( InMemoryStorage, "delete_all_records" @@ -320,17 +320,17 @@ async def test_remove_wallet_removes_profile_wallet_storage_records(self): ) wallet_profile = InMemoryProfile.test_profile() - self.manager._instances["test"] = wallet_profile retrieve_by_id.return_value = wallet_record get_wallet_profile.return_value = wallet_profile await self.manager.remove_wallet("test") - assert "test" not in self.manager._instances get_wallet_profile.assert_called_once_with( self.profile.context, wallet_record, {"wallet.key": "test_key"} ) - remove_profile.assert_called_once_with() + remove_wallet_profile.assert_called_once_with( + wallet_profile + ) assert wallet_delete_record.call_count == 1 delete_all_records.assert_called_once_with( RouteRecord.RECORD_TYPE, {"wallet_id": "test"} From e189caaba1588724d3a224dd081049dc48a923c7 Mon Sep 17 00:00:00 2001 From: Ethan Sung Date: Mon, 29 Nov 2021 15:56:36 +0900 Subject: [PATCH 4/5] Add unit test for remove_wallet_profile Signed-off-by: Ethan Sung --- .../tests/test_askar_profile_manager.py | 11 +++++++++++ .../multitenant/tests/test_manager.py | 15 +++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/aries_cloudagent/multitenant/tests/test_askar_profile_manager.py b/aries_cloudagent/multitenant/tests/test_askar_profile_manager.py index 5483ac2c7d..c007d93c8e 100644 --- a/aries_cloudagent/multitenant/tests/test_askar_profile_manager.py +++ b/aries_cloudagent/multitenant/tests/test_askar_profile_manager.py @@ -170,3 +170,14 @@ def side_effect(context, provision): wallet_config.call_args[0][0].settings.get("wallet.name") == multitenant_sub_wallet_name ) + + async def test_remove_wallet_profile(self): + test_profile = InMemoryProfile.test_profile() + + with async_mock.patch.object( + InMemoryProfile, "remove" + ) as profile_remove: + await self.manager.remove_wallet_profile( + test_profile + ) + profile_remove.assert_called_once_with() diff --git a/aries_cloudagent/multitenant/tests/test_manager.py b/aries_cloudagent/multitenant/tests/test_manager.py index 60ef8c624d..aac9fe5d27 100644 --- a/aries_cloudagent/multitenant/tests/test_manager.py +++ b/aries_cloudagent/multitenant/tests/test_manager.py @@ -173,3 +173,18 @@ def side_effect(context, provision): assert profile.settings.get("mediation.invite") == "http://invite.com" assert profile.settings.get("mediation.default_id") == "24a96ef5" assert profile.settings.get("mediation.clear") == True + + async def test_remove_wallet_profile(self): + test_profile = InMemoryProfile.test_profile( + settings={"wallet.id": "test"}, + ) + self.manager._instances["test"] = test_profile + + with async_mock.patch.object( + InMemoryProfile, "remove" + ) as profile_remove: + await self.manager.remove_wallet_profile( + test_profile + ) + assert "test" not in self.manager._instances + profile_remove.assert_called_once_with() From 792de161b98a82fd4c2f48e09687df972aee91f9 Mon Sep 17 00:00:00 2001 From: Ethan Sung Date: Mon, 29 Nov 2021 16:03:34 +0900 Subject: [PATCH 5/5] Fix formatting Signed-off-by: Ethan Sung --- .../multitenant/tests/test_askar_profile_manager.py | 8 ++------ aries_cloudagent/multitenant/tests/test_base.py | 4 +--- aries_cloudagent/multitenant/tests/test_manager.py | 8 ++------ 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/aries_cloudagent/multitenant/tests/test_askar_profile_manager.py b/aries_cloudagent/multitenant/tests/test_askar_profile_manager.py index c007d93c8e..6bad949cb4 100644 --- a/aries_cloudagent/multitenant/tests/test_askar_profile_manager.py +++ b/aries_cloudagent/multitenant/tests/test_askar_profile_manager.py @@ -174,10 +174,6 @@ def side_effect(context, provision): async def test_remove_wallet_profile(self): test_profile = InMemoryProfile.test_profile() - with async_mock.patch.object( - InMemoryProfile, "remove" - ) as profile_remove: - await self.manager.remove_wallet_profile( - test_profile - ) + with async_mock.patch.object(InMemoryProfile, "remove") as profile_remove: + await self.manager.remove_wallet_profile(test_profile) profile_remove.assert_called_once_with() diff --git a/aries_cloudagent/multitenant/tests/test_base.py b/aries_cloudagent/multitenant/tests/test_base.py index 8e29335f77..4f6cb8dabf 100644 --- a/aries_cloudagent/multitenant/tests/test_base.py +++ b/aries_cloudagent/multitenant/tests/test_base.py @@ -328,9 +328,7 @@ async def test_remove_wallet_removes_profile_wallet_storage_records(self): get_wallet_profile.assert_called_once_with( self.profile.context, wallet_record, {"wallet.key": "test_key"} ) - remove_wallet_profile.assert_called_once_with( - wallet_profile - ) + remove_wallet_profile.assert_called_once_with(wallet_profile) assert wallet_delete_record.call_count == 1 delete_all_records.assert_called_once_with( RouteRecord.RECORD_TYPE, {"wallet_id": "test"} diff --git a/aries_cloudagent/multitenant/tests/test_manager.py b/aries_cloudagent/multitenant/tests/test_manager.py index aac9fe5d27..7e01959f95 100644 --- a/aries_cloudagent/multitenant/tests/test_manager.py +++ b/aries_cloudagent/multitenant/tests/test_manager.py @@ -180,11 +180,7 @@ async def test_remove_wallet_profile(self): ) self.manager._instances["test"] = test_profile - with async_mock.patch.object( - InMemoryProfile, "remove" - ) as profile_remove: - await self.manager.remove_wallet_profile( - test_profile - ) + with async_mock.patch.object(InMemoryProfile, "remove") as profile_remove: + await self.manager.remove_wallet_profile(test_profile) assert "test" not in self.manager._instances profile_remove.assert_called_once_with()