Skip to content

Commit

Permalink
Merge pull request #1383 from ianco/proof-verify
Browse files Browse the repository at this point in the history
Remove connection check on proof verify
  • Loading branch information
andrewwhitehead authored Sep 1, 2021
2 parents 1a4df0a + 42fadfb commit f70e454
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 159 deletions.
10 changes: 0 additions & 10 deletions aries_cloudagent/protocols/present_proof/v1_0/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -817,16 +817,6 @@ async def presentation_exchange_verify_presentation(request: web.BaseRequest):
)
)

connection_id = pres_ex_record.connection_id

try:
connection_record = await ConnRecord.retrieve_by_id(session, connection_id)
except StorageError as err:
raise web.HTTPBadRequest(reason=err.roll_up) from err

if not connection_record.is_ready:
raise web.HTTPForbidden(reason=f"Connection {connection_id} not ready")

presentation_manager = PresentationManager(context.profile)
try:
pres_ex_record = await presentation_manager.verify_presentation(pres_ex_record)
Expand Down
86 changes: 0 additions & 86 deletions aries_cloudagent/protocols/present_proof/v1_0/tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1299,92 +1299,6 @@ async def test_presentation_exchange_verify_presentation_px_rec_not_found(self):
)
assert "no such record" in str(context.exception)

async def test_presentation_exchange_verify_presentation_not_found(self):
self.request.match_info = {"pres_ex_id": "dummy"}
self.profile.context.injector.bind_instance(
BaseLedger,
async_mock.MagicMock(
__aenter__=async_mock.CoroutineMock(),
__aexit__=async_mock.CoroutineMock(),
),
)
self.profile.context.injector.bind_instance(
IndyVerifier,
async_mock.MagicMock(
verify_presentation=async_mock.CoroutineMock(),
),
)

with async_mock.patch(
"aries_cloudagent.connections.models.conn_record.ConnRecord",
autospec=True,
) as mock_connection_record, async_mock.patch(
"aries_cloudagent.protocols.present_proof.v1_0.manager.PresentationManager",
autospec=True,
) as mock_presentation_manager, async_mock.patch(
(
"aries_cloudagent.protocols.present_proof.v1_0."
"models.presentation_exchange.V10PresentationExchange"
),
autospec=True,
) as mock_presentation_exchange:

# Since we are mocking import
importlib.reload(test_module)

mock_presentation_exchange.retrieve_by_id = async_mock.CoroutineMock(
return_value=async_mock.MagicMock(
state=mock_presentation_exchange.STATE_PRESENTATION_RECEIVED,
connection_id="dummy",
)
)

mock_connection_record.retrieve_by_id = async_mock.CoroutineMock(
side_effect=StorageNotFoundError
)

with self.assertRaises(test_module.web.HTTPBadRequest):
await test_module.presentation_exchange_verify_presentation(
self.request
)

async def test_presentation_exchange_verify_presentation_not_ready(self):
self.request.match_info = {"pres_ex_id": "dummy"}

with async_mock.patch(
"aries_cloudagent.connections.models.conn_record.ConnRecord",
autospec=True,
) as mock_connection_record, async_mock.patch(
"aries_cloudagent.protocols.present_proof.v1_0.manager.PresentationManager",
autospec=True,
) as mock_presentation_manager, async_mock.patch(
(
"aries_cloudagent.protocols.present_proof.v1_0."
"models.presentation_exchange.V10PresentationExchange"
),
autospec=True,
) as mock_presentation_exchange:

# Since we are mocking import
importlib.reload(test_module)

mock_presentation_exchange.retrieve_by_id = async_mock.CoroutineMock(
return_value=async_mock.MagicMock(
state=mock_presentation_exchange.STATE_PRESENTATION_RECEIVED,
connection_id="dummy",
)
)

mock_connection_record.is_ready = False
mock_connection_record.retrieve_by_id = async_mock.CoroutineMock(
return_value=mock_connection_record
)

with self.assertRaises(test_module.web.HTTPForbidden):
await test_module.presentation_exchange_verify_presentation(
self.request
)

async def test_presentation_exchange_verify_presentation_bad_state(self):
self.request.json = async_mock.CoroutineMock()
self.request.match_info = {"pres_ex_id": "dummy"}
Expand Down
10 changes: 0 additions & 10 deletions aries_cloudagent/protocols/present_proof/v2_0/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1093,16 +1093,6 @@ async def present_proof_verify_presentation(request: web.BaseRequest):
)
)

connection_id = pres_ex_record.connection_id

try:
conn_record = await ConnRecord.retrieve_by_id(session, connection_id)
except StorageError as err:
raise web.HTTPBadRequest(reason=err.roll_up) from err

if not conn_record.is_ready:
raise web.HTTPForbidden(reason=f"Connection {connection_id} not ready")

pres_manager = V20PresManager(context.profile)
try:
pres_ex_record = await pres_manager.verify_pres(pres_ex_record)
Expand Down
53 changes: 0 additions & 53 deletions aries_cloudagent/protocols/present_proof/v2_0/tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2082,59 +2082,6 @@ async def test_present_proof_verify_presentation_px_rec_not_found(self):
await test_module.present_proof_verify_presentation(self.request)
assert "no such record" in str(context.exception)

async def test_present_proof_verify_presentation_not_found(self):
self.request.match_info = {"pres_ex_id": "dummy"}

with async_mock.patch.object(
test_module, "ConnRecord", autospec=True
) as mock_conn_rec_cls, async_mock.patch.object(
test_module, "V20PresExRecord", autospec=True
) as mock_px_rec_cls:
mock_px_rec_inst = async_mock.MagicMock(
connection_id="dummy",
state=test_module.V20PresExRecord.STATE_PRESENTATION_RECEIVED,
serialize=async_mock.MagicMock(
return_value={"thread_id": "sample-thread-id"}
),
)
mock_px_rec_cls.retrieve_by_id = async_mock.CoroutineMock(
return_value=mock_px_rec_inst
)

mock_conn_rec_inst = async_mock.MagicMock(is_ready=True)
mock_conn_rec_cls.retrieve_by_id = async_mock.CoroutineMock(
side_effect=StorageNotFoundError()
)

with self.assertRaises(test_module.web.HTTPBadRequest):
await test_module.present_proof_verify_presentation(self.request)

async def test_present_proof_verify_presentation_not_ready(self):
self.request.match_info = {"pres_ex_id": "dummy"}

with async_mock.patch.object(
test_module, "ConnRecord", autospec=True
) as mock_conn_rec_cls, async_mock.patch.object(
test_module, "V20PresExRecord", autospec=True
) as mock_px_rec_cls:
mock_px_rec_inst = async_mock.MagicMock(
connection_id="dummy",
state=test_module.V20PresExRecord.STATE_PRESENTATION_RECEIVED,
serialize=async_mock.MagicMock(
return_value={"thread_id": "sample-thread-id"}
),
)
mock_px_rec_cls.retrieve_by_id = async_mock.CoroutineMock(
return_value=mock_px_rec_inst
)
mock_conn_rec_inst = async_mock.MagicMock(is_ready=False)
mock_conn_rec_cls.retrieve_by_id = async_mock.CoroutineMock(
return_value=mock_conn_rec_inst
)

with self.assertRaises(test_module.web.HTTPForbidden):
await test_module.present_proof_verify_presentation(self.request)

async def test_present_proof_verify_presentation_bad_state(self):
self.request.match_info = {"pres_ex_id": "dummy"}

Expand Down

0 comments on commit f70e454

Please sign in to comment.