Skip to content

Commit

Permalink
Fix clear revocation logic (#2956)
Browse files Browse the repository at this point in the history
Signed-off-by: jamshale <jamiehalebc@gmail.com>
  • Loading branch information
jamshale committed May 21, 2024
1 parent 0cae003 commit dbbcb73
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 29 deletions.
5 changes: 3 additions & 2 deletions aries_cloudagent/revocation/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,11 @@ async def clear_pending_revocations(
async with self._profile.transaction() as txn:
issuer_rr_recs = await IssuerRevRegRecord.query_by_pending(txn)
for issuer_rr_rec in issuer_rr_recs:
if purge and issuer_rr_rec.revoc_reg_id not in purge:
continue
rrid = issuer_rr_rec.revoc_reg_id
await issuer_rr_rec.clear_pending(txn, (purge or {}).get(rrid))
if issuer_rr_rec.pending_pub:
result[rrid] = issuer_rr_rec.pending_pub
result[rrid] = issuer_rr_rec.pending_pub
notify.append(rrid)
await txn.commit()

Expand Down
75 changes: 48 additions & 27 deletions aries_cloudagent/revocation/tests/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,18 +619,17 @@ async def test_publish_pending_revocations_1_rev_reg_some(self):
mock_issuer_rev_reg_records[1].clear_pending.assert_not_called()

async def test_clear_pending(self):
REV_REG_ID_2 = f"{TEST_DID}:4:{CRED_DEF_ID}:CL_ACCUM:tag2"
mock_issuer_rev_reg_records = [
mock.MagicMock(
test_module.IssuerRevRegRecord(
revoc_reg_id=REV_REG_ID,
tails_local_path=TAILS_LOCAL,
pending_pub=[],
clear_pending=mock.CoroutineMock(),
pending_pub=["1", "2"],
),
mock.MagicMock(
revoc_reg_id=f"{TEST_DID}:4:{CRED_DEF_ID}:CL_ACCUM:tag2",
test_module.IssuerRevRegRecord(
revoc_reg_id=REV_REG_ID_2,
tails_local_path=TAILS_LOCAL,
pending_pub=[],
clear_pending=mock.CoroutineMock(),
pending_pub=["9", "99"],
),
]
with mock.patch.object(
Expand All @@ -639,47 +638,45 @@ async def test_clear_pending(self):
mock.CoroutineMock(return_value=mock_issuer_rev_reg_records),
) as record:
result = await self.manager.clear_pending_revocations()
assert result == {}
assert result[REV_REG_ID] == []
assert result[REV_REG_ID_2] == []

async def test_clear_pending_1_rev_reg_all(self):
REV_REG_ID_2 = f"{TEST_DID}:4:{CRED_DEF_ID}:CL_ACCUM:tag2"

mock_issuer_rev_reg_records = [
mock.MagicMock(
test_module.IssuerRevRegRecord(
revoc_reg_id=REV_REG_ID,
tails_local_path=TAILS_LOCAL,
pending_pub=["1", "2"],
clear_pending=mock.CoroutineMock(),
),
mock.MagicMock(
revoc_reg_id=f"{TEST_DID}:4:{CRED_DEF_ID}:CL_ACCUM:tag2",
test_module.IssuerRevRegRecord(
revoc_reg_id=REV_REG_ID_2,
tails_local_path=TAILS_LOCAL,
pending_pub=["9", "99"],
clear_pending=mock.CoroutineMock(),
),
]
with mock.patch.object(
test_module.IssuerRevRegRecord,
"query_by_pending",
mock.CoroutineMock(return_value=mock_issuer_rev_reg_records),
) as record:
result = await self.manager.clear_pending_revocations({REV_REG_ID: None})
assert result == {
REV_REG_ID: ["1", "2"],
f"{TEST_DID}:4:{CRED_DEF_ID}:CL_ACCUM:tag2": ["9", "99"],
}
result = await self.manager.clear_pending_revocations({REV_REG_ID: []})
assert result[REV_REG_ID] == []
assert result.get(REV_REG_ID_2) is None

async def test_clear_pending_1_rev_reg_some(self):
REV_REG_ID_2 = f"{TEST_DID}:4:{CRED_DEF_ID}:CL_ACCUM:tag2"
mock_issuer_rev_reg_records = [
mock.MagicMock(
test_module.IssuerRevRegRecord(
revoc_reg_id=REV_REG_ID,
tails_local_path=TAILS_LOCAL,
pending_pub=["1", "2"],
clear_pending=mock.CoroutineMock(),
),
mock.MagicMock(
revoc_reg_id=f"{TEST_DID}:4:{CRED_DEF_ID}:CL_ACCUM:tag2",
test_module.IssuerRevRegRecord(
revoc_reg_id=REV_REG_ID_2,
tails_local_path=TAILS_LOCAL,
pending_pub=["99"],
clear_pending=mock.CoroutineMock(),
),
]
with mock.patch.object(
Expand All @@ -688,10 +685,34 @@ async def test_clear_pending_1_rev_reg_some(self):
mock.CoroutineMock(return_value=mock_issuer_rev_reg_records),
) as record:
result = await self.manager.clear_pending_revocations({REV_REG_ID: ["9"]})
assert result == {
REV_REG_ID: ["1", "2"],
f"{TEST_DID}:4:{CRED_DEF_ID}:CL_ACCUM:tag2": ["99"],
}

assert result[REV_REG_ID] == ["1", "2"]
assert result.get(REV_REG_ID_2) is None

async def test_clear_pending_both(self):
REV_REG_ID_2 = f"{TEST_DID}:4:{CRED_DEF_ID}:CL_ACCUM:tag2"
mock_issuer_rev_reg_records = [
test_module.IssuerRevRegRecord(
revoc_reg_id=REV_REG_ID,
tails_local_path=TAILS_LOCAL,
pending_pub=["1", "2"],
),
test_module.IssuerRevRegRecord(
revoc_reg_id=REV_REG_ID_2,
tails_local_path=TAILS_LOCAL,
pending_pub=["99"],
),
]
with mock.patch.object(
test_module.IssuerRevRegRecord,
"query_by_pending",
mock.CoroutineMock(return_value=mock_issuer_rev_reg_records),
) as record:
result = await self.manager.clear_pending_revocations(
{REV_REG_ID: ["1"], REV_REG_ID_2: ["99"]}
)
assert result[REV_REG_ID] == ["2"]
assert result[REV_REG_ID_2] == []

async def test_retrieve_records(self):
session = await self.profile.session()
Expand Down

0 comments on commit dbbcb73

Please sign in to comment.