Exemplo n.º 1
0
    def test_put(self):
        State.tenant_cache[1].anonymize_outgoing_connections = False

        # Add a file to the tmp dir
        with open('./robots.txt', 'w') as f:
            f.write("User-agent: *\n" +
                    "Allow: /\n" +
                    "Sitemap: http://localhost/sitemap.xml")

        # Start the HTTP server proxy requests will be forwarded to.
        self.pp = helpers.SimpleServerPP()

        # An extended SimpleHTTPServer to handle the addition of the globaleaks header
        e = "" + \
        "from SimpleHTTPServer import SimpleHTTPRequestHandler as rH; " + \
        "from SimpleHTTPServer import test as t; " + \
        "of = rH.end_headers; rH.end_headers = lambda s: s.send_header('Server', 'GlobaLeaks') or of(s); " + \
        "t(HandlerClass=rH)"

        yield reactor.spawnProcess(self.pp, 'python', args=['python', '-c', e, '43434'], usePTY=True)

        yield self.pp.start_defer

        for value in ['onion', 'localhost', 'antani.onion', 'antani.localhost']:
            handler = self.request({'operation': 'set_hostname', 'args': {'value': value}}, role='admin')
            yield self.assertFailure(handler.put(), errors.InputValidationError)

        handler = self.request({'operation': 'set_hostname', 'args': {'value': 'antani.gov'}}, role='admin')
        yield handler.put()
Exemplo n.º 2
0
    def test_https_process(self):
        valid_cfg = {
            'proxy_ip': '127.0.0.1',
            'proxy_port': 43434,
            'tls_socket_fds': [sock.fileno() for sock in self.https_socks],
            'debug': False,
        }
        db_cfg = yield wrap_db_tx(load_tls_dict)
        valid_cfg.update(db_cfg)

        tmp = tempfile.TemporaryFile()
        tmp.write(json.dumps(valid_cfg))
        tmp.seek(0, 0)
        tmp_fd = tmp.fileno()

        self.http_process = HTTPSProcess(fd=tmp_fd)

        # Connect to service ensure that it responds with a 502
        yield threads.deferToThread(self.fetch_resource_with_fail)

        # Start the HTTP server proxy requests will be forwarded to.
        self.pp = helpers.SimpleServerPP()
        reactor.spawnProcess(
            self.pp,
            'python',
            args=['python', '-m', 'SimpleHTTPServer', '43434'],
            usePTY=True)
        yield self.pp.start_defer

        # Check that requests are routed successfully
        yield threads.deferToThread(self.fetch_resource)
        yield threads.deferToThread(self.fetch_resource_with_gzip)
Exemplo n.º 3
0
    def test_post(self):
        handler = self.request(role='admin')

        # The first request must fail to the non-existent resource
        yield self.assertFailure(handler.post(), errors.ExternalResourceError)

        # Add a file to the tmp dir
        with open('./robots.txt', 'w') as f:
            f.write("User-agent: *\n" + "Allow: /\n" +
                    "Sitemap: http://localhost/sitemap.xml")

        # Start the HTTP server proxy requests will be forwarded to.
        self.pp = helpers.SimpleServerPP()

        # An extended SimpleHTTPServer to handle the addition of the globaleaks header
        e = ""+\
        "from SimpleHTTPServer import SimpleHTTPRequestHandler as rH; "+\
        "from SimpleHTTPServer import test as t; "+\
        "of = rH.end_headers; rH.end_headers = lambda s: s.send_header('Server', 'GlobaLeaks') or of(s); "+\
        "t(HandlerClass=rH)"

        yield reactor.spawnProcess(self.pp,
                                   'python',
                                   args=['python', '-c', e, '43434'],
                                   usePTY=True)

        yield self.pp.start_defer

        yield handler.post()