From d85035d70c62a3b88e535a7188d8f0ce1a2d532e Mon Sep 17 00:00:00 2001 From: Jason Sherman Date: Thu, 2 Nov 2023 16:22:16 -0700 Subject: [PATCH] Goal and Goal Code in invitation URL. Signed-off-by: Jason Sherman --- .../protocols/out_of_band/v1_0/manager.py | 3 +- .../out_of_band/v1_0/tests/test_manager.py | 45 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/aries_cloudagent/protocols/out_of_band/v1_0/manager.py b/aries_cloudagent/protocols/out_of_band/v1_0/manager.py index 2dfbe7f421..649401a5c5 100644 --- a/aries_cloudagent/protocols/out_of_band/v1_0/manager.py +++ b/aries_cloudagent/protocols/out_of_band/v1_0/manager.py @@ -362,11 +362,12 @@ async def create_invitation( routing_keys=routing_keys, ) ] - invi_url = invi_msg.to_url() if goal and goal_code: invi_msg.goal_code = goal_code invi_msg.goal = goal + invi_url = invi_msg.to_url() + # Update connection record if conn_rec: async with self.profile.session() as session: diff --git a/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_manager.py b/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_manager.py index 62f7db787c..b8a33c2598 100644 --- a/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_manager.py @@ -1,5 +1,6 @@ """Test OOB Manager.""" +import base64 import json from copy import deepcopy from datetime import datetime, timedelta, timezone @@ -850,6 +851,50 @@ async def test_create_invitation_x_public_metadata(self): context.exception ) + async def test_create_invitation_goal_code(self): + self.profile.context.update_settings({"public_invites": True}) + with mock.patch.object( + InMemoryWallet, "get_public_did", autospec=True + ) as mock_wallet_get_public_did: + mock_wallet_get_public_did.return_value = DIDInfo( + TestConfig.test_did, + TestConfig.test_verkey, + None, + method=SOV, + key_type=ED25519, + ) + goal = "To issue a Faber College Graduate credential" + goal_code = "issue-vc" + my_label = "Invitation to Barry" + + invi_rec = await self.manager.create_invitation( + public=False, + my_label=my_label, + protocol_version="1.1", + alias="Test Alias", + service_accept=["didcomm/aip1", "didcomm/aip2;env=rfc19"], + hs_protos=[test_module.HSProto.RFC23], + goal=goal, + goal_code=goal_code, + ) + assert isinstance(invi_rec, InvitationRecord) + assert invi_rec.invitation.handshake_protocols + assert invi_rec.invitation.label == my_label + assert invi_rec.invitation.goal == goal + assert invi_rec.invitation.goal_code == goal_code + assert invi_rec.invitation_url + + base64_message = invi_rec.invitation_url.split("=", maxsplit=1)[1] + base64_bytes = base64_message.encode("ascii") + message_bytes = base64.b64decode(base64_bytes) + data = message_bytes.decode("ascii") + assert data + invite_json = json.loads(data) + assert invite_json + assert invite_json["label"] == my_label + assert invite_json["goal"] == goal + assert invite_json["goal_code"] == goal_code + async def test_wait_for_conn_rec_active_retrieve_by_id(self): with mock.patch.object( ConnRecord,