async def test_startup(self):
        conductor = Conductor(
            self.good_inbound_transports,
            self.good_outbound_transports,
            ProtocolRegistry(),
            self.test_settings,
        )
        mock_inbound_mgr = async_mock.create_autospec(
            conductor.inbound_transport_manager)
        conductor.inbound_transport_manager = mock_inbound_mgr
        mock_outbound_mgr = async_mock.create_autospec(
            conductor.outbound_transport_manager)
        conductor.outbound_transport_manager = mock_outbound_mgr

        await conductor.start()

        mock_inbound_mgr.register.assert_called_once_with(
            self.good_inbound_transports[0].module,
            self.good_inbound_transports[0].host,
            self.good_inbound_transports[0].port,
            conductor.inbound_message_router,
            conductor.register_socket,
        )

        mock_inbound_mgr.start_all.assert_called_once_with()

        mock_outbound_mgr.register.assert_called_once_with(
            self.good_outbound_transports[0])

        mock_outbound_mgr.start_all.assert_called_once_with()
Exemple #2
0
    def setUp(self):
        self.context = InjectionContext(enforce_typing=False)

        self.ledger = async_mock.create_autospec(BaseLedger)
        self.ledger.__aenter__ = async_mock.CoroutineMock(
            return_value=self.ledger)
        self.ledger.create_and_send_credential_definition = async_mock.CoroutineMock(
            return_value=(CRED_DEF_ID, {
                "cred": "def"
            }))
        self.ledger.get_credential_definition = async_mock.CoroutineMock(
            return_value={"cred": "def"})
        self.context.injector.bind_instance(BaseLedger, self.ledger)

        self.issuer = async_mock.create_autospec(BaseIssuer)
        self.context.injector.bind_instance(BaseIssuer, self.issuer)

        self.storage = async_mock.create_autospec(BaseStorage)
        self.storage.search_records = async_mock.MagicMock(
            return_value=async_mock.MagicMock(
                fetch_all=async_mock.CoroutineMock(
                    return_value=[async_mock.MagicMock(value=CRED_DEF_ID)])))
        self.context.injector.bind_instance(BaseStorage, self.storage)

        self.app = {
            "request_context": self.context,
        }
Exemple #3
0
    def setUp(self):
        self.session_inject = {}
        self.context = AdminRequestContext.test_context(self.session_inject)
        self.request_dict = {"context": self.context}
        self.request = async_mock.MagicMock(
            app={"outbound_message_router": async_mock.CoroutineMock()},
            match_info={},
            query={},
            __getitem__=lambda _, k: self.request_dict[k],
        )

        self.ledger = async_mock.create_autospec(BaseLedger)
        self.ledger.__aenter__ = async_mock.CoroutineMock(
            return_value=self.ledger)
        self.ledger.create_and_send_credential_definition = async_mock.CoroutineMock(
            return_value=(CRED_DEF_ID, {
                "cred": "def"
            }, True))
        self.ledger.get_credential_definition = async_mock.CoroutineMock(
            return_value={"cred": "def"})
        self.session_inject[BaseLedger] = self.ledger

        self.issuer = async_mock.create_autospec(IndyIssuer)
        self.session_inject[IndyIssuer] = self.issuer

        self.storage = async_mock.create_autospec(BaseStorage)
        self.storage.search_records = async_mock.MagicMock(
            return_value=async_mock.MagicMock(
                fetch_all=async_mock.CoroutineMock(
                    return_value=[async_mock.MagicMock(value=CRED_DEF_ID)])))
        self.session_inject[BaseStorage] = self.storage
    async def test_outbound_message_handler(self):
        conductor = Conductor(
            self.good_inbound_transports,
            self.good_outbound_transports,
            ProtocolRegistry(),
            self.test_settings,
        )
        mock_serializer = async_mock.create_autospec(
            conductor.message_serializer)
        conductor.message_serializer = mock_serializer
        mock_outbound_mgr = async_mock.create_autospec(
            conductor.outbound_transport_manager)
        conductor.outbound_transport_manager = mock_outbound_mgr

        payload = "{}"
        target = ConnectionTarget(endpoint="endpoint",
                                  recipient_keys=(),
                                  routing_keys=(),
                                  sender_key="")
        message = OutboundMessage(payload=payload, target=target)

        await conductor.outbound_message_router(message)

        mock_serializer.encode_message.assert_called_once_with(
            conductor.context,
            payload,
            target.recipient_keys,
            target.routing_keys,
            target.sender_key,
        )

        mock_outbound_mgr.send_message.assert_called_once_with(message)
    async def test_inbound_message_handler(self):
        conductor = Conductor(
            self.good_inbound_transports,
            self.good_outbound_transports,
            ProtocolRegistry(),
            self.test_settings,
        )
        mock_dispatcher = async_mock.create_autospec(conductor.dispatcher)
        conductor.dispatcher = mock_dispatcher
        mock_serializer = async_mock.create_autospec(
            conductor.message_serializer)
        conductor.message_serializer = mock_serializer

        delivery = MessageDelivery()
        parsed_msg = {}
        mock_serializer.parse_message.return_value = (parsed_msg, delivery)

        message_body = "{}"
        transport = "http"
        await conductor.inbound_message_router(message_body, transport)

        mock_serializer.parse_message.assert_called_once_with(
            conductor.context, message_body, transport)

        mock_dispatcher.dispatch.assert_called_once_with(
            parsed_msg, delivery, None, conductor.outbound_message_router)
    def setUp(self):
        self.session_inject = {}
        self.context = AdminRequestContext.test_context(self.session_inject)
        self.request_dict = {
            "context": self.context,
            "outbound_message_router": async_mock.CoroutineMock(),
        }
        self.request = async_mock.MagicMock(
            app={},
            match_info={},
            query={},
            __getitem__=lambda _, k: self.request_dict[k],
        )

        self.ledger = async_mock.create_autospec(BaseLedger)
        self.ledger.__aenter__ = async_mock.CoroutineMock(
            return_value=self.ledger)
        self.ledger.create_and_send_schema = async_mock.CoroutineMock(
            return_value=(SCHEMA_ID, {
                "schema": "def",
                "signed_txn": "..."
            }))
        self.ledger.get_schema = async_mock.CoroutineMock(return_value={
            "schema": "def",
            "signed_txn": "..."
        })
        self.context.injector.bind_instance(BaseLedger, self.ledger)

        self.issuer = async_mock.create_autospec(IndyIssuer)
        self.context.injector.bind_instance(IndyIssuer, self.issuer)

        self.storage = async_mock.create_autospec(BaseStorage)
        self.storage.find_all_records = async_mock.CoroutineMock(
            return_value=[async_mock.MagicMock(value=SCHEMA_ID)])
        self.session_inject[BaseStorage] = self.storage
    def setUp(self):
        self.context = InjectionContext(enforce_typing=False)

        self.wallet = async_mock.create_autospec(BaseWallet)
        self.context.injector.bind_instance(BaseWallet, self.wallet)

        self.holder = async_mock.create_autospec(BaseHolder)
        self.app = {
            "request_context": self.context,
        }
    async def test_credentials_x_ledger(self):
        self.request.match_info = {"credential_id": "dummy"}
        ledger = async_mock.create_autospec(BaseLedger)
        self.session_inject[BaseLedger] = async_mock.create_autospec(
            BaseLedger)
        self.session_inject[IndyHolder] = async_mock.MagicMock(
            credential_revoked=async_mock.CoroutineMock(
                side_effect=test_module.LedgerError("down for maintenance")))

        with self.assertRaises(test_module.web.HTTPBadRequest):
            await test_module.credentials_revoked(self.request)
Exemple #9
0
    async def test_process_incoming_payload(self):
        extension = mock.create_autospec(spec=Extension)
        auth = mock.create_autospec(spec=AuthExtension)
        self.transport._extensions = [extension]
        self.transport._auth = auth
        payload = object()
        headers = object()

        await self.transport._process_incoming_payload(payload, headers)

        extension.incoming.assert_called_with(payload, headers)
        auth.incoming.assert_called_with(payload, headers)
Exemple #10
0
    def setUp(self):
        self.responder = MockResponder()
        self.responder.send = async_mock.CoroutineMock()

        self.session = InMemoryProfile.test_session(
            {
                "default_endpoint": TestConfig.test_endpoint,
                "default_label": "This guy",
                "additional_endpoints": ["http://aries.ca/another-endpoint"],
                "debug.auto_accept_invites": True,
                "debug.auto_accept_requests": True,
            }
        )
        self.session.context.injector.bind_instance(BaseResponder, self.responder)

        self.ledger = async_mock.create_autospec(BaseLedger)
        self.ledger.__aenter__ = async_mock.CoroutineMock(return_value=self.ledger)
        self.session.context.injector.bind_instance(BaseLedger, self.ledger)

        self.manager = OutOfBandManager(self.session)
        self.test_conn_rec = ConnRecord(
            my_did=TestConfig.test_did,
            their_did=TestConfig.test_target_did,
            their_role=None,
            state=ConnRecord.State.COMPLETED.rfc23,
        )
    def setUp(self):
        self.storage = BasicStorage()
        self.cache = BasicCache()
        self.wallet = BasicWallet()
        self.responder = MockResponder()
        self.responder.send = async_mock.CoroutineMock()

        self.context = InjectionContext(enforce_typing=False)
        self.context.injector.bind_instance(BaseStorage, self.storage)
        self.context.injector.bind_instance(BaseWallet, self.wallet)
        self.context.injector.bind_instance(BaseResponder, self.responder)
        self.context.injector.bind_instance(BaseCache, self.cache)
        self.ledger = async_mock.create_autospec(BaseLedger)
        self.ledger.__aenter__ = async_mock.CoroutineMock(
            return_value=self.ledger)
        self.context.injector.bind_instance(BaseLedger, self.ledger)
        self.context.update_settings({
            "default_endpoint":
            TestConfig.test_endpoint,
            "default_label":
            "This guy",
            "additional_endpoints": ["http://aries.ca/another-endpoint"],
            "debug.auto_accept_invites":
            True,
            "debug.auto_accept_requests":
            True,
        })

        self.manager = OutOfBandManager(self.context)
        self.test_conn_rec = ConnectionRecord(
            my_did=TestConfig.test_did,
            their_did=TestConfig.test_target_did,
            their_role=None,
            state=ConnectionRecord.STATE_ACTIVE,
        )
Exemple #12
0
 def __init__(self, c):
     mock_func = create_autospec(c.func, spec_set=True)
     mock_func.__module__ = c.func.__module__
     mock_func.__dict__.update(copy.deepcopy(c.func.__dict__))
     self.__dict__['contracted'] = Contracted(c.hub, c._mod, c.contracts,
                                              mock_func)
     self.signature = c.signature
    def setUp(self):
        self.session_inject = {}
        self.profile = InMemoryProfile.test_profile()
        self.profile_injector = self.profile.context.injector

        self.ledger = async_mock.create_autospec(BaseLedger)
        self.ledger.__aenter__ = async_mock.CoroutineMock(
            return_value=self.ledger)
        self.ledger.create_and_send_credential_definition = async_mock.CoroutineMock(
            return_value=(
                CRED_DEF_ID,
                {
                    "cred": "def",
                    "signed_txn": "..."
                },
                True,
            ))
        self.ledger.get_credential_definition = async_mock.CoroutineMock(
            return_value={
                "cred": "def",
                "signed_txn": "..."
            })
        self.profile_injector.bind_instance(BaseLedger, self.ledger)

        self.issuer = async_mock.create_autospec(IndyIssuer)
        self.profile_injector.bind_instance(IndyIssuer, self.issuer)

        self.storage = async_mock.create_autospec(BaseStorage)
        self.storage.find_all_records = async_mock.CoroutineMock(
            return_value=[async_mock.MagicMock(value=CRED_DEF_ID)])
        self.session_inject[BaseStorage] = self.storage

        self.context = AdminRequestContext.test_context(self.session_inject,
                                                        profile=self.profile)
        self.request_dict = {
            "context": self.context,
            "outbound_message_router": async_mock.CoroutineMock(),
        }
        self.request = async_mock.MagicMock(
            app={},
            match_info={},
            query={},
            __getitem__=lambda _, k: self.request_dict[k],
        )
    async def test_credentials_not_found(self):
        self.request.match_info = {"credential_id": "dummy"}
        self.session_inject[BaseLedger] = async_mock.create_autospec(
            BaseLedger)
        self.session_inject[IndyHolder] = async_mock.MagicMock(
            credential_revoked=async_mock.CoroutineMock(
                side_effect=test_module.WalletNotFoundError("no such cred")))

        with self.assertRaises(test_module.web.HTTPNotFound):
            await test_module.credentials_revoked(self.request)
Exemple #15
0
    async def test_process_outgoing_payload_without_auth(self):
        extension = mock.create_autospec(spec=Extension)
        self.transport._extensions = [extension]
        self.transport._auth = None
        payload = object()
        headers = object()

        await self.transport._process_outgoing_payload(payload, headers)

        extension.outgoing.assert_called_with(payload, headers)
Exemple #16
0
 def setUp(self):
     self.context = InjectionContext(enforce_typing=False)
     self.wallet = async_mock.create_autospec(BaseWallet)
     self.context.injector.bind_instance(BaseWallet, self.wallet)
     self.app = {
         "outbound_message_router": async_mock.CoroutineMock(),
         "request_context": self.context,
     }
     self.test_did = "did"
     self.test_verkey = "verkey"
Exemple #17
0
 async def setUp(self):
     self.context = InjectionContext(enforce_typing=False)
     self.storage = async_mock.create_autospec(BaseStorage)
     self.context.injector.bind_instance(BaseStorage, self.storage)
     self.wallet = self.wallet = BasicWallet()
     self.did_info = await self.wallet.create_local_did()
     self.context.injector.bind_instance(BaseWallet, self.wallet)
     self.app = {
         "request_context": self.context,
     }
 def setUp(self):
     self.context = InjectionContext(enforce_typing=False)
     self.ledger = async_mock.create_autospec(BaseLedger)
     self.context.injector.bind_instance(BaseLedger, self.ledger)
     self.app = {
         "outbound_message_router": async_mock.CoroutineMock(),
         "request_context": self.context,
     }
     self.test_did = "did"
     self.test_verkey = "verkey"
     self.test_endpoint = "http://localhost:8021"
    async def test_credentials_revoked(self):
        self.request.match_info = {"credential_id": "dummy"}
        self.session_inject[BaseLedger] = async_mock.create_autospec(
            BaseLedger)
        self.session_inject[IndyHolder] = async_mock.MagicMock(
            credential_revoked=async_mock.CoroutineMock(return_value=False))

        with async_mock.patch.object(test_module.web, "json_response",
                                     async_mock.Mock()) as json_response:
            result = await test_module.credentials_revoked(self.request)
            json_response.assert_called_once_with({"revoked": False})
            assert result is json_response.return_value
Exemple #20
0
    def test_init_creates_replay_storage(self, create_replay_storage):
        replay_param = object()
        create_replay_storage.return_value = mock.create_autospec(
            ReplayMarkerStorage)()

        client = Client(self.authenticator, replay=replay_param)

        self.assertEqual(client.auth, self.authenticator)
        self.assertEqual(client.extensions,
                         [create_replay_storage.return_value])
        self.assertEqual(client.replay_storage,
                         create_replay_storage.return_value)
        self.assertIsNone(client.replay_fallback)
        create_replay_storage.assert_called_with(replay_param)
Exemple #21
0
    async def test_send_payload_with_auth_with_extension(
            self, is_auth_error_message):
        response = object()
        payload = object()
        self.transport._send_payload = mock.CoroutineMock(
            return_value=response)
        self.transport._auth = mock.create_autospec(spec=AuthExtension)
        is_auth_error_message.return_value = False

        result = await self.transport._send_payload_with_auth(payload)

        self.assertIs(result, response)
        self.transport._send_payload.assert_called_with(payload)
        is_auth_error_message.assert_called_with(response)
        self.transport._auth.authenticate.assert_not_called()
    async def test_credentials_not_found(self):
        request = async_mock.MagicMock(app=self.app,
                                       match_info={"credential_id": "dummy"})
        ledger = async_mock.create_autospec(BaseLedger)

        request.app["request_context"].inject = async_mock.CoroutineMock(
            side_effect=[
                ledger,
                async_mock.MagicMock(
                    credential_revoked=async_mock.CoroutineMock(
                        side_effect=test_module.WalletNotFoundError(
                            "no such cred"))),
            ])

        with self.assertRaises(test_module.web.HTTPNotFound):
            await test_module.credentials_revoked(request)
    def setUp(self):
        self.wallet = async_mock.create_autospec(BaseWallet)
        self.session_inject = {BaseWallet: self.wallet}
        self.context = AdminRequestContext.test_context(self.session_inject)
        self.request_dict = {"context": self.context}
        self.request = async_mock.MagicMock(
            app={"outbound_message_router": async_mock.CoroutineMock()},
            match_info={},
            query={},
            __getitem__=lambda _, k: self.request_dict[k],
        )

        self.test_did = "did"
        self.test_verkey = "verkey"
        self.test_posted_did = "posted-did"
        self.test_posted_verkey = "posted-verkey"
    async def test_credentials_x_ledger(self):
        request = async_mock.MagicMock(app=self.app,
                                       match_info={"credential_id": "dummy"})
        ledger = async_mock.create_autospec(BaseLedger)

        request.app["request_context"].inject = async_mock.CoroutineMock(
            side_effect=[
                ledger,
                async_mock.MagicMock(
                    credential_revoked=async_mock.CoroutineMock(
                        side_effect=test_module.LedgerError(
                            "down for maintenance"))),
            ])

        with self.assertRaises(test_module.web.HTTPBadRequest):
            await test_module.credentials_revoked(request)
Exemple #25
0
    async def test_send_payload_with_auth_with_extension_error(
            self, is_auth_error_message):
        response = object()
        response2 = object()
        payload = object()
        self.transport._send_payload = mock.CoroutineMock(
            side_effect=[response, response2])
        self.transport._auth = mock.create_autospec(spec=AuthExtension)
        is_auth_error_message.return_value = True

        result = await self.transport._send_payload_with_auth(payload)

        self.assertIs(result, response2)
        self.transport._send_payload.assert_has_calls(
            [mock.call(payload), mock.call(payload)])
        is_auth_error_message.assert_called_with(response)
        self.transport._auth.authenticate.assert_called()
Exemple #26
0
    def setUp(self):
        self.ledger = async_mock.create_autospec(BaseLedger)
        self.ledger.pool_name = "pool.0"
        self.session_inject = {BaseLedger: self.ledger}
        self.context = AdminRequestContext.test_context(self.session_inject)
        self.request_dict = {"context": self.context}
        self.request = async_mock.MagicMock(
            app={"outbound_message_router": async_mock.CoroutineMock()},
            match_info={},
            query={},
            __getitem__=lambda _, k: self.request_dict[k],
        )

        self.test_did = "did"
        self.test_verkey = "verkey"
        self.test_endpoint = "http://localhost:8021"
        self.test_endpoint_type = EndpointType.PROFILE
        self.test_endpoint_type_profile = "http://company.com/profile"
    async def test_credentials_revoked(self):
        request = async_mock.MagicMock(
            app=self.app, match_info={"credential_id": "dummy"}
        )
        ledger = async_mock.create_autospec(BaseLedger)

        request.app["request_context"].inject = async_mock.CoroutineMock(
            side_effect=[
                ledger,
                async_mock.MagicMock(
                    credential_revoked=async_mock.CoroutineMock(return_value=False)
                ),
            ]
        )

        with async_mock.patch.object(
            test_module.web, "json_response", async_mock.Mock()
        ) as json_response:
            result = await test_module.credentials_revoked(request)
            json_response.assert_called_once_with({"revoked": False})
            assert result is json_response.return_value
    def setUp(self):
        self.ledger = async_mock.create_autospec(BaseLedger)
        self.ledger.pool_name = "pool.0"
        self.profile = InMemoryProfile.test_profile()
        self.context = self.profile.context
        setattr(self.context, "profile", self.profile)
        self.profile.context.injector.bind_instance(BaseLedger, self.ledger)
        self.request_dict = {
            "context": self.context,
            "outbound_message_router": async_mock.CoroutineMock(),
        }
        self.request = async_mock.MagicMock(
            app={},
            match_info={},
            query={},
            __getitem__=lambda _, k: self.request_dict[k],
        )

        self.test_did = "did"
        self.test_verkey = "verkey"
        self.test_endpoint = "http://localhost:8021"
        self.test_endpoint_type = EndpointType.PROFILE
        self.test_endpoint_type_profile = "http://company.com/profile"
Exemple #29
0
 def _mock_function(self, f):
     return create_autospec(strip_hub(f.func), spec_set=True)
Exemple #30
0
 def _mock_attr(self, a):
     return create_autospec(a, spec_set=True)