Skip to content

Commit f3e2706

Browse files
committed
fix: negative test case for default verkey strat
Signed-off-by: Daniel Bluhm <[email protected]>
1 parent 8178eb2 commit f3e2706

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

acapy_agent/wallet/default_verification_key_strategy.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ async def get_verification_method_id_for_did(
4343
*,
4444
proof_type: Optional[str] = None,
4545
proof_purpose: Optional[ProofPurposeStr] = None,
46-
) -> Optional[str]:
46+
) -> str:
4747
"""Given a DID, returns the verification key ID in use.
4848
4949
Returns None if no strategy is specified for this DID.
@@ -54,7 +54,7 @@ async def get_verification_method_id_for_did(
5454
:params proof_purpose: the verkey relationship (assertionMethod, keyAgreement, ..)
5555
:returns Optional[str]: the current verkey ID
5656
"""
57-
pass
57+
...
5858

5959

6060
class DefaultVerificationKeyStrategy(BaseVerificationKeyStrategy):
@@ -77,7 +77,7 @@ async def get_verification_method_id_for_did(
7777
*,
7878
proof_type: Optional[str] = None,
7979
proof_purpose: Optional[ProofPurposeStr] = None,
80-
) -> Optional[str]:
80+
) -> str:
8181
"""Given a did:key or did:sov, returns the verification key ID in use.
8282
8383
Returns None if no strategy is specified for this DID.
@@ -113,7 +113,12 @@ async def get_verification_method_id_for_did(
113113
for method in methods_or_refs
114114
]
115115

116-
method_types = self.key_types_mapping[proof_type]
116+
method_types = self.key_types_mapping.get(proof_type)
117+
if not method_types:
118+
raise VerificationKeyStrategyError(
119+
f"proof type {proof_type} is not supported"
120+
)
121+
117122
# Filter methods by type expected for proof_type
118123
methods = [vm for vm in methods if vm.type in method_types]
119124
if not methods:

acapy_agent/wallet/tests/test_default_verification_key_strategy.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
from unittest import IsolatedAsyncioTestCase
2+
import pytest
3+
4+
from acapy_agent.resolver.did_resolver import DIDResolver
25

36
from ...did.did_key import DIDKey
47
from ...utils.testing import create_test_profile
@@ -13,6 +16,8 @@
1316
class TestDefaultVerificationKeyStrategy(IsolatedAsyncioTestCase):
1417
async def asyncSetUp(self) -> None:
1518
self.profile = await create_test_profile()
19+
resolver = DIDResolver()
20+
self.profile.context.injector.bind_instance(DIDResolver, resolver)
1621

1722
async def test_with_did_sov(self):
1823
strategy = DefaultVerificationKeyStrategy()
@@ -30,9 +35,7 @@ async def test_with_did_key(self):
3035

3136
async def test_unsupported_did_method(self):
3237
strategy = DefaultVerificationKeyStrategy()
33-
assert (
38+
with pytest.raises(Exception):
3439
await strategy.get_verification_method_id_for_did(
3540
"did:test:test", self.profile
3641
)
37-
is None
38-
)

0 commit comments

Comments
 (0)