From 34577b37309cfd2ee1fcaffb15bf4657b4ad6b4d Mon Sep 17 00:00:00 2001 From: PeterStrob Date: Fri, 29 Oct 2021 13:43:42 -0700 Subject: [PATCH 1/4] feat:added presentation exchange flow integration test Signed-off-by: PeterStrob --- .../v0_1/messages/pres_request_received.py | 2 +- int/docker-compose.yml | 2 +- int/tests/test_presentation_integration.py | 77 +++++++++++++++++++ 3 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 int/tests/test_presentation_integration.py diff --git a/acapy_plugin_toolbox/holder/v0_1/messages/pres_request_received.py b/acapy_plugin_toolbox/holder/v0_1/messages/pres_request_received.py index d3e8bf18..8a4430d1 100644 --- a/acapy_plugin_toolbox/holder/v0_1/messages/pres_request_received.py +++ b/acapy_plugin_toolbox/holder/v0_1/messages/pres_request_received.py @@ -48,7 +48,7 @@ class Fields: def __init__(self, record: PresExRecord, **kwargs): super().__init__(**kwargs) self.raw_repr = record - self.presentation_request = record.presentation_request + self.presentation_request = record.presentation_request.serialize() self.presentation_exchange_id = record.presentation_exchange_id self.matching_credentials = [] self.page = None diff --git a/int/docker-compose.yml b/int/docker-compose.yml index 6b39a26f..7d991f63 100644 --- a/int/docker-compose.yml +++ b/int/docker-compose.yml @@ -18,7 +18,7 @@ services: ACAPY_TOOLBOX_LOG_LEVEL: DEBUG ports: - "3001:3001" - command: start -it http 0.0.0.0 3000 -ot http -e http://acapy_plugin_agent:3000 --admin 0.0.0.0 3001 --admin-insecure-mode --plugin acapy_plugin_toolbox --genesis-url https://raw.githubusercontent.com/Indicio-tech/indicio-network/master/genesis_files/pool_transactions_testnet_genesis --wallet-type indy --wallet-name default --wallet-key "insecure, for use in testing only" --auto-provision --auto-ping-connection --monitor-ping + command: start -it http 0.0.0.0 3000 -ot http -e http://acapy_plugin_agent:3000 --admin 0.0.0.0 3001 --admin-insecure-mode --plugin acapy_plugin_toolbox --genesis-url https://raw.githubusercontent.com/Indicio-tech/indicio-network/master/genesis_files/pool_transactions_testnet_genesis --wallet-type indy --wallet-name default --wallet-key "insecure, for use in testing only" --auto-provision --auto-ping-connection --monitor-ping --auto-store-credential echo: image: echo-agent diff --git a/int/tests/test_presentation_integration.py b/int/tests/test_presentation_integration.py new file mode 100644 index 00000000..2442cb9d --- /dev/null +++ b/int/tests/test_presentation_integration.py @@ -0,0 +1,77 @@ +from acapy_client.models.indy_proof_request import IndyProofRequest +from acapy_client.models.indy_proof_request_requested_attributes import ( + IndyProofRequestRequestedAttributes, +) +from acapy_client.models.indy_proof_request_requested_predicates import ( + IndyProofRequestRequestedPredicates, +) +from acapy_client.models.v10_presentation_send_request_request import ( + V10PresentationSendRequestRequest, +) +from acapy_client.types import Unset +import pytest +from typing import cast +from acapy_client import Client +from acapy_client.models.conn_record import ConnRecord +from acapy_client.api.present_proof_v10 import send_proof_request + +from tests.test_holder import issue_credential, issuer_holder_connection +from tests.conftest import connection + + +@pytest.mark.asyncio +async def test_presentation( + backchannel: Client, + issue_credential, + issuer_holder_connection, + wait_for_message, + connection, +): + """Test the presentation message and notification flows.""" + verifier, prover = issuer_holder_connection + verifier = cast(ConnRecord, verifier) + prover = cast(ConnRecord, prover) + assert not isinstance(verifier.connection_id, Unset) + assert not isinstance(prover.connection_id, Unset) + proof_req = await send_proof_request.asyncio( + client=backchannel, + json_body=V10PresentationSendRequestRequest( + connection_id=prover.connection_id, + proof_request=IndyProofRequest( + name="test-proof", + requested_attributes=IndyProofRequestRequestedAttributes.from_dict( + {"attr_1_0": {"name": "attr_1_0"}} + ), + requested_predicates=IndyProofRequestRequestedPredicates(), + version="0.1", + ), + ), + ) + presentation_request_received = await wait_for_message( + msg_type="did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/admin-holder/0.1/presentation-request-received" + ) + assert presentation_request_received["matching_credentials"] + await connection.send_async( + { + "@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/admin-holder/0.1/presentation-request-approve", + "@id": "3fa85f64-5717-4562-b3fc-2c963f66afa6", + "presentation_exchange_id": presentation_request_received[ + "presentation_exchange_id" + ], + "self_attested_attributes": {}, + "requested_attributes": { + "attr_1_0": { + "cred_id": presentation_request_received["matching_credentials"][0][ + "cred_info" + ]["referent"], + "revealed": True, + } + }, + "requested_predicates": {}, + "comment": "It's dangerous to go alone. Take this!", + } + ) + pres_sent = await wait_for_message( + msg_type="did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/admin-holder/0.1/presentation-sent" + ) + assert pres_sent["presentation_exchange_id"] From 278564f6e08117ed63cc379066d4864a0501bbe1 Mon Sep 17 00:00:00 2001 From: PeterStrob Date: Wed, 3 Nov 2021 14:08:21 -0700 Subject: [PATCH 2/4] fix:updated test_events and test_holder tests, added flag to docker-compose.yml file Signed-off-by: PeterStrob --- int/docker-compose.yml | 2 +- int/tests/test_holder.py | 14 +++----------- tests/holder/test_events.py | 6 +++++- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/int/docker-compose.yml b/int/docker-compose.yml index 7d991f63..f9053eb8 100644 --- a/int/docker-compose.yml +++ b/int/docker-compose.yml @@ -18,7 +18,7 @@ services: ACAPY_TOOLBOX_LOG_LEVEL: DEBUG ports: - "3001:3001" - command: start -it http 0.0.0.0 3000 -ot http -e http://acapy_plugin_agent:3000 --admin 0.0.0.0 3001 --admin-insecure-mode --plugin acapy_plugin_toolbox --genesis-url https://raw.githubusercontent.com/Indicio-tech/indicio-network/master/genesis_files/pool_transactions_testnet_genesis --wallet-type indy --wallet-name default --wallet-key "insecure, for use in testing only" --auto-provision --auto-ping-connection --monitor-ping --auto-store-credential + command: start -it http 0.0.0.0 3000 -ot http -e http://acapy_plugin_agent:3000 --admin 0.0.0.0 3001 --admin-insecure-mode --plugin acapy_plugin_toolbox --genesis-url https://raw.githubusercontent.com/Indicio-tech/indicio-network/master/genesis_files/pool_transactions_testnet_genesis --wallet-type indy --wallet-name default --wallet-key "insecure, for use in testing only" --auto-provision --auto-ping-connection --monitor-ping --auto-store-credential --preserve-exchange-records echo: image: echo-agent diff --git a/int/tests/test_holder.py b/int/tests/test_holder.py index a304271e..140b1fb3 100644 --- a/int/tests/test_holder.py +++ b/int/tests/test_holder.py @@ -166,28 +166,20 @@ async def test_holder_credential_exchange( async def test_credentials_get_list( backchannel: Client, connection, - issuer_holder_connection, - endorser_did, - create_schema, - create_cred_def, issue_credential, ): - cred1 = issue_credential - cred2 = issue_credential + cred = issue_credential credentials_get_list = await connection.send_and_await_reply_async( { "@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/admin-holder/0.1/credentials-get-list" } ) - cred1_set = set([result.credential_exchange_id for result in cred1.results]) - cred2_set = set([result.credential_exchange_id for result in cred2.results]) + cred_set = set([result.credential_exchange_id for result in cred.results]) cred_get_list_set = set( [cred["credential_exchange_id"] for cred in credentials_get_list["results"]] ) - assert ( credentials_get_list["@type"] == "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/admin-holder/0.1/credentials-list" ) - assert cred1_set.issubset(cred_get_list_set) - assert cred2_set.issubset(cred_get_list_set) + assert cred_set.issubset(cred_get_list_set) diff --git a/tests/holder/test_events.py b/tests/holder/test_events.py index 10ff7eff..bd791274 100644 --- a/tests/holder/test_events.py +++ b/tests/holder/test_events.py @@ -2,6 +2,8 @@ # pylint: disable=redefined-outer-name +import typing + import pytest from acapy_plugin_toolbox.holder import v0_1 as test_module from aries_cloudagent.core.event_bus import Event, EventBus @@ -120,7 +122,9 @@ async def test_pres_req_received_sent_on_state(profile, mock_send_to_admins): handler = test_module.present_proof_event_handler state = V10PresentationExchange.STATE_REQUEST_RECEIVED message = test_module.PresRequestReceived - event = Event("anything", {"state": state}) + event = Event( + "anything", {"state": state, "presentation_request": {"pres_request": "test"}} + ) with mock.patch.object( message, "retrieve_matching_credentials", mock.CoroutineMock() ): From 55cf1be212868fd52da592b9e9022f5de5782f54 Mon Sep 17 00:00:00 2001 From: PeterStrob Date: Thu, 4 Nov 2021 09:31:29 -0700 Subject: [PATCH 3/4] fix:renamed presentation test, removed unnecessary import Signed-off-by: PeterStrob --- int/tests/test_presentation.py | 77 ++++++++++++++++++++++++++++++++++ tests/holder/test_events.py | 2 - 2 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 int/tests/test_presentation.py diff --git a/int/tests/test_presentation.py b/int/tests/test_presentation.py new file mode 100644 index 00000000..2442cb9d --- /dev/null +++ b/int/tests/test_presentation.py @@ -0,0 +1,77 @@ +from acapy_client.models.indy_proof_request import IndyProofRequest +from acapy_client.models.indy_proof_request_requested_attributes import ( + IndyProofRequestRequestedAttributes, +) +from acapy_client.models.indy_proof_request_requested_predicates import ( + IndyProofRequestRequestedPredicates, +) +from acapy_client.models.v10_presentation_send_request_request import ( + V10PresentationSendRequestRequest, +) +from acapy_client.types import Unset +import pytest +from typing import cast +from acapy_client import Client +from acapy_client.models.conn_record import ConnRecord +from acapy_client.api.present_proof_v10 import send_proof_request + +from tests.test_holder import issue_credential, issuer_holder_connection +from tests.conftest import connection + + +@pytest.mark.asyncio +async def test_presentation( + backchannel: Client, + issue_credential, + issuer_holder_connection, + wait_for_message, + connection, +): + """Test the presentation message and notification flows.""" + verifier, prover = issuer_holder_connection + verifier = cast(ConnRecord, verifier) + prover = cast(ConnRecord, prover) + assert not isinstance(verifier.connection_id, Unset) + assert not isinstance(prover.connection_id, Unset) + proof_req = await send_proof_request.asyncio( + client=backchannel, + json_body=V10PresentationSendRequestRequest( + connection_id=prover.connection_id, + proof_request=IndyProofRequest( + name="test-proof", + requested_attributes=IndyProofRequestRequestedAttributes.from_dict( + {"attr_1_0": {"name": "attr_1_0"}} + ), + requested_predicates=IndyProofRequestRequestedPredicates(), + version="0.1", + ), + ), + ) + presentation_request_received = await wait_for_message( + msg_type="did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/admin-holder/0.1/presentation-request-received" + ) + assert presentation_request_received["matching_credentials"] + await connection.send_async( + { + "@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/admin-holder/0.1/presentation-request-approve", + "@id": "3fa85f64-5717-4562-b3fc-2c963f66afa6", + "presentation_exchange_id": presentation_request_received[ + "presentation_exchange_id" + ], + "self_attested_attributes": {}, + "requested_attributes": { + "attr_1_0": { + "cred_id": presentation_request_received["matching_credentials"][0][ + "cred_info" + ]["referent"], + "revealed": True, + } + }, + "requested_predicates": {}, + "comment": "It's dangerous to go alone. Take this!", + } + ) + pres_sent = await wait_for_message( + msg_type="did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/admin-holder/0.1/presentation-sent" + ) + assert pres_sent["presentation_exchange_id"] diff --git a/tests/holder/test_events.py b/tests/holder/test_events.py index bd791274..28e1e73b 100644 --- a/tests/holder/test_events.py +++ b/tests/holder/test_events.py @@ -2,8 +2,6 @@ # pylint: disable=redefined-outer-name -import typing - import pytest from acapy_plugin_toolbox.holder import v0_1 as test_module from aries_cloudagent.core.event_bus import Event, EventBus From efd00b96c6e9fa8e346a229bb1cd98af35ce970b Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Fri, 5 Nov 2021 10:34:24 -0400 Subject: [PATCH 4/4] fix: remove old file Signed-off-by: Daniel Bluhm --- int/tests/test_presentation_integration.py | 77 ---------------------- 1 file changed, 77 deletions(-) delete mode 100644 int/tests/test_presentation_integration.py diff --git a/int/tests/test_presentation_integration.py b/int/tests/test_presentation_integration.py deleted file mode 100644 index 2442cb9d..00000000 --- a/int/tests/test_presentation_integration.py +++ /dev/null @@ -1,77 +0,0 @@ -from acapy_client.models.indy_proof_request import IndyProofRequest -from acapy_client.models.indy_proof_request_requested_attributes import ( - IndyProofRequestRequestedAttributes, -) -from acapy_client.models.indy_proof_request_requested_predicates import ( - IndyProofRequestRequestedPredicates, -) -from acapy_client.models.v10_presentation_send_request_request import ( - V10PresentationSendRequestRequest, -) -from acapy_client.types import Unset -import pytest -from typing import cast -from acapy_client import Client -from acapy_client.models.conn_record import ConnRecord -from acapy_client.api.present_proof_v10 import send_proof_request - -from tests.test_holder import issue_credential, issuer_holder_connection -from tests.conftest import connection - - -@pytest.mark.asyncio -async def test_presentation( - backchannel: Client, - issue_credential, - issuer_holder_connection, - wait_for_message, - connection, -): - """Test the presentation message and notification flows.""" - verifier, prover = issuer_holder_connection - verifier = cast(ConnRecord, verifier) - prover = cast(ConnRecord, prover) - assert not isinstance(verifier.connection_id, Unset) - assert not isinstance(prover.connection_id, Unset) - proof_req = await send_proof_request.asyncio( - client=backchannel, - json_body=V10PresentationSendRequestRequest( - connection_id=prover.connection_id, - proof_request=IndyProofRequest( - name="test-proof", - requested_attributes=IndyProofRequestRequestedAttributes.from_dict( - {"attr_1_0": {"name": "attr_1_0"}} - ), - requested_predicates=IndyProofRequestRequestedPredicates(), - version="0.1", - ), - ), - ) - presentation_request_received = await wait_for_message( - msg_type="did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/admin-holder/0.1/presentation-request-received" - ) - assert presentation_request_received["matching_credentials"] - await connection.send_async( - { - "@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/admin-holder/0.1/presentation-request-approve", - "@id": "3fa85f64-5717-4562-b3fc-2c963f66afa6", - "presentation_exchange_id": presentation_request_received[ - "presentation_exchange_id" - ], - "self_attested_attributes": {}, - "requested_attributes": { - "attr_1_0": { - "cred_id": presentation_request_received["matching_credentials"][0][ - "cred_info" - ]["referent"], - "revealed": True, - } - }, - "requested_predicates": {}, - "comment": "It's dangerous to go alone. Take this!", - } - ) - pres_sent = await wait_for_message( - msg_type="did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/admin-holder/0.1/presentation-sent" - ) - assert pres_sent["presentation_exchange_id"]