Skip to content

Commit

Permalink
fix: negative test case for default verkey strat
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Bluhm <[email protected]>
  • Loading branch information
dbluhm committed Nov 12, 2024
1 parent 8178eb2 commit f3e2706
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
13 changes: 9 additions & 4 deletions acapy_agent/wallet/default_verification_key_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async def get_verification_method_id_for_did(
*,
proof_type: Optional[str] = None,
proof_purpose: Optional[ProofPurposeStr] = None,
) -> Optional[str]:
) -> str:
"""Given a DID, returns the verification key ID in use.
Returns None if no strategy is specified for this DID.
Expand All @@ -54,7 +54,7 @@ async def get_verification_method_id_for_did(
:params proof_purpose: the verkey relationship (assertionMethod, keyAgreement, ..)
:returns Optional[str]: the current verkey ID
"""
pass
...


class DefaultVerificationKeyStrategy(BaseVerificationKeyStrategy):
Expand All @@ -77,7 +77,7 @@ async def get_verification_method_id_for_did(
*,
proof_type: Optional[str] = None,
proof_purpose: Optional[ProofPurposeStr] = None,
) -> Optional[str]:
) -> str:
"""Given a did:key or did:sov, returns the verification key ID in use.
Returns None if no strategy is specified for this DID.
Expand Down Expand Up @@ -113,7 +113,12 @@ async def get_verification_method_id_for_did(
for method in methods_or_refs
]

method_types = self.key_types_mapping[proof_type]
method_types = self.key_types_mapping.get(proof_type)
if not method_types:
raise VerificationKeyStrategyError(
f"proof type {proof_type} is not supported"
)

# Filter methods by type expected for proof_type
methods = [vm for vm in methods if vm.type in method_types]
if not methods:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from unittest import IsolatedAsyncioTestCase
import pytest

from acapy_agent.resolver.did_resolver import DIDResolver

from ...did.did_key import DIDKey
from ...utils.testing import create_test_profile
Expand All @@ -13,6 +16,8 @@
class TestDefaultVerificationKeyStrategy(IsolatedAsyncioTestCase):
async def asyncSetUp(self) -> None:
self.profile = await create_test_profile()
resolver = DIDResolver()
self.profile.context.injector.bind_instance(DIDResolver, resolver)

async def test_with_did_sov(self):
strategy = DefaultVerificationKeyStrategy()
Expand All @@ -30,9 +35,7 @@ async def test_with_did_key(self):

async def test_unsupported_did_method(self):
strategy = DefaultVerificationKeyStrategy()
assert (
with pytest.raises(Exception):
await strategy.get_verification_method_id_for_did(
"did:test:test", self.profile
)
is None
)

0 comments on commit f3e2706

Please sign in to comment.