Skip to content

Commit

Permalink
Add descriptive error for issuance without RevRegRecord (openwallet-f…
Browse files Browse the repository at this point in the history
…oundation#3109)

* Add descriptive error for issuance without RevRegRecord

Signed-off-by: jamshale <jamiehalebc@gmail.com>

* Ignore line length in error msg

Signed-off-by: jamshale <jamiehalebc@gmail.com>

---------

Signed-off-by: jamshale <jamiehalebc@gmail.com>
  • Loading branch information
jamshale authored Jul 19, 2024
1 parent f3a10ba commit e1dea37
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
15 changes: 8 additions & 7 deletions aries_cloudagent/revocation/indy.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,7 @@ async def get_or_create_active_registry(
triggered and the caller should retry after a delay.
"""
try:
active_rev_reg_rec = await self.get_active_issuer_rev_reg_record(
cred_def_id
)
active_rev_reg_rec = await self.get_active_issuer_rev_reg_record(cred_def_id)
rev_reg = active_rev_reg_rec.get_registry()
await rev_reg.get_or_fetch_local_tails_path()
return active_rev_reg_rec, rev_reg
Expand All @@ -254,11 +252,14 @@ async def get_or_create_active_registry(
# all registries are full, create a new one
if not full_registries:
# Use any registry to get max cred num
any_registry = (
await IssuerRevRegRecord.query_by_cred_def_id(
session, cred_def_id, limit=1
any_registry = await IssuerRevRegRecord.query_by_cred_def_id(
session, cred_def_id, limit=1
)
if not any_registry:
raise RevocationError(
f"No revocation registry record found in issuer wallet for cred def id {cred_def_id}" # noqa: E501
)
)[0]
any_registry = any_registry[0]
await self.init_issuer_registry(
cred_def_id,
max_cred_num=any_registry.max_cred_num,
Expand Down
26 changes: 17 additions & 9 deletions aries_cloudagent/revocation/tests/test_indy.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from ...multitenant.manager import MultitenantManager
from ...storage.error import StorageNotFoundError
from ..error import (
RevocationError,
RevocationNotSupportedError,
RevocationRegistryBadSizeError,
)
Expand Down Expand Up @@ -161,9 +162,7 @@ async def test_decommission_issuer_registries(self):
recs = await self.revoc.list_issuer_registries()
assert len(recs) == 2

init_list = list(
filter(lambda r: r.state == IssuerRevRegRecord.STATE_INIT, recs)
)
init_list = list(filter(lambda r: r.state == IssuerRevRegRecord.STATE_INIT, recs))
assert len(init_list) == 2

# store the ids to verify they are decommissioned
Expand Down Expand Up @@ -204,14 +203,10 @@ async def test_decommission_issuer_registries(self):
filter(lambda r: r.state == IssuerRevRegRecord.STATE_DECOMMISSIONED, recs)
)
assert len(decomm_list) == 2
decomm_rev_reg_ids = [
rec.revoc_reg_id for rec in decomm_list if rec.revoc_reg_id
]
decomm_rev_reg_ids = [rec.revoc_reg_id for rec in decomm_list if rec.revoc_reg_id]

# new ones replacing the decommissioned are in init state
init_list = list(
filter(lambda r: r.state == IssuerRevRegRecord.STATE_INIT, recs)
)
init_list = list(filter(lambda r: r.state == IssuerRevRegRecord.STATE_INIT, recs))
assert len(init_list) == 2

# check that the original rev reg ids are decommissioned
Expand Down Expand Up @@ -295,6 +290,19 @@ async def test_get_or_create_active_registry_has_no_active_and_only_full_registi
assert not result
assert self.revoc.init_issuer_registry.call_args.kwargs["max_cred_num"] == 3

@mock.patch(
"aries_cloudagent.revocation.indy.IndyRevocation.get_active_issuer_rev_reg_record",
mock.CoroutineMock(side_effect=StorageNotFoundError("No such record")),
)
@mock.patch(
"aries_cloudagent.revocation.indy.IndyRevocation.init_issuer_registry",
mock.CoroutineMock(return_value=None),
)
@mock.patch.object(IssuerRevRegRecord, "query_by_cred_def_id", side_effect=[[], []])
async def test_get_or_create_active_registry_has_no_active_or_any_registry(self, *_):
with self.assertRaises(RevocationError):
await self.revoc.get_or_create_active_registry("cred_def_id")

@mock.patch(
"aries_cloudagent.revocation.indy.IndyRevocation.get_active_issuer_rev_reg_record",
mock.CoroutineMock(side_effect=StorageNotFoundError("No such record")),
Expand Down

0 comments on commit e1dea37

Please sign in to comment.