Пример #1
0
    def _test_new_invalid(self, _call_request, _show, data=None, config=None):
        if config is None:
            config = self.setup_config(data)
        _call_request.return_value = mock_response(self.method, self.url)
        result = command.new(config, lib_api=self.api)

        assert not _call_request.called
        eq_(result, None)
Пример #2
0
    def _test_new_valid(self, _call_request, _show, data=None, config=None):
        if config is None:
            config = self.setup_config(data)
        _call_request.return_value = mock_response(self.method, self.url)
        result = command.new(config, lib_api=self.api)

        _call_request.assert_called_with(*self.correct(data))
        eq_(result, self.expected)
        eq_(_show.call_args[0][0], self.expected)
Пример #3
0
def probe( moduleName, args, torCtrl ):

    logger.info("Running module '%s'." % moduleName)
    module = __import__("modules.%s" % moduleName, fromlist=[moduleName])

    # Obtain the list of exit relays to scan.
    if args.exit:
        exitRelays = [args.exit]
    else:
        hosts = [(socket.gethostbyname(host), port) for
                 (host, port) in module.targets]
        exitRelays = exitselector.getExits(args.consensus,
                                           countryCode=args.country,
                                           hosts=hosts)

    count = len(exitRelays)
    if count < 1:
        raise error.ExitSelectionError("Exit selection yielded %d exits " \
                                       "but need at least one." % count)
    logger.info("About to probe %d exit relays." % count)

    # Create circuit pool and set up stream attacher.
    circuitPool = circuitpool.new(torCtrl, list(exitRelays))
    eventHandler = streamattacher.new(circuitPool, torCtrl)
    torCtrl.add_event_listener(eventHandler.newEvent, EventType.STREAM)

    circuits = torCtrl.get_circuits()
    logger.debug("Open circuits:")
    for circuit in circuits:
        logger.debug(circuit)

    executor = ProcessPoolExecutor(max_workers=const.CIRCUIT_POOL_SIZE)
    logger.debug("Beginning to populate process pool with %d jobs." % count)

    # Invoke a module instance for every exit relay.
    for _ in xrange(count, 0, -1):

        cmd = command.new(None)
        executor.submit(module.probe, cmd, count)
        count -= 1

    logger.info("Submitted jobs.  Terminating main scanner.")
Пример #4
0
    def test_some_binary_data(self, _call_request, _show):
        data = 'FOOBAR'
        config = self.setup_config(binary_data='FOOBAR')
        _call_request.return_value = mock_response(self.method, self.url)
        result = command.new(config, lib_api=self.api)

        expected_kwargs = {
            'binary_data': True
        }
        expected_headers = {
            'content-type': 'application/octet-stream',
            'accept': 'application/json',
            'content-disposition': 'form-data; name="binary_data"; '
                                   'filename="some_binary.data"',
        }
        _call_request.assert_called_with(*self.correct(
                data, expected_kwargs=expected_kwargs,
                expected_headers=expected_headers))
        eq_(result, self.expected)
        eq_(_show.call_args[0][0], self.expected)
Пример #5
0
    def test_invalid_data(self, _call_request):
        cmd = self.setup_config('{"foo":')
        _call_request.return_value = mock_response('GET', self.url)
        command.new(cmd, lib_api=self.api)

        assert not _call_request.called
Пример #6
0
    def test_some_data(self, _call_request):
        cmd = self.setup_config('{"foo": "bar"}')
        _call_request.return_value = mock_response('GET', self.url)
        command.new(cmd, lib_api=self.api)

        _call_request.assert_called_with(*self.correct('{"foo": "bar"}'))