3434from ....discovery .v2_0 .manager import V20DiscoveryMgr
3535
3636from ..manager import ConnectionManager , ConnectionManagerError
37+ from .. import manager as test_module
3738from ..messages .connection_invitation import ConnectionInvitation
3839from ..messages .connection_request import ConnectionRequest
3940from ..messages .connection_response import ConnectionResponse
@@ -111,21 +112,6 @@ async def setUp(self):
111112 self .manager = ConnectionManager (self .profile )
112113 assert self .manager .profile
113114
114- async def test_create_invitation_public_and_multi_use_fails (self ):
115- self .context .update_settings ({"public_invites" : True })
116- with async_mock .patch .object (
117- InMemoryWallet , "get_public_did" , autospec = True
118- ) as mock_wallet_get_public_did :
119- mock_wallet_get_public_did .return_value = DIDInfo (
120- self .test_did ,
121- self .test_verkey ,
122- None ,
123- method = SOV ,
124- key_type = ED25519 ,
125- )
126- with self .assertRaises (ConnectionManagerError ):
127- await self .manager .create_invitation (public = True , multi_use = True )
128-
129115 async def test_create_invitation_non_multi_use_invitation_fails_on_reuse (self ):
130116 connect_record , connect_invite = await self .manager .create_invitation ()
131117
@@ -173,7 +159,7 @@ async def test_create_invitation_public(self):
173159 public = True , my_endpoint = "testendpoint"
174160 )
175161
176- assert connect_record is None
162+ assert connect_record
177163 assert connect_invite .did .endswith (self .test_did )
178164 self .route_manager .route_public_did .assert_called_once_with (
179165 self .profile , self .test_verkey
@@ -265,23 +251,6 @@ async def test_create_invitation_metadata_assigned(self):
265251
266252 assert await record .metadata_get_all (session ) == {"hello" : "world" }
267253
268- async def test_create_invitation_public_and_metadata_fails (self ):
269- self .context .update_settings ({"public_invites" : True })
270- with async_mock .patch .object (
271- InMemoryWallet , "get_public_did" , autospec = True
272- ) as mock_wallet_get_public_did :
273- mock_wallet_get_public_did .return_value = DIDInfo (
274- self .test_did ,
275- self .test_verkey ,
276- None ,
277- method = SOV ,
278- key_type = ED25519 ,
279- )
280- with self .assertRaises (ConnectionManagerError ):
281- await self .manager .create_invitation (
282- public = True , metadata = {"hello" : "world" }
283- )
284-
285254 async def test_create_invitation_multi_use_metadata_transfers_to_connection (self ):
286255 async with self .profile .session () as session :
287256 connect_record , _ = await self .manager .create_invitation (
@@ -642,7 +611,83 @@ async def test_receive_request_public_did_oob_invite(self):
642611 self .profile , mock_request
643612 )
644613
614+ async def test_receive_request_public_did_unsolicited_fails (self ):
615+ async with self .profile .session () as session :
616+ mock_request = async_mock .MagicMock ()
617+ mock_request .connection = async_mock .MagicMock ()
618+ mock_request .connection .did = self .test_did
619+ mock_request .connection .did_doc = async_mock .MagicMock ()
620+ mock_request .connection .did_doc .did = self .test_did
621+
622+ receipt = MessageReceipt (
623+ recipient_did = self .test_did , recipient_did_public = True
624+ )
625+ await session .wallet .create_local_did (
626+ method = SOV ,
627+ key_type = ED25519 ,
628+ seed = None ,
629+ did = self .test_did ,
630+ )
631+
632+ self .context .update_settings ({"public_invites" : True })
633+ with self .assertRaises (ConnectionManagerError ), async_mock .patch .object (
634+ ConnRecord , "connection_id" , autospec = True
635+ ), async_mock .patch .object (
636+ ConnRecord , "save" , autospec = True
637+ ) as mock_conn_rec_save , async_mock .patch .object (
638+ ConnRecord , "attach_request" , autospec = True
639+ ) as mock_conn_attach_request , async_mock .patch .object (
640+ ConnRecord , "retrieve_by_id" , autospec = True
641+ ) as mock_conn_retrieve_by_id , async_mock .patch .object (
642+ ConnRecord , "retrieve_request" , autospec = True
643+ ), async_mock .patch .object (
644+ ConnRecord , "retrieve_by_invitation_msg_id" , async_mock .CoroutineMock ()
645+ ) as mock_conn_retrieve_by_invitation_msg_id :
646+ mock_conn_retrieve_by_invitation_msg_id .return_value = None
647+ conn_rec = await self .manager .receive_request (mock_request , receipt )
648+
645649 async def test_receive_request_public_did_conn_invite (self ):
650+ async with self .profile .session () as session :
651+ mock_request = async_mock .MagicMock ()
652+ mock_request .connection = async_mock .MagicMock ()
653+ mock_request .connection .did = self .test_did
654+ mock_request .connection .did_doc = async_mock .MagicMock ()
655+ mock_request .connection .did_doc .did = self .test_did
656+
657+ receipt = MessageReceipt (
658+ recipient_did = self .test_did , recipient_did_public = True
659+ )
660+ await session .wallet .create_local_did (
661+ method = SOV ,
662+ key_type = ED25519 ,
663+ seed = None ,
664+ did = self .test_did ,
665+ )
666+
667+ mock_connection_record = async_mock .MagicMock ()
668+ mock_connection_record .save = async_mock .CoroutineMock ()
669+ mock_connection_record .attach_request = async_mock .CoroutineMock ()
670+
671+ self .context .update_settings ({"public_invites" : True })
672+ with async_mock .patch .object (
673+ ConnRecord , "connection_id" , autospec = True
674+ ), async_mock .patch .object (
675+ ConnRecord , "save" , autospec = True
676+ ) as mock_conn_rec_save , async_mock .patch .object (
677+ ConnRecord , "attach_request" , autospec = True
678+ ) as mock_conn_attach_request , async_mock .patch .object (
679+ ConnRecord , "retrieve_by_id" , autospec = True
680+ ) as mock_conn_retrieve_by_id , async_mock .patch .object (
681+ ConnRecord , "retrieve_request" , autospec = True
682+ ), async_mock .patch .object (
683+ ConnRecord ,
684+ "retrieve_by_invitation_msg_id" ,
685+ async_mock .CoroutineMock (return_value = mock_connection_record ),
686+ ) as mock_conn_retrieve_by_invitation_msg_id :
687+ conn_rec = await self .manager .receive_request (mock_request , receipt )
688+ assert conn_rec
689+
690+ async def test_receive_request_public_did_unsolicited (self ):
646691 async with self .profile .session () as session :
647692 mock_request = async_mock .MagicMock ()
648693 mock_request .connection = async_mock .MagicMock ()
@@ -661,6 +706,7 @@ async def test_receive_request_public_did_conn_invite(self):
661706 )
662707
663708 self .context .update_settings ({"public_invites" : True })
709+ self .context .update_settings ({"requests_through_public_did" : True })
664710 with async_mock .patch .object (
665711 ConnRecord , "connection_id" , autospec = True
666712 ), async_mock .patch .object (
0 commit comments