Skip to content

Commit 31ac61e

Browse files
authored
Merge branch 'main' into troubleshooting
2 parents 115b2e7 + 5ac6086 commit 31ac61e

7 files changed

Lines changed: 90 additions & 11 deletions

File tree

aries_cloudagent/protocols/present_proof/v1_0/handlers/presentation_request_handler.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
8080
"connection_id": connection_id,
8181
},
8282
) # holder initiated via proposal
83+
presentation_exchange_record.presentation_request = indy_proof_request
84+
presentation_exchange_record.presentation_request_dict = (
85+
context.message.serialize()
86+
)
8387
except StorageNotFoundError: # verifier sent this request free of any proposal
8488
presentation_exchange_record = V10PresentationExchange(
8589
connection_id=connection_id,
@@ -94,7 +98,6 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
9498
trace=(context.message._trace is not None),
9599
)
96100

97-
presentation_exchange_record.presentation_request = indy_proof_request
98101
presentation_exchange_record = await presentation_manager.receive_request(
99102
presentation_exchange_record
100103
) # mgr only saves record: on exception, saving state null is hopeless

aries_cloudagent/protocols/present_proof/v1_0/manager.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,9 @@ async def send_presentation_ack(
472472
return
473473

474474
if responder:
475-
presentation_ack_message = PresentationAck()
475+
presentation_ack_message = PresentationAck(
476+
verification_result=presentation_exchange_record.verified
477+
)
476478
presentation_ack_message._thread = {
477479
"thid": presentation_exchange_record.thread_id
478480
}
@@ -515,7 +517,7 @@ async def receive_presentation_ack(
515517
"role": V10PresentationExchange.ROLE_PROVER,
516518
},
517519
)
518-
520+
presentation_exchange_record.verified = message._verification_result
519521
presentation_exchange_record.state = (
520522
V10PresentationExchange.STATE_PRESENTATION_ACKED
521523
)

aries_cloudagent/protocols/present_proof/v1_0/messages/presentation_ack.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Represents an explicit RFC 15 ack message, adopted into present-proof protocol."""
22

3-
from marshmallow import EXCLUDE
3+
from marshmallow import EXCLUDE, fields, validate
44

55
from ....notification.v1_0.messages.ack import V10Ack, V10AckSchema
66

@@ -21,7 +21,7 @@ class Meta:
2121
message_type = PRESENTATION_ACK
2222
schema_class = "PresentationAckSchema"
2323

24-
def __init__(self, status: str = None, **kwargs):
24+
def __init__(self, status: str = None, verification_result: str = None, **kwargs):
2525
"""
2626
Initialize an explicit ack message instance.
2727
@@ -30,6 +30,7 @@ def __init__(self, status: str = None, **kwargs):
3030
3131
"""
3232
super().__init__(status, **kwargs)
33+
self._verification_result = verification_result
3334

3435

3536
class PresentationAckSchema(V10AckSchema):
@@ -40,3 +41,10 @@ class Meta:
4041

4142
model_class = PresentationAck
4243
unknown = EXCLUDE
44+
45+
verification_result = fields.Str(
46+
required=False,
47+
description="Whether presentation is verified: true or false",
48+
example="true",
49+
validate=validate.OneOf(["true", "false"]),
50+
)

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1301,7 +1301,7 @@ async def test_send_presentation_ack_no_responder(self):
13011301
self.profile.context.injector.clear_binding(BaseResponder)
13021302
await self.manager.send_presentation_ack(exchange)
13031303

1304-
async def test_receive_presentation_ack(self):
1304+
async def test_receive_presentation_ack_a(self):
13051305
connection_record = async_mock.MagicMock(connection_id=CONN_ID)
13061306

13071307
exchange_dummy = V10PresentationExchange()
@@ -1322,6 +1322,28 @@ async def test_receive_presentation_ack(self):
13221322
V10PresentationExchange.STATE_PRESENTATION_ACKED
13231323
)
13241324

1325+
async def test_receive_presentation_ack_b(self):
1326+
connection_record = async_mock.MagicMock(connection_id=CONN_ID)
1327+
1328+
exchange_dummy = V10PresentationExchange()
1329+
message = async_mock.MagicMock(_verification_result="true")
1330+
1331+
with async_mock.patch.object(
1332+
V10PresentationExchange, "save", autospec=True
1333+
) as save_ex, async_mock.patch.object(
1334+
V10PresentationExchange, "retrieve_by_tag_filter", autospec=True
1335+
) as retrieve_ex:
1336+
retrieve_ex.return_value = exchange_dummy
1337+
exchange_out = await self.manager.receive_presentation_ack(
1338+
message, connection_record
1339+
)
1340+
save_ex.assert_called_once()
1341+
1342+
assert exchange_out.state == (
1343+
V10PresentationExchange.STATE_PRESENTATION_ACKED
1344+
)
1345+
assert exchange_out.verified == "true"
1346+
13251347
async def test_receive_problem_report(self):
13261348
connection_id = "connection-id"
13271349
stored_exchange = V10PresentationExchange(

aries_cloudagent/protocols/present_proof/v2_0/manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ async def send_pres_ack(self, pres_ex_record: V20PresExRecord):
409409
responder = self._profile.inject_or(BaseResponder)
410410

411411
if responder:
412-
pres_ack_message = V20PresAck()
412+
pres_ack_message = V20PresAck(verification_result=pres_ex_record.verified)
413413
pres_ack_message._thread = {"thid": pres_ex_record.thread_id}
414414
pres_ack_message.assign_trace_decorator(
415415
self._profile.settings, pres_ex_record.trace
@@ -445,7 +445,7 @@ async def receive_pres_ack(self, message: V20PresAck, conn_record: ConnRecord):
445445
"role": V20PresExRecord.ROLE_PROVER,
446446
},
447447
)
448-
448+
pres_ex_record.verified = message._verification_result
449449
pres_ex_record.state = V20PresExRecord.STATE_DONE
450450

451451
await pres_ex_record.save(session, reason="receive v2.0 presentation ack")

aries_cloudagent/protocols/present_proof/v2_0/messages/pres_ack.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Represents an explicit RFC 15 ack message, adopted into present-proof protocol."""
22

3-
from marshmallow import EXCLUDE
3+
from marshmallow import EXCLUDE, fields, validate
44

55
from ....notification.v1_0.messages.ack import V10Ack, V10AckSchema
66

@@ -19,7 +19,7 @@ class Meta:
1919
message_type = PRES_20_ACK
2020
schema_class = "V20PresAckSchema"
2121

22-
def __init__(self, status: str = None, **kwargs):
22+
def __init__(self, status: str = None, verification_result: str = None, **kwargs):
2323
"""
2424
Initialize an explicit ack message instance.
2525
@@ -28,6 +28,7 @@ def __init__(self, status: str = None, **kwargs):
2828
2929
"""
3030
super().__init__(status, **kwargs)
31+
self._verification_result = verification_result
3132

3233

3334
class V20PresAckSchema(V10AckSchema):
@@ -38,3 +39,10 @@ class Meta:
3839

3940
model_class = V20PresAck
4041
unknown = EXCLUDE
42+
43+
verification_result = fields.Str(
44+
required=False,
45+
description="Whether presentation is verified: true or false",
46+
example="true",
47+
validate=validate.OneOf(["true", "false"]),
48+
)

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

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2076,13 +2076,31 @@ async def test_send_pres_ack(self):
20762076
messages = responder.messages
20772077
assert len(messages) == 1
20782078

2079+
px_rec = V20PresExRecord(verified="true")
2080+
2081+
responder = MockResponder()
2082+
self.profile.context.injector.bind_instance(BaseResponder, responder)
2083+
2084+
await self.manager.send_pres_ack(px_rec)
2085+
messages = responder.messages
2086+
assert len(messages) == 1
2087+
2088+
px_rec = V20PresExRecord(verified="false")
2089+
2090+
responder = MockResponder()
2091+
self.profile.context.injector.bind_instance(BaseResponder, responder)
2092+
2093+
await self.manager.send_pres_ack(px_rec)
2094+
messages = responder.messages
2095+
assert len(messages) == 1
2096+
20792097
async def test_send_pres_ack_no_responder(self):
20802098
px_rec = V20PresExRecord()
20812099

20822100
self.profile.context.injector.clear_binding(BaseResponder)
20832101
await self.manager.send_pres_ack(px_rec)
20842102

2085-
async def test_receive_pres_ack(self):
2103+
async def test_receive_pres_ack_a(self):
20862104
conn_record = async_mock.MagicMock(connection_id=CONN_ID)
20872105

20882106
px_rec_dummy = V20PresExRecord()
@@ -2099,6 +2117,24 @@ async def test_receive_pres_ack(self):
20992117

21002118
assert px_rec_out.state == V20PresExRecord.STATE_DONE
21012119

2120+
async def test_receive_pres_ack_b(self):
2121+
conn_record = async_mock.MagicMock(connection_id=CONN_ID)
2122+
2123+
px_rec_dummy = V20PresExRecord()
2124+
message = async_mock.MagicMock(_verification_result="true")
2125+
2126+
with async_mock.patch.object(
2127+
V20PresExRecord, "save", autospec=True
2128+
) as save_ex, async_mock.patch.object(
2129+
V20PresExRecord, "retrieve_by_tag_filter", autospec=True
2130+
) as retrieve_ex:
2131+
retrieve_ex.return_value = px_rec_dummy
2132+
px_rec_out = await self.manager.receive_pres_ack(message, conn_record)
2133+
save_ex.assert_called_once()
2134+
2135+
assert px_rec_out.state == V20PresExRecord.STATE_DONE
2136+
assert px_rec_out.verified == "true"
2137+
21022138
async def test_receive_problem_report(self):
21032139
connection_id = "connection-id"
21042140
stored_exchange = V20PresExRecord(

0 commit comments

Comments
 (0)