From b05c9c6d13dc6eba735eaaeb942cc693f80b07bc Mon Sep 17 00:00:00 2001 From: ff137 Date: Tue, 23 Apr 2024 22:46:07 +0200 Subject: [PATCH 1/5] :bug: Fix ServiceDecorator references in finding oob target Signed-off-by: ff137 --- aries_cloudagent/core/oob_processor.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/aries_cloudagent/core/oob_processor.py b/aries_cloudagent/core/oob_processor.py index c3a99a64b1..35c89f22e2 100644 --- a/aries_cloudagent/core/oob_processor.py +++ b/aries_cloudagent/core/oob_processor.py @@ -91,7 +91,7 @@ async def find_oob_target_for_outbound_message( oob_record.their_service, ) - their_service = ServiceDecorator.deserialize(oob_record.their_service) + their_service = oob_record.their_service # Attach ~service decorator so other message can respond message = json.loads(outbound_message.payload) @@ -100,7 +100,7 @@ async def find_oob_target_for_outbound_message( "Setting our service on the message ~service %s", oob_record.our_service, ) - message["~service"] = oob_record.our_service + message["~service"] = oob_record.our_service.serialize() message["~thread"] = { **message.get("~thread", {}), @@ -256,14 +256,7 @@ async def find_oob_record_for_inbound_message( ) return None - their_service = ( - cast( - ServiceDecorator, - ServiceDecorator.deserialize(oob_record.their_service), - ) - if oob_record.their_service - else None - ) + their_service = oob_record.their_service # Verify the sender key is present in their service in our record # If we don't have the sender verkey stored yet we can allow any key From 2665d7772171ba3452232f0e137e038e651fc3fa Mon Sep 17 00:00:00 2001 From: ff137 Date: Tue, 23 Apr 2024 23:50:13 +0200 Subject: [PATCH 2/5] :white_check_mark: fix tests by using ServiceDecorator model instead of dictionaries Signed-off-by: ff137 --- .../core/tests/test_oob_processor.py | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/aries_cloudagent/core/tests/test_oob_processor.py b/aries_cloudagent/core/tests/test_oob_processor.py index 9559e9bde5..eb805eda64 100644 --- a/aries_cloudagent/core/tests/test_oob_processor.py +++ b/aries_cloudagent/core/tests/test_oob_processor.py @@ -31,11 +31,11 @@ async def asyncSetUp(self): self.oob_record = mock.MagicMock( connection_id="a-connection-id", attach_thread_id="the-thid", - their_service={ - "recipientKeys": ["9WCgWKUaAJj3VWxxtzvvMQN3AoFxoBtBDo9ntwJnVVCC"], - "routingKeys": ["6QSduYdf8Bi6t8PfNm5vNomGWDtXhmMmTRzaciudBXYJ"], - "serviceEndpoint": "http://their-service-endpoint.com", - }, + their_service=ServiceDecorator( + recipient_keys=["9WCgWKUaAJj3VWxxtzvvMQN3AoFxoBtBDo9ntwJnVVCC"], + routing_keys=["6QSduYdf8Bi6t8PfNm5vNomGWDtXhmMmTRzaciudBXYJ"], + endpoint="http://their-service-endpoint.com", + ), emit_event=mock.CoroutineMock(), delete_record=mock.CoroutineMock(), save=mock.CoroutineMock(), @@ -121,16 +121,16 @@ async def test_find_oob_target_for_outbound_message(self): invitation=mock.MagicMock(requests_attach=[]), invi_msg_id="the-pthid", our_recipient_key="3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRx", - their_service={ - "recipientKeys": ["9WCgWKUaAJj3VWxxtzvvMQN3AoFxoBtBDo9ntwJnVVCC"], - "serviceEndpoint": "http://their-service-endpoint.com", - "routingKeys": ["6QSduYdf8Bi6t8PfNm5vNomGWDtXhmMmTRzaciudBXYJ"], - }, - our_service={ - "recipientKeys": ["3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRx"], - "serviceEndpoint": "http://our-service-endpoint.com", - "routingKeys": [], - }, + their_service=ServiceDecorator( + recipient_keys=["9WCgWKUaAJj3VWxxtzvvMQN3AoFxoBtBDo9ntwJnVVCC"], + endpoint="http://their-service-endpoint.com", + routing_keys=["6QSduYdf8Bi6t8PfNm5vNomGWDtXhmMmTRzaciudBXYJ"], + ), + our_service=ServiceDecorator( + recipient_keys=["3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRx"], + endpoint="http://our-service-endpoint.com", + routing_keys=[], + ), ) message = json.dumps({"~thread": {"thid": "the-thid"}}) @@ -196,16 +196,16 @@ async def test_find_oob_target_for_outbound_message_update_service_thread(self): invitation=mock.MagicMock(requests_attach=[]), invi_msg_id="the-pthid", our_recipient_key="3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRx", - their_service={ - "recipientKeys": ["9WCgWKUaAJj3VWxxtzvvMQN3AoFxoBtBDo9ntwJnVVCC"], - "serviceEndpoint": "http://their-service-endpoint.com", - "routingKeys": ["6QSduYdf8Bi6t8PfNm5vNomGWDtXhmMmTRzaciudBXYJ"], - }, - our_service={ - "recipientKeys": ["3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRx"], - "serviceEndpoint": "http://our-service-endpoint.com", - "routingKeys": [], - }, + their_service=ServiceDecorator( + recipient_keys=["9WCgWKUaAJj3VWxxtzvvMQN3AoFxoBtBDo9ntwJnVVCC"], + endpoint="http://their-service-endpoint.com", + routing_keys=["6QSduYdf8Bi6t8PfNm5vNomGWDtXhmMmTRzaciudBXYJ"], + ), + our_service=ServiceDecorator( + recipient_keys=["3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRx"], + endpoint="http://our-service-endpoint.com", + routing_keys=[], + ), ) with mock.patch.object( @@ -303,7 +303,7 @@ async def test_find_oob_record_for_inbound_message_connectionless_retrieve_oob( self.context.message_receipt = MessageReceipt( thread_id="the-thid", recipient_verkey="our-recipient-key", - sender_verkey=self.oob_record.their_service["recipientKeys"][0], + sender_verkey=self.oob_record.their_service.recipient_keys[0], ) assert await self.oob_processor.find_oob_record_for_inbound_message( From 8a7b824404ece9c189497d38d10d7399886162ea Mon Sep 17 00:00:00 2001 From: ff137 Date: Tue, 23 Apr 2024 23:57:35 +0200 Subject: [PATCH 3/5] :art: fix unused import Signed-off-by: ff137 --- aries_cloudagent/core/oob_processor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aries_cloudagent/core/oob_processor.py b/aries_cloudagent/core/oob_processor.py index 35c89f22e2..d6cd9c6281 100644 --- a/aries_cloudagent/core/oob_processor.py +++ b/aries_cloudagent/core/oob_processor.py @@ -2,7 +2,7 @@ import json import logging -from typing import Any, Callable, Dict, List, Optional, cast +from typing import Any, Callable, Dict, List, Optional from ..messaging.agent_message import AgentMessage from ..connections.models.conn_record import ConnRecord From 92d0dc4940f3d5c6a355eb180e1b2b4cac153ec1 Mon Sep 17 00:00:00 2001 From: ff137 Date: Wed, 24 Apr 2024 00:27:10 +0200 Subject: [PATCH 4/5] :cherries: include changes from #2908: dbluhm:fix/connectionless-oob-service-parse Signed-off-by: ff137 --- aries_cloudagent/core/oob_processor.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/aries_cloudagent/core/oob_processor.py b/aries_cloudagent/core/oob_processor.py index d6cd9c6281..91ade823c6 100644 --- a/aries_cloudagent/core/oob_processor.py +++ b/aries_cloudagent/core/oob_processor.py @@ -92,10 +92,12 @@ async def find_oob_target_for_outbound_message( ) their_service = oob_record.their_service + if not their_service: + raise OobMessageProcessorError("Could not determine their service") # Attach ~service decorator so other message can respond message = json.loads(outbound_message.payload) - if not message.get("~service"): + if not message.get("~service") and oob_record.our_service: LOGGER.debug( "Setting our service on the message ~service %s", oob_record.our_service, @@ -256,17 +258,15 @@ async def find_oob_record_for_inbound_message( ) return None - their_service = oob_record.their_service - # Verify the sender key is present in their service in our record # If we don't have the sender verkey stored yet we can allow any key - if their_service and ( + if oob_record.their_service and ( ( context.message_receipt.recipient_verkey and ( not context.message_receipt.sender_verkey or context.message_receipt.sender_verkey - not in their_service.recipient_keys + not in oob_record.their_service.recipient_keys ) ) ): @@ -350,7 +350,7 @@ async def handle_message( LOGGER.debug( "Storing their service in oob record %s", their_service ) - oob_record.their_service = their_service.serialize() + oob_record.their_service = their_service await oob_record.save(session) From 594f5b43e78057ca1150650727c89dc9ff96c78c Mon Sep 17 00:00:00 2001 From: ff137 Date: Wed, 24 Apr 2024 00:27:52 +0200 Subject: [PATCH 5/5] :white_check_mark: fix test assertion Signed-off-by: ff137 --- aries_cloudagent/core/tests/test_oob_processor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aries_cloudagent/core/tests/test_oob_processor.py b/aries_cloudagent/core/tests/test_oob_processor.py index eb805eda64..c7e42e2b81 100644 --- a/aries_cloudagent/core/tests/test_oob_processor.py +++ b/aries_cloudagent/core/tests/test_oob_processor.py @@ -728,7 +728,7 @@ async def test_handle_message_connectionless(self): ) assert oob_record.attach_thread_id == "4a580490-a9d8-44f5-a3f6-14e0b8a219b0" - assert oob_record.their_service == { + assert oob_record.their_service.serialize() == { "serviceEndpoint": "http://their-service-endpoint.com", "recipientKeys": ["9WCgWKUaAJj3VWxxtzvvMQN3AoFxoBtBDo9ntwJnVVCC"], "routingKeys": ["6QSduYdf8Bi6t8PfNm5vNomGWDtXhmMmTRzaciudBXYJ"],