Ejemplo n.º 1
0
    def test_abort_request(self):
        request_id = 6
        request = [
            Record(FCGI_BEGIN_REQUEST, begin_request_struct.pack(FCGI_RESPONDER, 0), request_id),
            Record(FCGI_ABORT_REQUEST, '', request_id),
            ]
        response = self._handle_one_request(request_id, request)
        self.assertIs(response.stdout, None)
        self.assertIs(response.stderr, None)

        # let greenlet start after final FCGI_PARAMS then abort the request
        request_id = 7
        request = [
            Record(FCGI_BEGIN_REQUEST, begin_request_struct.pack(FCGI_RESPONDER, 0), request_id),
            Record(FCGI_PARAMS, pack_env(REQUEST_METHOD='POST', HTTPS='on'), request_id),
            Record(FCGI_PARAMS, '', request_id),
            Record(FCGI_STDIN, '', request_id),
            # make short delay!!!
            0.5,
            Record(FCGI_ABORT_REQUEST, '', request_id),
            ]
        # run slow_app to make sure server cannot complete request faster than FCGI_ABORT_REQUEST "arrives"
        response = self._handle_one_request(request_id, request, app=slow_app)
        if response.stdout is not None:
            self.assertTrue(response.stdout.startswith('Status: 500 '))
        if response.stdout is not None:
            self.assertTrue(response.stderr.startswith('Traceback (most recent call last):'))
Ejemplo n.º 2
0
 def test_multiplexer(self):
     requests = [
         Record(FCGI_BEGIN_REQUEST, begin_request_struct.pack(FCGI_RESPONDER, 0), 8),
         Record(FCGI_PARAMS, pack_env(REQUEST_METHOD='POST'), 8),
         Record(FCGI_BEGIN_REQUEST, begin_request_struct.pack(FCGI_RESPONDER, 0), 9),
         Record(FCGI_PARAMS, pack_env(REQUEST_METHOD='POST'), 9),
         Record(FCGI_PARAMS, '', 9),
         Record(FCGI_PARAMS, '', 8),
         Record(FCGI_STDIN, DATA, 9),
         Record(FCGI_STDIN, DATA, 8),
         Record(FCGI_STDIN, '', 9),
         Record(FCGI_STDIN, '', 8),
         ]
     for response in self._handle_requests((8, 9), requests, app=echo_app):
         self.assertEqual(response.request_status, FCGI_REQUEST_COMPLETE)
         self.assertTrue(response.stdout_closed and response.stderr_closed)
         self.assertTrue(response.stdout.startswith('Status: 200 OK\r\n\r\n'))
         self.assertEqual(len(response.stdout) - 18, len(DATA))
Ejemplo n.º 3
0
 def test_empty_response(self):
     request_id = 12
     request = [
         Record(FCGI_BEGIN_REQUEST, begin_request_struct.pack(FCGI_RESPONDER, 0), request_id),
         Record(FCGI_PARAMS, '', request_id),
         Record(FCGI_STDIN, '', request_id),
         ]
     response = self._handle_one_request(request_id, request, app=empty_app)
     self.assertEquals(response.stdout, 'Status: 200 OK\r\n\r\n')
     self.assertEquals(response.stderr, '')
Ejemplo n.º 4
0
 def test_wrong_role(self):
     request_id = 5
     request = [
         Record(FCGI_BEGIN_REQUEST, begin_request_struct.pack(FCGI_RESPONDER, 0), request_id),
         Record(FCGI_PARAMS, pack_env(REQUEST_METHOD='POST'), request_id),
         Record(FCGI_PARAMS, '', request_id),
         Record(FCGI_STDIN, '', request_id),
         ]
     response = self._handle_one_request(request_id, request, role=FCGI_FILTER)
     self.assertEqual(response.request_status, FCGI_UNKNOWN_ROLE)
Ejemplo n.º 5
0
 def test_multiple_requests(self):
     requests = [
         # keep "connection" open after first request is processed
         Record(FCGI_BEGIN_REQUEST, begin_request_struct.pack(FCGI_RESPONDER, FCGI_KEEP_CONN), 3),
         Record(FCGI_PARAMS, pack_env(REQUEST_METHOD='POST'), 3),
         Record(FCGI_PARAMS, '', 3),
         Record(FCGI_STDIN, DATA, 3),
         Record(FCGI_STDIN, '', 3),
         # and after this one connection supposed to be closed by 
         Record(FCGI_BEGIN_REQUEST, begin_request_struct.pack(FCGI_RESPONDER, 0), 4),
         Record(FCGI_PARAMS, pack_env(REQUEST_METHOD='POST'), 4),
         Record(FCGI_PARAMS, '', 4),
         Record(FCGI_STDIN, DATA, 4),
         Record(FCGI_STDIN, '', 4),
         ]
     for response in self._handle_requests((3, 4), requests):
         self.assertEquals(response.request_status, FCGI_REQUEST_COMPLETE)
         self.assertTrue(response.stdout_closed)
         self.assertTrue(response.stderr_closed)
Ejemplo n.º 6
0
 def test_authorizer(self):
     request_id = 13
     request = [
         Record(FCGI_BEGIN_REQUEST, begin_request_struct.pack(FCGI_AUTHORIZER, 0), request_id),
         Record(FCGI_PARAMS, pack_env(), request_id),
         Record(FCGI_PARAMS, '', request_id),
         ]
     response = self._handle_one_request(request_id, request, app=empty_app, role=FCGI_AUTHORIZER)
     self.assertEquals(response.request_status, FCGI_REQUEST_COMPLETE)
     self.assertTrue(response.stdout_closed)
     self.assertTrue(response.stderr_closed)
Ejemplo n.º 7
0
    def test_failed_request(self):
        request_id = 10
        request = [
            Record(FCGI_BEGIN_REQUEST, begin_request_struct.pack(FCGI_RESPONDER, 0), request_id),
            Record(FCGI_PARAMS, '', request_id),
            Record(FCGI_STDIN, '', request_id),
            ]
        response = self._handle_one_request(request_id, request, app=failing_app)
        self.assertTrue(response.stdout.startswith('Status: 500 Internal Server Error'))
        self.assertTrue(response.stderr.startswith('Traceback (most recent call last):'))

        request_id = 11
        request = [
            Record(FCGI_BEGIN_REQUEST, begin_request_struct.pack(FCGI_RESPONDER, 0), request_id),
            Record(FCGI_PARAMS, '', request_id),
            Record(FCGI_STDIN, '', request_id),
            ]
        response = self._handle_one_request(request_id, request, app=failing_app2)
        print response.stdout
        print '*' * 100
        print response.stderr
Ejemplo n.º 8
0
 def test_responder(self):
     request_id = 1
     request = (
         Record(FCGI_BEGIN_REQUEST, begin_request_struct.pack(FCGI_RESPONDER, 0), request_id),
         Record(FCGI_PARAMS, pack_env(REQUEST_METHOD='POST'), request_id),
         Record(FCGI_PARAMS, '', request_id),
         Record(FCGI_STDIN, DATA, request_id),
         Record(FCGI_STDIN, '', request_id),
     )
     response = self._handle_one_request(request_id, request)
     self.assertEquals(response.request_status, FCGI_REQUEST_COMPLETE)
     self.assertTrue(response.stdout_closed)
     self.assertTrue(response.stderr_closed)
Ejemplo n.º 9
0
 def test_filter(self):
     request_id = 2
     request = [
         Record(FCGI_BEGIN_REQUEST, begin_request_struct.pack(FCGI_FILTER, 0), request_id),
         Record(FCGI_PARAMS, pack_env(), request_id),
         Record(FCGI_PARAMS, '', request_id),
         Record(FCGI_STDIN, '', request_id),
         Record(FCGI_DATA, '', request_id),
         ]
     response = self._handle_one_request(request_id, request, address='asdasdasd', role=FCGI_FILTER)
     self.assertEquals(response.request_status, FCGI_REQUEST_COMPLETE)
     self.assertTrue(response.stdout_closed)
     self.assertTrue(response.stderr_closed)