Skip to content

Commit

Permalink
Merge pull request #1757 from shaangill025/issue#1754
Browse files Browse the repository at this point in the history
Prover - verification outcome from presentation ack message
  • Loading branch information
swcurran authored Jun 21, 2022
2 parents 5d1988f + 9f64c74 commit 01981b6
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 10 deletions.
6 changes: 4 additions & 2 deletions aries_cloudagent/protocols/present_proof/v1_0/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,9 @@ async def send_presentation_ack(
return

if responder:
presentation_ack_message = PresentationAck()
presentation_ack_message = PresentationAck(
verification_result=presentation_exchange_record.verified
)
presentation_ack_message._thread = {
"thid": presentation_exchange_record.thread_id
}
Expand Down Expand Up @@ -515,7 +517,7 @@ async def receive_presentation_ack(
"role": V10PresentationExchange.ROLE_PROVER,
},
)

presentation_exchange_record.verified = message._verification_result
presentation_exchange_record.state = (
V10PresentationExchange.STATE_PRESENTATION_ACKED
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Represents an explicit RFC 15 ack message, adopted into present-proof protocol."""

from marshmallow import EXCLUDE
from marshmallow import EXCLUDE, fields, validate

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

Expand All @@ -21,7 +21,7 @@ class Meta:
message_type = PRESENTATION_ACK
schema_class = "PresentationAckSchema"

def __init__(self, status: str = None, **kwargs):
def __init__(self, status: str = None, verification_result: str = None, **kwargs):
"""
Initialize an explicit ack message instance.
Expand All @@ -30,6 +30,7 @@ def __init__(self, status: str = None, **kwargs):
"""
super().__init__(status, **kwargs)
self._verification_result = verification_result


class PresentationAckSchema(V10AckSchema):
Expand All @@ -40,3 +41,10 @@ class Meta:

model_class = PresentationAck
unknown = EXCLUDE

verification_result = fields.Str(
required=False,
description="Whether presentation is verified: true or false",
example="true",
validate=validate.OneOf(["true", "false"]),
)
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,7 @@ async def test_send_presentation_ack_no_responder(self):
self.profile.context.injector.clear_binding(BaseResponder)
await self.manager.send_presentation_ack(exchange)

async def test_receive_presentation_ack(self):
async def test_receive_presentation_ack_a(self):
connection_record = async_mock.MagicMock(connection_id=CONN_ID)

exchange_dummy = V10PresentationExchange()
Expand All @@ -1322,6 +1322,28 @@ async def test_receive_presentation_ack(self):
V10PresentationExchange.STATE_PRESENTATION_ACKED
)

async def test_receive_presentation_ack_b(self):
connection_record = async_mock.MagicMock(connection_id=CONN_ID)

exchange_dummy = V10PresentationExchange()
message = async_mock.MagicMock(_verification_result="true")

with async_mock.patch.object(
V10PresentationExchange, "save", autospec=True
) as save_ex, async_mock.patch.object(
V10PresentationExchange, "retrieve_by_tag_filter", autospec=True
) as retrieve_ex:
retrieve_ex.return_value = exchange_dummy
exchange_out = await self.manager.receive_presentation_ack(
message, connection_record
)
save_ex.assert_called_once()

assert exchange_out.state == (
V10PresentationExchange.STATE_PRESENTATION_ACKED
)
assert exchange_out.verified == "true"

async def test_receive_problem_report(self):
connection_id = "connection-id"
stored_exchange = V10PresentationExchange(
Expand Down
4 changes: 2 additions & 2 deletions aries_cloudagent/protocols/present_proof/v2_0/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ async def send_pres_ack(self, pres_ex_record: V20PresExRecord):
responder = self._profile.inject_or(BaseResponder)

if responder:
pres_ack_message = V20PresAck()
pres_ack_message = V20PresAck(verification_result=pres_ex_record.verified)
pres_ack_message._thread = {"thid": pres_ex_record.thread_id}
pres_ack_message.assign_trace_decorator(
self._profile.settings, pres_ex_record.trace
Expand Down Expand Up @@ -445,7 +445,7 @@ async def receive_pres_ack(self, message: V20PresAck, conn_record: ConnRecord):
"role": V20PresExRecord.ROLE_PROVER,
},
)

pres_ex_record.verified = message._verification_result
pres_ex_record.state = V20PresExRecord.STATE_DONE

await pres_ex_record.save(session, reason="receive v2.0 presentation ack")
Expand Down
12 changes: 10 additions & 2 deletions aries_cloudagent/protocols/present_proof/v2_0/messages/pres_ack.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Represents an explicit RFC 15 ack message, adopted into present-proof protocol."""

from marshmallow import EXCLUDE
from marshmallow import EXCLUDE, fields, validate

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

Expand All @@ -19,7 +19,7 @@ class Meta:
message_type = PRES_20_ACK
schema_class = "V20PresAckSchema"

def __init__(self, status: str = None, **kwargs):
def __init__(self, status: str = None, verification_result: str = None, **kwargs):
"""
Initialize an explicit ack message instance.
Expand All @@ -28,6 +28,7 @@ def __init__(self, status: str = None, **kwargs):
"""
super().__init__(status, **kwargs)
self._verification_result = verification_result


class V20PresAckSchema(V10AckSchema):
Expand All @@ -38,3 +39,10 @@ class Meta:

model_class = V20PresAck
unknown = EXCLUDE

verification_result = fields.Str(
required=False,
description="Whether presentation is verified: true or false",
example="true",
validate=validate.OneOf(["true", "false"]),
)
Original file line number Diff line number Diff line change
Expand Up @@ -2076,13 +2076,31 @@ async def test_send_pres_ack(self):
messages = responder.messages
assert len(messages) == 1

px_rec = V20PresExRecord(verified="true")

responder = MockResponder()
self.profile.context.injector.bind_instance(BaseResponder, responder)

await self.manager.send_pres_ack(px_rec)
messages = responder.messages
assert len(messages) == 1

px_rec = V20PresExRecord(verified="false")

responder = MockResponder()
self.profile.context.injector.bind_instance(BaseResponder, responder)

await self.manager.send_pres_ack(px_rec)
messages = responder.messages
assert len(messages) == 1

async def test_send_pres_ack_no_responder(self):
px_rec = V20PresExRecord()

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

async def test_receive_pres_ack(self):
async def test_receive_pres_ack_a(self):
conn_record = async_mock.MagicMock(connection_id=CONN_ID)

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

assert px_rec_out.state == V20PresExRecord.STATE_DONE

async def test_receive_pres_ack_b(self):
conn_record = async_mock.MagicMock(connection_id=CONN_ID)

px_rec_dummy = V20PresExRecord()
message = async_mock.MagicMock(_verification_result="true")

with async_mock.patch.object(
V20PresExRecord, "save", autospec=True
) as save_ex, async_mock.patch.object(
V20PresExRecord, "retrieve_by_tag_filter", autospec=True
) as retrieve_ex:
retrieve_ex.return_value = px_rec_dummy
px_rec_out = await self.manager.receive_pres_ack(message, conn_record)
save_ex.assert_called_once()

assert px_rec_out.state == V20PresExRecord.STATE_DONE
assert px_rec_out.verified == "true"

async def test_receive_problem_report(self):
connection_id = "connection-id"
stored_exchange = V20PresExRecord(
Expand Down

0 comments on commit 01981b6

Please sign in to comment.