async def test_create_invitation_handshake_succeeds(self):
        self.manager.context.update_settings({"public_invites": True})
        with async_mock.patch.object(
                BaseWallet, "get_public_did",
                autospec=True) as mock_wallet_get_public_did:
            mock_wallet_get_public_did.return_value = DIDInfo(
                self.test_did, self.test_verkey, None)
            inv_model = await self.manager.create_invitation(
                my_label="label",
                my_endpoint="endpoint",
                use_public_did=True,
                include_handshake=True,
                multi_use=False,
            )

            assert (inv_model.invitation["@type"] ==
                    "https://didcomm.org/out-of-band/1.0/invitation")
            assert not inv_model.invitation["request~attach"]
            assert inv_model.invitation["label"] == "label"
            assert inv_model.invitation["handshake_protocols"] == [
                "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/connections/1.0/invitation"
            ]
            assert inv_model.invitation["service"] == [
                f"did:sov:{TestConfig.test_did}"
            ]
    async def test_receive_invitation_service_block(self):
        self.manager.context.update_settings({"public_invites": True})
        with async_mock.patch.object(
                BaseWallet, "get_public_did", autospec=True
        ) as mock_wallet_get_public_did, async_mock.patch.object(
                ConnectionManager, "receive_invitation", autospec=True
        ) as conn_mgr_receive_invitation, async_mock.patch(
                "aries_cloudagent.protocols.out_of_band.v1_0.manager.InvitationMessage",
                autospec=True,
        ) as inv_message_cls, async_mock.patch(
                "aries_cloudagent.protocols.out_of_band.v1_0.manager.ConnectionInvitation",
                autospec=True,
        ) as conn_inv_cls:
            mock_wallet_get_public_did.return_value = DIDInfo(
                self.test_did, self.test_verkey, None)

            conn_inv_cls.deserialize.return_value = async_mock.MagicMock()

            conn_inv_mock = async_mock.MagicMock()
            inv_message_cls.deserialize.return_value = conn_inv_mock
            conn_inv_mock.service_blocks = [async_mock.MagicMock()]
            conn_inv_mock.handshake_protocols = [
                "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/connections/1.0/invitation"
            ]

            inv_model = await self.manager.receive_invitation(conn_inv_mock)
Ejemplo n.º 3
0
    async def test_create_invitation_attachment_present_proof(self):
        self.manager.context.update_settings({"public_invites": True})
        with async_mock.patch.object(
                BaseWallet, "get_public_did", autospec=True
        ) as mock_wallet_get_public_did, async_mock.patch.object(
                test_module.V10PresentationExchange,
                "retrieve_by_id",
                async_mock.CoroutineMock(),
        ) as mock_retrieve_pxid:
            mock_wallet_get_public_did.return_value = DIDInfo(
                TestConfig.test_did, TestConfig.test_verkey, None)
            mock_retrieve_pxid.return_value = async_mock.MagicMock(
                presentation_request_dict={"pres": "req"})
            inv_model = await self.manager.create_invitation(
                my_endpoint=TestConfig.test_endpoint,
                use_public_did=True,
                include_handshake=True,
                multi_use=False,
                attachments=[{
                    "type": "present-proof",
                    "id": "dummy-id"
                }],
            )

            assert inv_model.invitation["request~attach"]
            mock_retrieve_pxid.assert_called_once_with(self.manager.context,
                                                       "dummy-id")
Ejemplo n.º 4
0
 async def test_create_invitation_attachment_x(self):
     self.manager.context.update_settings({"public_invites": True})
     with async_mock.patch.object(
             BaseWallet, "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)
         with self.assertRaises(OutOfBandManagerError):
             await self.manager.create_invitation(
                 my_endpoint=TestConfig.test_endpoint,
                 use_public_did=True,
                 include_handshake=True,
                 multi_use=False,
                 attachments=[{
                     "having": "attachment",
                     "is": "no",
                     "good": "here"
                 }],
             )
    async def test_receive_invitation_bad_service_length(self):
        self.manager.context.update_settings({"public_invites": True})
        with async_mock.patch.object(
                BaseWallet, "get_public_did", autospec=True
        ) as mock_wallet_get_public_did, async_mock.patch.object(
                ConnectionManager, "create_invitation", autospec=True
        ) as conn_mgr_create_inv, async_mock.patch(
                "aries_cloudagent.protocols.out_of_band.v1_0.manager.InvitationMessage",
                autospec=True,
        ) as inv_message_cls:
            mock_wallet_get_public_did.return_value = DIDInfo(
                self.test_did, self.test_verkey, None)

            conn_inv_mock = async_mock.MagicMock()
            inv_message_cls.deserialize.return_value = conn_inv_mock
            conn_inv_mock.service_blocks = []

            with self.assertRaises(OutOfBandManagerError):
                inv_model = await self.manager.receive_invitation(conn_inv_mock
                                                                  )
Ejemplo n.º 6
0
    async def create_static_connection(
        self,
        my_did: str = None,
        my_seed: str = None,
        their_did: str = None,
        their_seed: str = None,
        their_verkey: str = None,
        their_endpoint: str = None,
        their_role: str = None,
        their_label: str = None,
        alias: str = None,
    ) -> (DIDInfo, DIDInfo, ConnectionRecord):
        """
        Register a new static connection (for use by the test suite).

        Args:
            my_did: override the DID used in the connection
            my_seed: provide a seed used to generate our DID and keys
            their_did: provide the DID used by the other party
            their_seed: provide a seed used to generate their DID and keys
            their_verkey: provide the verkey used by the other party
            their_endpoint: their URL endpoint for routing messages
            their_role: their role in this connection
            alias: an alias for this connection record

        Returns:
            The new `ConnectionRecord` instance

        """
        wallet: BaseWallet = await self.context.inject(BaseWallet)

        # seed and DID optional
        my_info = await wallet.create_local_did(my_seed, my_did)

        # must provide their DID and verkey if the seed is not known
        if (not their_did or not their_verkey) and not their_seed:
            raise ConnectionManagerError(
                "Either a verkey or seed must be provided for the other party")
        if not their_did:
            their_did = seed_to_did(their_seed)
        if not their_verkey:
            their_verkey_bin, _ = create_keypair(their_seed.encode())
            their_verkey = bytes_to_b58(their_verkey_bin)
        their_info = DIDInfo(their_did, their_verkey, {})

        # Create connection record
        connection = ConnectionRecord(
            initiator=ConnectionRecord.INITIATOR_SELF,
            invitation_mode=ConnectionRecord.INVITATION_MODE_STATIC,
            my_did=my_info.did,
            their_did=their_info.did,
            their_role=their_role,
            their_label=their_label,
            state=ConnectionRecord.STATE_ACTIVE,
            alias=alias,
        )
        await connection.save(self.context,
                              reason="Created new static connection")

        # Synthesize their DID doc
        did_doc = await self.create_did_document(their_info, None,
                                                 [their_endpoint])
        await self.store_did_document(did_doc)

        return my_info, their_info, connection