Ejemplo n.º 1
0
    def test_keep_conn(self):
        data = binary_data()
        requests = [
            # keep "connection" open
            Record(FCGI_BEGIN_REQUEST,
                   pack_begin_request(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),
        ]

        # following requests should be served too
        for request_id in (4, 44, 444):
            requests += [
                Record(FCGI_BEGIN_REQUEST,
                       pack_begin_request(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),
            ]
        for response in self._handle_requests((3, 4, 44, 444), requests):
            assert response.request_status == FCGI_REQUEST_COMPLETE
Ejemplo n.º 2
0
 def test_abort_request(self):
     request_id = 6
     request = [
         Record(FCGI_BEGIN_REQUEST, pack_begin_request(FCGI_RESPONDER, 0),
                request_id),
         Record(FCGI_ABORT_REQUEST, '', request_id),
     ]
     response = self._handle_one_request(request_id, request)
     assert response.request_status == FCGI_REQUEST_COMPLETE
Ejemplo n.º 3
0
 def test_responder(self):
     request_id = 1
     request = (
         Record(FCGI_BEGIN_REQUEST, pack_begin_request(FCGI_RESPONDER, 0),
                request_id),
         Record(FCGI_PARAMS, pack_env(REQUEST_METHOD='POST', HTTPS='yes'),
                request_id),
         Record(FCGI_PARAMS, '', request_id),
         Record(FCGI_STDIN, binary_data(), request_id),
         Record(FCGI_STDIN, '', request_id),
     )
     response = self._handle_one_request(request_id, request)
     assert response.request_status == FCGI_REQUEST_COMPLETE
Ejemplo n.º 4
0
 def test_authorizer(self):
     request_id = 13
     request = [
         Record(FCGI_BEGIN_REQUEST, pack_begin_request(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,
                                         role=FCGI_AUTHORIZER,
                                         app=app(response=''))
     assert response.request_status == FCGI_REQUEST_COMPLETE
Ejemplo n.º 5
0
 def test_filter(self):
     request_id = 2
     request = [
         Record(FCGI_BEGIN_REQUEST, pack_begin_request(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,
                                         role=FCGI_FILTER)
     assert response.request_status == FCGI_REQUEST_COMPLETE
Ejemplo n.º 6
0
 def test_empty_response(self):
     request_id = 12
     request = [
         Record(FCGI_BEGIN_REQUEST, pack_begin_request(FCGI_RESPONDER, 0),
                request_id),
         Record(FCGI_PARAMS, '', request_id),
         Record(FCGI_STDIN, '', request_id),
     ]
     response = self._handle_one_request(request_id,
                                         request,
                                         app=app(response=''))
     assert response.stdout.eof_received
     headers, body = response.parse()
     assert len(body) == 0, repr(body)
Ejemplo n.º 7
0
 def test_wrong_role(self):
     request_id = 5
     request = [
         Record(FCGI_BEGIN_REQUEST, pack_begin_request(FCGI_RESPONDER, 0),
                request_id),
     ]
     response = self._handle_one_request(request_id,
                                         request,
                                         role=FCGI_FILTER)
     assert response.request_status == FCGI_UNKNOWN_ROLE
Ejemplo n.º 8
0
    def test_failed_request(self):
        error = AssertionError('Mock application failure SIMULATION')
        request_id = 10
        request = [
            Record(FCGI_BEGIN_REQUEST, pack_begin_request(FCGI_RESPONDER, 0),
                   request_id),
            Record(FCGI_PARAMS, '', request_id),
            Record(FCGI_STDIN, '', request_id),
        ]
        response = self._handle_one_request(request_id,
                                            request,
                                            app=app(exception=error))
        assert response.stdout.eof_received
        headers, body = response.parse()
        assert headers.get('Status', '').startswith('500 ')

        request_id = 11
        request = [
            Record(FCGI_BEGIN_REQUEST, pack_begin_request(FCGI_RESPONDER, 0),
                   request_id),
            Record(FCGI_PARAMS, '', request_id),
            Record(FCGI_STDIN, '', request_id),
        ]
        response = self._handle_one_request(request_id,
                                            request,
                                            app=app(delay=1, exception=error))
Ejemplo n.º 9
0
 def test_multiplexer(self):
     data = binary_data()
     requests = [
         Record(FCGI_BEGIN_REQUEST, pack_begin_request(FCGI_RESPONDER, 0),
                8),
         Record(FCGI_PARAMS, pack_env(REQUEST_METHOD='POST'), 8),
         Record(FCGI_BEGIN_REQUEST, pack_begin_request(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):
         assert response.request_status == FCGI_REQUEST_COMPLETE
         assert response.stdout.eof_received
         headers, body = response.parse()
         assert headers.get('Status') == '200 OK', repr(headers)
         assert body == data
Ejemplo n.º 10
0
    def _run_get_values(self, conn):
        names = (FCGI_MAX_CONNS, FCGI_MAX_REQS, FCGI_MPXS_CONNS)
        get_values_record = Record(FCGI_GET_VALUES,
                                   pack_pairs(dict.fromkeys(names, '')),
                                   FCGI_NULL_REQUEST_ID)

        conn.write_record(get_values_record)
        conn.done_writing()
        done = False
        for record in conn:
            self.assertFalse(done)
            self.assertEquals(record.type, FCGI_GET_VALUES_RESULT)
            values = dict(unpack_pairs(record.content))
            for name in names:
                self.assertIn(name, values)
            done = True
Ejemplo n.º 11
0
    def test_read_write(self):
        record_type = FCGI_DATA
        request_id = randint(1, 65535)
        data = binary_data()
        record = Record(record_type, data, request_id)

        conn = Connection(self.sock)
        conn.write_record(record)

        self.sock.flip()

        record = conn.read_record()
        assert record.type == record_type
        assert record.content == data
        assert record.request_id == request_id

        assert conn.read_record() is None
Ejemplo n.º 12
0
 def test_unknown_request_id(self):
     with start_wsgi_server() as server:
         with make_connection(server.address) as conn:
             conn.write_record(Record(FCGI_ABORT_REQUEST, '', 1))
             conn.done_writing()
             assert conn.read_record() is None
def make_record(record_type, content='', request_id=FCGI_NULL_REQUEST_ID):
    return Record(record_type, content, request_id)
Ejemplo n.º 14
0
 def test_read_write_long_content(self):
     data = binary_data(FCGI_MAX_CONTENT_LEN + 1)
     conn = Connection(self.sock)
     with self.assertRaises(ValueError):
         conn.write_record(Record(FCGI_STDERR, data, 1))