From 9af952e6e196b11e133c23d833afc741ba521a4c Mon Sep 17 00:00:00 2001 From: jamshale Date: Tue, 26 Nov 2024 18:32:52 +0000 Subject: [PATCH 1/3] Add test wallet config option Signed-off-by: jamshale --- acapy_agent/askar/profile.py | 8 ++++++-- acapy_agent/askar/profile_anon.py | 8 ++++++-- acapy_agent/config/argparse.py | 27 +++++++++++++++++++++------ acapy_agent/config/wallet.py | 1 + 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/acapy_agent/askar/profile.py b/acapy_agent/askar/profile.py index e80bc569f1..313c026bf3 100644 --- a/acapy_agent/askar/profile.py +++ b/acapy_agent/askar/profile.py @@ -324,7 +324,9 @@ async def provision( ) -> Profile: """Provision a new instance of a profile.""" store_config = AskarStoreConfig(config) - opened = await store_config.open_store(provision=True) + opened = await store_config.open_store( + provision=True, in_memory=config.get("test") + ) return AskarProfile(opened, context) async def open( @@ -332,7 +334,9 @@ async def open( ) -> Profile: """Open an instance of an existing profile.""" store_config = AskarStoreConfig(config) - opened = await store_config.open_store(provision=False) + opened = await store_config.open_store( + provision=False, in_memory=config.get("test") + ) return AskarProfile(opened, context) @classmethod diff --git a/acapy_agent/askar/profile_anon.py b/acapy_agent/askar/profile_anon.py index eea73d876f..9a3cb3e622 100644 --- a/acapy_agent/askar/profile_anon.py +++ b/acapy_agent/askar/profile_anon.py @@ -277,7 +277,9 @@ async def provision( ) -> Profile: """Provision a new instance of a profile.""" store_config = AskarStoreConfig(config) - opened = await store_config.open_store(provision=True) + opened = await store_config.open_store( + provision=True, in_memory=config.get("test") + ) return AskarAnoncredsProfile(opened, context) async def open( @@ -285,7 +287,9 @@ async def open( ) -> Profile: """Open an instance of an existing profile.""" store_config = AskarStoreConfig(config) - opened = await store_config.open_store(provision=False) + opened = await store_config.open_store( + provision=False, in_memory=config.get("test") + ) return AskarAnoncredsProfile(opened, context) @classmethod diff --git a/acapy_agent/config/argparse.py b/acapy_agent/config/argparse.py index ec0d3d95e1..8293fdec94 100644 --- a/acapy_agent/config/argparse.py +++ b/acapy_agent/config/argparse.py @@ -1610,13 +1610,13 @@ def add_arguments(self, parser: ArgumentParser): "--wallet-type", type=str, metavar="", - default="basic", + default="askar", env_var="ACAPY_WALLET_TYPE", help=( "Specifies the type of wallet provider to use. " - "Supported internal storage types are 'basic' (memory), 'askar' " + "Supported internal storage types are 'askar' " "and 'askar-anoncreds'." - "The default (if not specified) is 'basic'." + "The default (if not specified) is 'askar'." ), ) parser.add_argument( @@ -1627,11 +1627,24 @@ def add_arguments(self, parser: ArgumentParser): env_var="ACAPY_WALLET_STORAGE_TYPE", help=( "Specifies the type of wallet backend to use. " - "Supported internal storage types are 'basic' (memory), " - "'default' (sqlite), and 'postgres_storage'. The default, " + "Supported internal storage types are 'default' (sqlite), " + "and 'postgres_storage'. The default, " "if not specified, is 'default'." ), ) + parser.add_argument( + "--wallet-test", + type=str, + metavar="", + default=False, + env_var="ACAPY_WALLET_TEST", + help=( + "Using this option will create a wallet with an in-memory askar wallet " + "storage with a random name. This is useful for testing purposes. " + "The data will not be persisted after the agent is stopped. The default " + "is False. " + ), + ) parser.add_argument( "--wallet-storage-config", type=str, @@ -1714,6 +1727,8 @@ def get_settings(self, args: Namespace) -> dict: settings["wallet.storage_type"] = args.wallet_storage_type if args.wallet_type: settings["wallet.type"] = args.wallet_type + if args.wallet_test: + settings["wallet.test"] = True if args.wallet_key_derivation_method: settings["wallet.key_derivation_method"] = args.wallet_key_derivation_method if args.wallet_rekey_derivation_method: @@ -1731,7 +1746,7 @@ def get_settings(self, args: Namespace) -> dict: # check required settings for persistent wallets if settings["wallet.type"] in ["askar", "askar-anoncreds"]: # requires name, key - if not args.wallet_name or not args.wallet_key: + if not args.wallet_test and (not args.wallet_name or not args.wallet_key): raise ArgsParseError( "Parameters --wallet-name and --wallet-key must be provided " "for persistent wallets" diff --git a/acapy_agent/config/wallet.py b/acapy_agent/config/wallet.py index f857b07847..ce5beb8fc3 100644 --- a/acapy_agent/config/wallet.py +++ b/acapy_agent/config/wallet.py @@ -26,6 +26,7 @@ "storage_config", "storage_creds", "storage_type", + "test", } From d136646ce8a2362db3ace75612d2b8c454aef8cc Mon Sep 17 00:00:00 2001 From: jamshale Date: Tue, 26 Nov 2024 19:37:43 +0000 Subject: [PATCH 2/3] Change wallet test arg to store true / Fix tests Signed-off-by: jamshale --- acapy_agent/commands/tests/test_start.py | 1 + acapy_agent/commands/tests/test_upgrade.py | 1 + acapy_agent/config/argparse.py | 3 +-- acapy_agent/config/tests/test_argparse.py | 6 ++---- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/acapy_agent/commands/tests/test_start.py b/acapy_agent/commands/tests/test_start.py index cac10b8df6..4c9fe32bcb 100644 --- a/acapy_agent/commands/tests/test_start.py +++ b/acapy_agent/commands/tests/test_start.py @@ -55,6 +55,7 @@ def test_exec_start(self): "0.0.0.0", "80", "--no-ledger", + "--wallet-test", ] ) start_app.assert_called_once() diff --git a/acapy_agent/commands/tests/test_upgrade.py b/acapy_agent/commands/tests/test_upgrade.py index 41728221c8..8d24bbc723 100644 --- a/acapy_agent/commands/tests/test_upgrade.py +++ b/acapy_agent/commands/tests/test_upgrade.py @@ -439,6 +439,7 @@ async def test_execute(self): "--from-version", "v0.7.0", "--force-upgrade", + "--wallet-test", ] ) diff --git a/acapy_agent/config/argparse.py b/acapy_agent/config/argparse.py index 8293fdec94..87a67aeaf7 100644 --- a/acapy_agent/config/argparse.py +++ b/acapy_agent/config/argparse.py @@ -1634,8 +1634,7 @@ def add_arguments(self, parser: ArgumentParser): ) parser.add_argument( "--wallet-test", - type=str, - metavar="", + action="store_true", default=False, env_var="ACAPY_WALLET_TEST", help=( diff --git a/acapy_agent/config/tests/test_argparse.py b/acapy_agent/config/tests/test_argparse.py index b80e478032..c3965de392 100644 --- a/acapy_agent/config/tests/test_argparse.py +++ b/acapy_agent/config/tests/test_argparse.py @@ -525,10 +525,7 @@ async def test_wallet_key_derivation_method_value_parsing(self): group.add_arguments(parser) result = parser.parse_args( - [ - "--wallet-key-derivation-method", - key_derivation_method, - ] + ["--wallet-key-derivation-method", key_derivation_method, "--wallet-test"] ) settings = group.get_settings(result) @@ -545,6 +542,7 @@ async def test_wallet_key_value_parsing(self): [ "--wallet-key", key_value, + "--wallet-test", ] ) From 33775dd18d76bec1843fa11c142e7858a8fea305 Mon Sep 17 00:00:00 2001 From: jamshale Date: Mon, 2 Dec 2024 17:47:34 +0000 Subject: [PATCH 3/3] Add unit test with test wallet config Signed-off-by: jamshale --- acapy_agent/askar/tests/test_profile.py | 29 ++++++++++++++----------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/acapy_agent/askar/tests/test_profile.py b/acapy_agent/askar/tests/test_profile.py index 38a0326ded..15bbbba1ef 100644 --- a/acapy_agent/askar/tests/test_profile.py +++ b/acapy_agent/askar/tests/test_profile.py @@ -3,10 +3,11 @@ import pytest -from ...askar.profile import AskarProfile +from ...askar.profile import AskarProfile, AskarProfileManager from ...config.injection_context import InjectionContext from ...ledger.base import BaseLedger from .. import profile as test_module +from ..profile_anon import AskarAnonProfileManager @pytest.fixture @@ -107,15 +108,17 @@ async def test_profile_manager_transaction(): @pytest.mark.asyncio async def test_profile_manager_store(): - profile = "profileId" - - with mock.patch("acapy_agent.askar.profile.AskarProfile") as AskarProfile: - askar_profile = AskarProfile(None, False, profile_id=profile) - askar_profile.profile_id = profile - askar_profile_session = mock.MagicMock() - askar_profile.store.session.return_value = askar_profile_session - - sessionProfile = test_module.AskarProfileSession(askar_profile, False) - - assert sessionProfile._opener == askar_profile_session - askar_profile.store.session.assert_called_once_with(profile) + config = { + "test": True, + } + context = InjectionContext( + settings=config, + ) + await AskarProfileManager().provision( + context=context, + config=config, + ) + await AskarAnonProfileManager().provision( + context=context, + config=config, + )