3535from ....discovery .v2_0 .manager import V20DiscoveryMgr
3636
3737from ..manager import ConnectionManager , ConnectionManagerError
38+ from .. import manager as test_module
3839from ..messages .connection_invitation import ConnectionInvitation
3940from ..messages .connection_request import ConnectionRequest
4041from ..messages .connection_response import ConnectionResponse
@@ -112,21 +113,6 @@ async def setUp(self):
112113 self .manager = ConnectionManager (self .profile )
113114 assert self .manager .profile
114115
115- async def test_create_invitation_public_and_multi_use_fails (self ):
116- self .context .update_settings ({"public_invites" : True })
117- with async_mock .patch .object (
118- InMemoryWallet , "get_public_did" , autospec = True
119- ) as mock_wallet_get_public_did :
120- mock_wallet_get_public_did .return_value = DIDInfo (
121- self .test_did ,
122- self .test_verkey ,
123- None ,
124- method = DIDMethod .SOV ,
125- key_type = KeyType .ED25519 ,
126- )
127- with self .assertRaises (ConnectionManagerError ):
128- await self .manager .create_invitation (public = True , multi_use = True )
129-
130116 async def test_create_invitation_non_multi_use_invitation_fails_on_reuse (self ):
131117 connect_record , connect_invite = await self .manager .create_invitation ()
132118
@@ -174,7 +160,7 @@ async def test_create_invitation_public(self):
174160 public = True , my_endpoint = "testendpoint"
175161 )
176162
177- assert connect_record is None
163+ assert connect_record
178164 assert connect_invite .did .endswith (self .test_did )
179165 self .route_manager .route_public_did .assert_called_once_with (
180166 self .profile , self .test_verkey
@@ -266,23 +252,6 @@ async def test_create_invitation_metadata_assigned(self):
266252
267253 assert await record .metadata_get_all (session ) == {"hello" : "world" }
268254
269- async def test_create_invitation_public_and_metadata_fails (self ):
270- self .context .update_settings ({"public_invites" : True })
271- with async_mock .patch .object (
272- InMemoryWallet , "get_public_did" , autospec = True
273- ) as mock_wallet_get_public_did :
274- mock_wallet_get_public_did .return_value = DIDInfo (
275- self .test_did ,
276- self .test_verkey ,
277- None ,
278- method = DIDMethod .SOV ,
279- key_type = KeyType .ED25519 ,
280- )
281- with self .assertRaises (ConnectionManagerError ):
282- await self .manager .create_invitation (
283- public = True , metadata = {"hello" : "world" }
284- )
285-
286255 async def test_create_invitation_multi_use_metadata_transfers_to_connection (self ):
287256 async with self .profile .session () as session :
288257 connect_record , _ = await self .manager .create_invitation (
@@ -643,7 +612,84 @@ async def test_receive_request_public_did_oob_invite(self):
643612 self .profile , mock_request
644613 )
645614
615+ async def test_receive_request_public_did_unsolicited_fails (self ):
616+ async with self .profile .session () as session :
617+ mock_request = async_mock .MagicMock ()
618+ mock_request .connection = async_mock .MagicMock ()
619+ mock_request .connection .did = self .test_did
620+ mock_request .connection .did_doc = async_mock .MagicMock ()
621+ mock_request .connection .did_doc .did = self .test_did
622+
623+ receipt = MessageReceipt (
624+ recipient_did = self .test_did , recipient_did_public = True
625+ )
626+ await session .wallet .create_local_did (
627+ method = DIDMethod .SOV ,
628+ key_type = KeyType .ED25519 ,
629+ seed = None ,
630+ did = self .test_did ,
631+ )
632+
633+ self .context .update_settings ({"public_invites" : True })
634+ with self .assertRaises (
635+ ConnectionManagerError
636+ ), async_mock .patch .object (
637+ ConnRecord , "connection_id" , autospec = True
638+ ), async_mock .patch .object (
639+ ConnRecord , "save" , autospec = True
640+ ) as mock_conn_rec_save , async_mock .patch .object (
641+ ConnRecord , "attach_request" , autospec = True
642+ ) as mock_conn_attach_request , async_mock .patch .object (
643+ ConnRecord , "retrieve_by_id" , autospec = True
644+ ) as mock_conn_retrieve_by_id , async_mock .patch .object (
645+ ConnRecord , "retrieve_request" , autospec = True
646+ ), async_mock .patch .object (
647+ ConnRecord , "retrieve_by_invitation_msg_id" , async_mock .CoroutineMock ()
648+ ) as mock_conn_retrieve_by_invitation_msg_id :
649+ mock_conn_retrieve_by_invitation_msg_id .return_value = None
650+ conn_rec = await self .manager .receive_request (mock_request , receipt )
651+
646652 async def test_receive_request_public_did_conn_invite (self ):
653+ async with self .profile .session () as session :
654+ mock_request = async_mock .MagicMock ()
655+ mock_request .connection = async_mock .MagicMock ()
656+ mock_request .connection .did = self .test_did
657+ mock_request .connection .did_doc = async_mock .MagicMock ()
658+ mock_request .connection .did_doc .did = self .test_did
659+
660+ receipt = MessageReceipt (
661+ recipient_did = self .test_did , recipient_did_public = True
662+ )
663+ await session .wallet .create_local_did (
664+ method = DIDMethod .SOV ,
665+ key_type = KeyType .ED25519 ,
666+ seed = None ,
667+ did = self .test_did ,
668+ )
669+
670+ mock_connection_record = async_mock .MagicMock ()
671+ mock_connection_record .save = async_mock .CoroutineMock ()
672+ mock_connection_record .attach_request = async_mock .CoroutineMock ()
673+
674+
675+ self .context .update_settings ({"public_invites" : True })
676+ with async_mock .patch .object (
677+ ConnRecord , "connection_id" , autospec = True
678+ ), async_mock .patch .object (
679+ ConnRecord , "save" , autospec = True
680+ ) as mock_conn_rec_save , async_mock .patch .object (
681+ ConnRecord , "attach_request" , autospec = True
682+ ) as mock_conn_attach_request , async_mock .patch .object (
683+ ConnRecord , "retrieve_by_id" , autospec = True
684+ ) as mock_conn_retrieve_by_id , async_mock .patch .object (
685+ ConnRecord , "retrieve_request" , autospec = True
686+ ), async_mock .patch .object (
687+ ConnRecord , "retrieve_by_invitation_msg_id" , async_mock .CoroutineMock (return_value = mock_connection_record )
688+ ) as mock_conn_retrieve_by_invitation_msg_id :
689+ conn_rec = await self .manager .receive_request (mock_request , receipt )
690+ assert conn_rec
691+
692+ async def test_receive_request_public_did_unsolicited (self ):
647693 async with self .profile .session () as session :
648694 mock_request = async_mock .MagicMock ()
649695 mock_request .connection = async_mock .MagicMock ()
@@ -662,6 +708,7 @@ async def test_receive_request_public_did_conn_invite(self):
662708 )
663709
664710 self .context .update_settings ({"public_invites" : True })
711+ self .context .update_settings ({"requests_through_public_did" : True })
665712 with async_mock .patch .object (
666713 ConnRecord , "connection_id" , autospec = True
667714 ), async_mock .patch .object (
0 commit comments