Skip to content

Commit 08dd1cf

Browse files
authored
Merge branch 'main' into patch-1
2 parents d428e0b + cdea418 commit 08dd1cf

2 files changed

Lines changed: 170 additions & 3 deletions

File tree

aries_cloudagent/protocols/present_proof/v2_0/formats/indy/handler.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,10 @@ def _check_proof_vs_proposal():
199199
f"attr::{name}::value": proof_value,
200200
}
201201

202-
if not any(r.items() <= criteria.items() for r in req_restrictions):
202+
if (
203+
not any(r.items() <= criteria.items() for r in req_restrictions)
204+
and len(req_restrictions) != 0
205+
):
203206
raise V20PresFormatHandlerError(
204207
f"Presented attribute {reft} does not satisfy proof request "
205208
f"restrictions {req_restrictions}"
@@ -234,7 +237,10 @@ def _check_proof_vs_proposal():
234237
},
235238
}
236239

237-
if not any(r.items() <= criteria.items() for r in req_restrictions):
240+
if (
241+
not any(r.items() <= criteria.items() for r in req_restrictions)
242+
and len(req_restrictions) != 0
243+
):
238244
raise V20PresFormatHandlerError(
239245
f"Presented attr group {reft} does not satisfy proof request "
240246
f"restrictions {req_restrictions}"
@@ -287,7 +293,10 @@ def _check_proof_vs_proposal():
287293
"issuer_did": cred_def_id.split(":")[-5],
288294
}
289295

290-
if not any(r.items() <= criteria.items() for r in req_restrictions):
296+
if (
297+
not any(r.items() <= criteria.items() for r in req_restrictions)
298+
and len(req_restrictions) != 0
299+
):
291300
raise V20PresFormatHandlerError(
292301
f"Presented predicate {reft} does not satisfy proof request "
293302
f"restrictions {req_restrictions}"

aries_cloudagent/protocols/present_proof/v2_0/tests/test_manager.py

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,6 +1400,164 @@ async def test_receive_pres_receive_pred_value_mismatch_punt_to_indy(self):
14001400
save_ex.assert_called_once()
14011401
assert px_rec_out.state == (V20PresExRecord.STATE_PRESENTATION_RECEIVED)
14021402

1403+
async def test_receive_pres_indy_no_predicate_restrictions(self):
1404+
connection_record = async_mock.MagicMock(connection_id=CONN_ID)
1405+
indy_proof_req = {
1406+
"name": PROOF_REQ_NAME,
1407+
"version": PROOF_REQ_VERSION,
1408+
"nonce": PROOF_REQ_NONCE,
1409+
"requested_attributes": {
1410+
"0_player_uuid": {
1411+
"name": "player",
1412+
"restrictions": [{"cred_def_id": CD_ID}],
1413+
"non_revoked": {"from": NOW, "to": NOW},
1414+
},
1415+
"0_screencapture_uuid": {
1416+
"name": "screenCapture",
1417+
"restrictions": [{"cred_def_id": CD_ID}],
1418+
"non_revoked": {"from": NOW, "to": NOW},
1419+
},
1420+
},
1421+
"requested_predicates": {
1422+
"0_highscore_GE_uuid": {
1423+
"name": "highScore",
1424+
"p_type": ">=",
1425+
"p_value": 1000000,
1426+
"restrictions": [],
1427+
"non_revoked": {"from": NOW, "to": NOW},
1428+
}
1429+
},
1430+
}
1431+
pres_request = V20PresRequest(
1432+
formats=[
1433+
V20PresFormat(
1434+
attach_id="indy",
1435+
format_=ATTACHMENT_FORMAT[PRES_20_REQUEST][
1436+
V20PresFormat.Format.INDY.api
1437+
],
1438+
)
1439+
],
1440+
request_presentations_attach=[
1441+
AttachDecorator.data_base64(indy_proof_req, ident="indy")
1442+
],
1443+
)
1444+
pres = V20Pres(
1445+
formats=[
1446+
V20PresFormat(
1447+
attach_id="indy",
1448+
format_=ATTACHMENT_FORMAT[PRES_20][V20PresFormat.Format.INDY.api],
1449+
)
1450+
],
1451+
presentations_attach=[
1452+
AttachDecorator.data_base64(INDY_PROOF, ident="indy")
1453+
],
1454+
)
1455+
pres.assign_thread_id("thread-id")
1456+
1457+
px_rec_dummy = V20PresExRecord(
1458+
pres_request=pres_request.serialize(),
1459+
)
1460+
1461+
# cover by_format property
1462+
by_format = px_rec_dummy.by_format
1463+
1464+
assert by_format.get("pres_request").get("indy") == indy_proof_req
1465+
1466+
with async_mock.patch.object(
1467+
V20PresExRecord, "save", autospec=True
1468+
) as save_ex, async_mock.patch.object(
1469+
V20PresExRecord, "retrieve_by_tag_filter", autospec=True
1470+
) as retrieve_ex, async_mock.patch.object(
1471+
self.profile,
1472+
"session",
1473+
async_mock.MagicMock(return_value=self.profile.session()),
1474+
) as session:
1475+
retrieve_ex.side_effect = [px_rec_dummy]
1476+
px_rec_out = await self.manager.receive_pres(pres, connection_record, None)
1477+
retrieve_ex.assert_called_once_with(
1478+
session.return_value,
1479+
{"thread_id": "thread-id"},
1480+
{"role": V20PresExRecord.ROLE_VERIFIER, "connection_id": CONN_ID},
1481+
)
1482+
save_ex.assert_called_once()
1483+
assert px_rec_out.state == (V20PresExRecord.STATE_PRESENTATION_RECEIVED)
1484+
1485+
async def test_receive_pres_indy_no_attr_restrictions(self):
1486+
connection_record = async_mock.MagicMock(connection_id=CONN_ID)
1487+
indy_proof_req = {
1488+
"name": PROOF_REQ_NAME,
1489+
"version": PROOF_REQ_VERSION,
1490+
"nonce": PROOF_REQ_NONCE,
1491+
"requested_attributes": {
1492+
"0_player_uuid": {
1493+
"name": "player",
1494+
"restrictions": [],
1495+
"non_revoked": {"from": NOW, "to": NOW},
1496+
}
1497+
},
1498+
"requested_predicates": {},
1499+
}
1500+
proof = deepcopy(INDY_PROOF)
1501+
proof["requested_proof"]["revealed_attrs"] = {
1502+
"0_player_uuid": {
1503+
"sub_proof_index": 0,
1504+
"raw": "Richie Knucklez",
1505+
"encoded": "516439982",
1506+
}
1507+
}
1508+
proof["requested_proof"]["predicates"] = {}
1509+
pres_request = V20PresRequest(
1510+
formats=[
1511+
V20PresFormat(
1512+
attach_id="indy",
1513+
format_=ATTACHMENT_FORMAT[PRES_20_REQUEST][
1514+
V20PresFormat.Format.INDY.api
1515+
],
1516+
)
1517+
],
1518+
request_presentations_attach=[
1519+
AttachDecorator.data_base64(indy_proof_req, ident="indy")
1520+
],
1521+
)
1522+
pres = V20Pres(
1523+
formats=[
1524+
V20PresFormat(
1525+
attach_id="indy",
1526+
format_=ATTACHMENT_FORMAT[PRES_20][V20PresFormat.Format.INDY.api],
1527+
)
1528+
],
1529+
presentations_attach=[AttachDecorator.data_base64(proof, ident="indy")],
1530+
)
1531+
pres.assign_thread_id("thread-id")
1532+
1533+
px_rec_dummy = V20PresExRecord(
1534+
pres_request=pres_request.serialize(),
1535+
)
1536+
1537+
# cover by_format property
1538+
by_format = px_rec_dummy.by_format
1539+
1540+
assert by_format.get("pres_request").get("indy") == indy_proof_req
1541+
1542+
with async_mock.patch.object(
1543+
V20PresExRecord, "save", autospec=True
1544+
) as save_ex, async_mock.patch.object(
1545+
V20PresExRecord, "retrieve_by_tag_filter", autospec=True
1546+
) as retrieve_ex, async_mock.patch.object(
1547+
self.profile,
1548+
"session",
1549+
async_mock.MagicMock(return_value=self.profile.session()),
1550+
) as session:
1551+
retrieve_ex.side_effect = [px_rec_dummy]
1552+
px_rec_out = await self.manager.receive_pres(pres, connection_record, None)
1553+
retrieve_ex.assert_called_once_with(
1554+
session.return_value,
1555+
{"thread_id": "thread-id"},
1556+
{"role": V20PresExRecord.ROLE_VERIFIER, "connection_id": CONN_ID},
1557+
)
1558+
save_ex.assert_called_once()
1559+
assert px_rec_out.state == (V20PresExRecord.STATE_PRESENTATION_RECEIVED)
1560+
14031561
async def test_receive_pres_bait_and_switch_attr_name(self):
14041562
connection_record = async_mock.MagicMock(connection_id=CONN_ID)
14051563
indy_proof_req = deepcopy(INDY_PROOF_REQ_NAME)

0 commit comments

Comments
 (0)