Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

accommodate proofs with repeat cred defs, check for bait-and-switch b… #330

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
restore present_proof_create_request() and test coverage
Signed-off-by: sklump <[email protected]>
  • Loading branch information
sklump committed Jan 20, 2020
commit 5fd106714811b3c899a7452e12487b312ea55aea
1 change: 0 additions & 1 deletion aries_cloudagent/protocols/present_proof/v1_0/manager.py
Original file line number Diff line number Diff line change
@@ -370,7 +370,6 @@ async def receive_presentation(self):
f"Presentation {name}={value} mismatches proposal value"
)

# Looks OK
presentation_exchange_record.presentation = presentation
presentation_exchange_record.state = (
V10PresentationExchange.STATE_PRESENTATION_RECEIVED
55 changes: 55 additions & 0 deletions aries_cloudagent/protocols/present_proof/v1_0/routes.py
Original file line number Diff line number Diff line change
@@ -427,6 +427,61 @@ async def presentation_exchange_send_proposal(request: web.BaseRequest):
return web.json_response(presentation_exchange_record.serialize())


sklump marked this conversation as resolved.
Show resolved Hide resolved
@docs(
tags=["present-proof"],
summary="""
Creates a presentation request not bound to any proposal or existing connection
""",
)
@request_schema(V10PresentationRequestRequestSchema())
@response_schema(V10PresentationExchangeSchema(), 200)
async def presentation_exchange_create_request(request: web.BaseRequest):
"""
Request handler for creating a free presentation request.

The presentation request will not be bound to any proposal
or existing connection.

Args:
request: aiohttp request object

Returns:
The presentation exchange details

"""
context = request.app["request_context"]
outbound_handler = request.app["outbound_message_router"]

body = await request.json()

comment = body.get("comment")
indy_proof_request = body.get("proof_request")
if not indy_proof_request.get("nonce"):
indy_proof_request["nonce"] = str(uuid4().int)

presentation_request_message = PresentationRequest(
comment=comment,
request_presentations_attach=[
AttachDecorator.from_indy_dict(
indy_dict=indy_proof_request,
ident=ATTACH_DECO_IDS[PRESENTATION_REQUEST],
)
],
)

presentation_manager = PresentationManager(context)

(
presentation_exchange_record
) = await presentation_manager.create_exchange_for_request(
connection_id=None, presentation_request_message=presentation_request_message
)

await outbound_handler(presentation_request_message, connection_id=None)

return web.json_response(presentation_exchange_record.serialize())


@docs(
tags=["present-proof"],
summary="Sends a free presentation request not bound to any proposal",
42 changes: 42 additions & 0 deletions aries_cloudagent/protocols/present_proof/v1_0/tests/test_routes.py
Original file line number Diff line number Diff line change
@@ -256,6 +256,48 @@ async def test_presentation_exchange_send_proposal_not_ready(self):
with self.assertRaises(test_module.web.HTTPForbidden):
await test_module.presentation_exchange_send_proposal(mock)

async def test_presentation_exchange_create_request(self):
mock = async_mock.MagicMock()
mock.json = async_mock.CoroutineMock(
return_value={"comment": "dummy", "proof_request": {}}
)

mock.app = {
"outbound_message_router": async_mock.CoroutineMock(),
"request_context": self.mock_context,
}

with async_mock.patch.object(
test_module, "PresentationManager", autospec=True
) as mock_presentation_manager, async_mock.patch.object(
test_module, "PresentationPreview", autospec=True
) as mock_presentation_proposal, async_mock.patch.object(
test_module, "PresentationRequest", autospec=True
) as mock_presentation_request, async_mock.patch.object(
test_module, "AttachDecorator", autospec=True
) as mock_attach_decorator, async_mock.patch.object(
test_module, "V10PresentationExchange", autospec=True
) as mock_presentation_exchange:

mock_attach_decorator.from_indy_dict = async_mock.MagicMock(
return_value=mock_attach_decorator
)

mock_presentation_exchange.serialize = async_mock.MagicMock()
mock_presentation_exchange.serialize.return_value = {"hello": "world"}

mock_presentation_manager.return_value.create_exchange_for_request = async_mock.CoroutineMock(
return_value=mock_presentation_exchange
)

with async_mock.patch.object(
test_module.web, "json_response"
) as mock_response:
await test_module.presentation_exchange_create_request(mock)
mock_response.assert_called_once_with(
mock_presentation_exchange.serialize.return_value
)

async def test_presentation_exchange_send_free_request(self):
mock = async_mock.MagicMock()
mock.json = async_mock.CoroutineMock(