예제 #1
0
    def setUp(self):
        d = dict(
            MONGO={
                "enabled": "False",
                "URI": "mongodb://localhost"
            },
            LOCALLOG={
                "enabled": "False",
                "PATH": "/tmp/tanner_report.json"
            },
        )
        m = mock.MagicMock()
        m.__getitem__.side_effect = d.__getitem__
        m.__iter__.side_effect = d.__iter__

        with mock.patch("tanner.tests.test_server.TannerConfig") as p:

            TannerConfig.config = m
            TannerConfig.get = m.get

        with mock.patch("tanner.dorks_manager.DorksManager", mock.Mock()):
            with mock.patch("tanner.emulators.base.BaseHandler",
                            mock.Mock(),
                            create=True):
                with mock.patch(
                        "tanner.sessions.session_manager.SessionManager",
                        mock.Mock(),
                        create=True):
                    self.serv = server.TannerServer()

        self.test_uuid = uuid.uuid4()

        async def _add_or_update_mock(data, client):
            sess = mock.Mock()
            sess.set_attack_type = mock.Mock()
            sess_id = hashlib.md5(b"foo")
            test_uuid = uuid
            sess.get_uuid = mock.Mock(return_value=str(self.test_uuid))
            return sess, sess_id

        async def _delete_sessions_mock(client):
            pass

        self.serv.session_manager.add_or_update_session = _add_or_update_mock
        self.serv.session_manager.delete_sessions_on_shutdown = _delete_sessions_mock

        async def choosed(client):
            return [x for x in range(10)]

        dorks = mock.Mock()
        dorks.choose_dorks = choosed
        dorks.extract_path = self._make_coroutine()

        redis = AsyncMock()
        redis.close = mock.Mock()
        redis.wait_closed = AsyncMock()
        self.serv.dorks = dorks
        self.serv.redis_client = redis

        super(TestServer, self).setUp()
예제 #2
0
    def setUp(self):
        d = dict(MONGO={
            'enabled': 'False',
            'URI': 'mongodb://localhost'
        },
                 LOCALLOG={
                     'enabled': 'False',
                     'PATH': '/tmp/tanner_report.json'
                 })
        m = mock.MagicMock()
        m.__getitem__.side_effect = d.__getitem__
        m.__iter__.side_effect = d.__iter__
        TannerConfig.config = m
        TannerConfig.get = m.get

        with mock.patch('tanner.dorks_manager.DorksManager', mock.Mock()):
            with mock.patch('tanner.emulators.base.BaseHandler',
                            mock.Mock(),
                            create=True):
                with mock.patch('tanner.session_manager.SessionManager',
                                mock.Mock(),
                                create=True):
                    self.serv = server.TannerServer()

        self.test_uuid = uuid.uuid4()

        async def _add_or_update_mock(data, client):
            sess = mock.Mock()
            sess.set_attack_type = mock.Mock()
            test_uuid = uuid
            sess.get_uuid = mock.Mock(return_value=str(self.test_uuid))
            return sess

        async def _delete_sessions_mock(client):
            pass

        self.serv.session_manager.add_or_update_session = _add_or_update_mock
        self.serv.session_manager.delete_sessions_on_shutdown = _delete_sessions_mock

        async def choosed(client):
            return [x for x in range(10)]

        dorks = mock.Mock()
        dorks.choose_dorks = choosed
        dorks.extract_path = self._make_coroutine()

        redis = mock.Mock()
        redis.close = mock.Mock()
        self.serv.dorks = dorks
        self.serv.redis_client = redis

        super(TestServer, self).setUp()