Skip to content

Commit

Permalink
Remove need for insecure seed option to create did
Browse files Browse the repository at this point in the history
Signed-off-by: jamshale <[email protected]>
  • Loading branch information
jamshale committed Nov 19, 2024
1 parent a681deb commit 1ac4f84
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 36 deletions.
3 changes: 0 additions & 3 deletions acapy_agent/did/indy/indy_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ async def _get_key_type(self, key_type: str) -> KeyType:

def _create_key_pair(self, options: dict, key_type: KeyType) -> Key:
seed = options.get("seed")
if seed and not self.profile.settings.get("wallet.allow_insecure_seed"):
raise WalletError("Insecure seed is not allowed")

if seed:
seed = validate_seed(seed)
return Key.from_secret_bytes(key_type, seed)
Expand Down
41 changes: 8 additions & 33 deletions acapy_agent/did/indy/tests/test_indy_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,27 @@

from aries_askar import AskarError

from acapy_agent.core.in_memory.profile import (
InMemoryProfile,
InMemoryProfileSession,
)
from acapy_agent.askar.profile import AskarProfileSession
from acapy_agent.did.indy.indy_manager import DidIndyManager
from acapy_agent.tests import mock
from acapy_agent.utils.testing import create_test_profile
from acapy_agent.wallet.did_method import DIDMethods
from acapy_agent.wallet.error import WalletError
from acapy_agent.wallet.key_type import KeyTypes


class TestIndyManager(IsolatedAsyncioTestCase):
async def asyncSetUp(self) -> None:
self.profile = InMemoryProfile.test_profile()
self.profile = await create_test_profile()
self.profile.context.injector.bind_instance(
DIDMethods, mock.MagicMock(auto_spec=DIDMethods)
DIDMethods, mock.MagicMock(DIDMethods, auto_spec=True)
)
self.profile.context.injector.bind_instance(KeyTypes, KeyTypes())

def test_init(self):
assert DidIndyManager(self.profile)

@mock.patch.object(InMemoryProfileSession, "handle")
@mock.patch.object(AskarProfileSession, "handle")
async def test_register(self, mock_handle):
mock_handle.insert_key = mock.CoroutineMock()
mock_handle.insert = mock.CoroutineMock()
Expand All @@ -42,30 +40,7 @@ async def test_register(self, mock_handle):
with self.assertRaises(WalletError):
await manager.register({})

@mock.patch.object(InMemoryProfileSession, "handle")
async def test_register_with_seed_without_allow_insecure(self, mock_handle):
mock_handle.insert_key = mock.CoroutineMock()
mock_handle.insert = mock.CoroutineMock()
manager = DidIndyManager(self.profile)
with self.assertRaises(WalletError):
await manager.register({"seed": "000000000000000000000000Trustee1"})

@mock.patch.object(InMemoryProfileSession, "handle")
async def test_register_with_seed_with_allow_insecure(self, mock_handle):
self.profile.context.injector.bind_instance(
DIDMethods, mock.MagicMock(auto_spec=DIDMethods)
)
self.profile.context.injector.bind_instance(KeyTypes, KeyTypes())
self.profile.settings.set_value("wallet.allow_insecure_seed", True)
mock_handle.insert_key = mock.CoroutineMock()
mock_handle.insert = mock.CoroutineMock()
manager = DidIndyManager(self.profile)

result = await manager.register({"seed": "000000000000000000000000Steward1"})
assert result.get("did") == "did:indy:HPMyRCWfgav5HXtYaaJaZK"
assert result.get("verkey")

@mock.patch.object(InMemoryProfileSession, "handle")
@mock.patch.object(AskarProfileSession, "handle")
async def test_register_with_seed_with_key_type(self, mock_handle):
mock_handle.insert_key = mock.CoroutineMock()
mock_handle.insert = mock.CoroutineMock()
Expand All @@ -75,7 +50,7 @@ async def test_register_with_seed_with_key_type(self, mock_handle):
assert result.get("did")
assert result.get("verkey")

@mock.patch.object(InMemoryProfileSession, "handle")
@mock.patch.object(AskarProfileSession, "handle")
async def test_register_with_seed_with_defined_did(self, mock_handle):
mock_handle.insert_key = mock.CoroutineMock()
mock_handle.insert = mock.CoroutineMock()
Expand All @@ -85,7 +60,7 @@ async def test_register_with_seed_with_defined_did(self, mock_handle):
assert result.get("did") == "did:indy:WRfXPg8dantKVubE3HX8pw"
assert result.get("verkey")

@mock.patch.object(InMemoryProfileSession, "handle")
@mock.patch.object(AskarProfileSession, "handle")
async def test_register_with_seed_with_all_options(self, mock_handle):
self.profile.settings.set_value("wallet.allow_insecure_seed", True)
mock_handle.insert_key = mock.CoroutineMock()
Expand Down

0 comments on commit 1ac4f84

Please sign in to comment.