Exemplo n.º 1
0
    def test_bad_auth_client(self):
        """
        Tests a non-valid auth message for a client.
        """
        with QdbServer(
                client_host='localhost',
                client_port=0,
                client_auth_fn=lambda _: False,  # Fail all new clients.
                tracer_server=QdbNopServer()) as server:

            ws = create_connection('ws://localhost:%d%s' %
                                   (server.client_server.server_port,
                                    DEFAULT_ROUTE_FMT.format(uuid='test')))
            send_client_event(ws, 'start', 'friendzoned-again')

            auth_failed_event = disable_event = None

            with gevent.Timeout(2, False):
                # The server should time us out in 1 second and send back these
                # two messages.
                auth_failed_event = recv_client_event(ws)
                disable_event = recv_client_event(ws)

            auth_failed_dict = fmt_err_msg('auth', 'Authentication failed')

            self.assertEqual(auth_failed_event, auth_failed_dict)
            self.assertEqual(disable_event['e'], 'disable')
            self.assertFalse('test' in server.session_store)
Exemplo n.º 2
0
    def test_tracer_attach_timeout(self, mode):
        """
        Tests the case where a tracer attaches but no client does.
        """
        with QdbServer(tracer_host='localhost',
                       tracer_port=0,
                       client_server=QdbNopServer(),
                       attach_timeout=0.01,
                       timeout_disable_mode=mode) as server:

            tracer = gevent.socket.create_connection(
                ('localhost', server.tracer_server.server_port))
            send_tracer_event(tracer, 'start', {
                'uuid': 'test',
                'auth': '',
                'local': (0, 0),
            })
            disable_event = None
            with gevent.Timeout(0.1, False):
                error_event = recv_tracer_event(tracer)
                disable_event = recv_tracer_event(tracer)

            error_dict = fmt_err_msg('client', 'No client')

            self.assertEqual(error_dict, error_event)
            self.assertEqual(fmt_msg('disable', mode), disable_event)
            self.assertNotIn('test', server.session_store)
Exemplo n.º 3
0
    def test_client_auth_timeout(self):
        with QdbServer(
                client_host='localhost',
                client_port=0,
                auth_timeout=1,  # Timeout after 1 second.
                tracer_server=QdbNopServer()) as server:
            ws = create_connection('ws://localhost:%d%s' %
                                   (server.client_server.server_port,
                                    DEFAULT_ROUTE_FMT.format(uuid='test')))

            auth_failed_dict = fmt_err_msg('auth', 'No start event received')
            disable_dict = fmt_msg('disable')

            auth_failed_msg = ''
            disable_msg = ''

            with gevent.Timeout(2, False):
                # The server should time us out in 1 second and send back these
                # two messages.
                auth_failed_msg = ws.recv()
                disable_msg = ws.recv()

            self.assertEqual(auth_failed_msg, json.dumps(auth_failed_dict))
            self.assertEqual(disable_msg, json.dumps(disable_dict))
            self.assertFalse('test' in server.session_store)
Exemplo n.º 4
0
    def test_locals(self):
        """
        Tests accessing the locals.
        """
        tracer = self.MockTracer()
        tracer.curframe_locals = {'a': 'a'}
        cmd_manager = self.cmd_manager
        cmd_manager.start(tracer, '')
        gyield()
        self.server.session_store.send_to_tracer(
            uuid=tracer.uuid,
            event=fmt_msg('locals')
        )

        command_locals_called = NonLocal(False)

        def test_command_locals(cmd_manager, tracer, payload):
            command_locals_called.value = True
            type(self.cmd_manager).command_locals(cmd_manager, tracer, payload)

        cmd_locals = partial(test_command_locals, cmd_manager)
        with gevent.Timeout(0.1, False), \
                patch.object(cmd_manager, 'command_locals', cmd_locals):
            cmd_manager.next_command(tracer)
        self.assertTrue(command_locals_called.value)

        tracer.start.assert_called()  # Start always gets called.
        self.server.session_store.slaughter(tracer.uuid)
Exemplo n.º 5
0
    def test_client_attach_timeout(self, mode):
        """
        Tests the case when a client attaches but no tracer does.
        """
        with QdbServer(tracer_server=QdbNopServer(),
                       client_host='localhost',
                       client_port=0,
                       attach_timeout=0.01,
                       timeout_disable_mode=mode) as server:

            client = create_connection(
                'ws://localhost:%d%s' % (server.client_server.server_port,
                                         DEFAULT_ROUTE_FMT.format(uuid='test'))
            )
            send_client_event(client, 'start', '')
            disable_event = None
            with gevent.Timeout(0.1, False):
                error_event = recv_client_event(client)
                disable_event = recv_client_event(client)

            error_dict = fmt_err_msg('tracer', 'No tracer')

            self.assertEqual(error_dict, error_event)
            self.assertEqual(fmt_msg('disable'), disable_event)
            self.assertNotIn('test', server.session_store)
Exemplo n.º 6
0
 def test_runforever_exit(self):
     """
     Tests that stopping a server from one greenlet causes serve_forever()
     to return.
     """
     server = QdbServer(client_port=0, tracer_port=0)
     with gevent.Timeout(1, False):
         # Stop the server in 0.3 seconds.
         gevent.spawn_later(0.3, server.stop)
         server.serve_forever()
     self.assertFalse(server.is_running)
Exemplo n.º 7
0
 def test_commands(self, attrgetter_, event, payload=None):
     """
     Tests various commands with or without payloads.
     """
     tracer = self.MockTracer()
     cmd_manager = self.cmd_manager
     cmd_manager.start(tracer, '')
     self.server.session_store.send_to_tracer(uuid=tracer.uuid,
                                              event=fmt_msg(event, payload))
     with gevent.Timeout(0.1, False):
         cmd_manager.next_command(tracer)
     tracer.start.assert_called()  # Start always gets called.
     attrgetter_(tracer).assert_called()
     # Kill the session we just created
     self.server.session_store.slaughter(tracer.uuid)
Exemplo n.º 8
0
 def test_why_are_you_executing_all_these_commands(self):
     db = Qdb(
         uuid='send_stack_test',
         cmd_manager=self.cmd_manager,
         host=self.tracer_host,
         port=self.tracer_port,
         redirect_output=False,
         green=True,
     )
     gyield()
     for n in range(sys.getrecursionlimit()):
         self.server.session_store.send_to_tracer(uuid=db.uuid,
                                                  event=fmt_msg(
                                                      'eval', 'None'))
     self.server.session_store.send_to_tracer(uuid=db.uuid,
                                              event=fmt_msg('continue'))
     with gevent.Timeout(1):
         db.set_trace(stop=True)