Esempio n. 1
0
    def test_pathInfo(self):
        """
        L{twcgi.CGIScript.render} sets the process environment
        I{PATH_INFO} from the request path.
        """
        class FakeReactor:
            """
            A fake reactor recording the environment passed to spawnProcess.
            """
            def spawnProcess(self, process, filename, args, env, wdir):
                """
                Store the C{env} L{dict} to an instance attribute.

                @param process: Ignored
                @param filename: Ignored
                @param args: Ignored
                @param env: The environment L{dict} which will be stored
                @param wdir: Ignored
                """
                self.process_env = env

        _reactor = FakeReactor()
        resource = twcgi.CGIScript(self.mktemp(), reactor=_reactor)
        request = DummyRequest(['a', 'b'])
        request.client = address.IPv4Address('TCP', '127.0.0.1', 12345)
        _render(resource, request)

        self.assertEqual(_reactor.process_env["PATH_INFO"], "/a/b")
Esempio n. 2
0
    def test_useReactorArgument(self):
        """
        L{twcgi.FilteredScript.runProcess} uses the reactor passed as an
        argument to the constructor.
        """
        class FakeReactor:
            """
            A fake reactor recording whether spawnProcess is called.
            """
            called = False

            def spawnProcess(self, *args, **kwargs):
                """
                Set the C{called} flag to C{True} if C{spawnProcess} is called.

                @param args: Positional arguments.
                @param kwargs: Keyword arguments.
                """
                self.called = True

        fakeReactor = FakeReactor()
        request = DummyRequest(['a', 'b'])
        request.client = address.IPv4Address('TCP', '127.0.0.1', 12345)
        resource = twcgi.FilteredScript("dummy-file", reactor=fakeReactor)
        _render(resource, request)

        self.assertTrue(fakeReactor.called)
Esempio n. 3
0
 def makeRequest(self, method='GET', clientAddress=None):
     """
     Create a L{DummyRequest} (change me to create a
     L{twisted.web.http.Request} instead).
     """
     request = DummyRequest('/')
     request.method = method
     request.client = clientAddress
     return request
Esempio n. 4
0
 def makeRequest(self, method='GET', clientAddress=None):
     """
     Create a L{DummyRequest} (change me to create a
     L{twisted.web.http.Request} instead).
     """
     request = DummyRequest('/')
     request.method = method
     request.client = clientAddress
     return request
    def test_hook_bad_ip(self):
        """
        An error is raised when request is comming from an untrusted IP.
        """
        request = DummyRequest([])
        request.client = IPv4Address('TCP', '111.0.0.0', 2345)
        result = hook(request, 'hook_name')

        self.assertEqual(403, request.code)
        self.assertTrue(result.startswith('Error:001: '))
Esempio n. 6
0
 def makeRequest(self, method=b'GET', clientAddress=None):
     """
     Create a L{DummyRequest} (change me to create a
     L{twisted.web.http.Request} instead).
     """
     if clientAddress is None:
         clientAddress = IPv4Address("TCP", "localhost", 1234)
     request = DummyRequest(b'/')
     request.method = method
     request.client = clientAddress
     return request