Exemplo n.º 1
0
    def create_chains(self):
        chain_200 = chains.base(forward=True)
        chain_200.request.body = ''.join(
            ['Arbitrary data ' for _ in range(300)])
        chain_200.request.update()

        chain_400 = deproxy.MessageChain(
            request=deproxy.Request(), expected_response=chains.response_400())
        return [chain_200, chain_400]
Exemplo n.º 2
0
 def create_chains(self):
     chain_200 = chains.base(forward=True)
     # Append some garbge to message.
     chain_200.request.msg += ''.join(['Arbitrary data ' for _ in range(300)])
     # Body is not declared in the request, so the garbage will be treated
     # as a new request. 400 response will be sent and client connection
     # will be closed.
     chain_400 = deproxy.MessageChain(
         request = deproxy.Request(),
         expected_response = chains.response_400())
     return [chain_200, chain_400]
Exemplo n.º 3
0
 def __init__(self, clients, servers):
     deproxy.Deproxy.__init__(self, None, None, servers, register=False)
     self.clients = clients
     request = deproxy.Request("GET / HTTP/1.1\r\n"
                               "Host: host\r\n"
                               "User-Agent: curl/7.53.1\r\n"
                               "\r\n")
     response = deproxy.Response()
     self.current_chain = deproxy.MessageChain(request,
                                               response,
                                               server_response=response)
     self.register_tester()
Exemplo n.º 4
0
def base_message_chain(uri='/', method='GET'):
    """Base message chain. Looks like simple Curl request to Tempesta and
    response for it.

    Return new message chain.
    """
    request_headers = [
        'Host: %s' % tf_cfg.cfg.get('Tempesta', 'ip'),
        'User-Agent: curl/7.53.1', 'Connection: keep-alive', 'Accept: */*'
    ]
    request = deproxy.Request.create(method, request_headers, uri=uri)

    fwd_request_headers = (request_headers + [
        'Via: 1.1 tempesta_fw (Tempesta FW %s)' % tempesta.version(),
        'X-Forwarded-For: %s' % tf_cfg.cfg.get('Client', 'ip')
    ])
    fwd_request = deproxy.Request.create(method, fwd_request_headers, uri=uri)

    response_headers = [
        'Content-type: text/html', 'Connection: keep-alive',
        'Content-Length: 138', 'Last-Modified: Mon, 12 Dec 2016 13:59:39 GMT'
    ]
    body = ("<html>\r\n"
            "<head>\r\n"
            "  <title>An Example Page</title>\r\n"
            "</head>\r\n"
            "<body>\r\n"
            "  Hello World, this is a very simple HTML document.\r\n"
            "</body>\r\n"
            "</html>\r\n")

    server_headers = response_headers + ['Server: Deproxy Server']
    server_response = deproxy.Response.create(200,
                                              server_headers,
                                              date=True,
                                              body=body)

    tempesta_headers = (response_headers + [
        'Server: Tempesta FW/%s' % tempesta.version(),
        'Via: 1.1 tempesta_fw (Tempesta FW %s)' % tempesta.version(),
        'Date: %s' % server_response.headers['Date']
    ])
    tempesta_response = deproxy.Response.create(200,
                                                tempesta_headers,
                                                body=body)

    base_chain = deproxy.MessageChain(request=request,
                                      expected_response=tempesta_response,
                                      forwarded_request=fwd_request,
                                      server_response=server_response)

    return copy.copy(base_chain)
Exemplo n.º 5
0
 def chain_failover_forbidden(self):
     chain = deproxy.MessageChain(
         request=self.tester.message_chains[1].request,
         expected_response=cookies.make_502())
     return [chain for _ in range(cookies.CHAIN_LENGTH)]
Exemplo n.º 6
0
def base(uri='/', method='GET', forward=True, date=None):
    """Base message chain. Looks like simple Curl request to Tempesta and
    response for it.

    Return new message chain.
    """

    if date is None:
        date = deproxy.HttpMessage.date_time_string()

    sample_body = ("<html>\r\n"
                   "<head>\r\n"
                   "  <title>An Example Page</title>\r\n"
                   "</head>\r\n"
                   "<body>\r\n"
                   "  Hello World, this is a very simple HTML document.\r\n"
                   "</body>\r\n"
                   "</html>\r\n")
    sample_headers = ['Content-Length: 138', 'Content-type: text/html']

    #
    # Prepare request and response contents (common variant for a GET request)
    #

    # common part of request headers
    common_req_headers = [
        'Host: %s' % tf_cfg.cfg.get('Tempesta', 'ip'),
        'User-Agent: curl/7.53.1', 'Connection: keep-alive', 'Accept: */*'
    ]
    # request headers added in client->tempesta
    client_req_headers_addn = []
    # request headers added in tempesta->backend
    tempesta_req_headers_addn = [
        'Via: 1.1 tempesta_fw (Tempesta FW %s)' % tempesta.version(),
        'X-Forwarded-For: %s' % tf_cfg.cfg.get('Client', 'ip')
    ]
    common_req_body = ''

    # response HTTP code
    common_resp_code = 200
    # response Date: header
    common_resp_date = date
    # response body
    common_resp_body = ''
    # common part of response headers
    common_resp_headers = [
        'Connection: keep-alive',
    ]
    # response headers added in tempesta->client
    tempesta_resp_headers_addn = [
        'Server: Tempesta FW/%s' % tempesta.version(),
        'Via: 1.1 tempesta_fw (Tempesta FW %s)' % tempesta.version()
    ]
    if not forward:
        tempesta_resp_headers_addn += ['Age: 0']
    # response headers added in backend->tempesta
    backend_resp_headers_addn = ['Server: Deproxy Server']

    #
    # Adjust requst and response based on actual method
    #

    if method == "PURGE":
        assert (forward == False)
        common_resp_headers += ['Content-Length: 0']
        tempesta_resp_headers_addn = []

    elif method == "HEAD" or method == "GET":
        common_resp_headers += sample_headers + [
            'Last-Modified: Mon, 12 Dec 2016 13:59:39 GMT'
        ]
        if method == "GET":
            common_resp_body = sample_body

    elif method == "POST":
        common_req_headers += [
            'Content-type: multipart/form-data;boundary="boundary"',
            'Content-Length: 162'
        ]
        common_req_body = (
            '--boundary\r\n'
            'Content-Disposition: form-data; name="field1"\r\n'
            '\r\n'
            'value1\r\n'
            '--boundary\r\n'
            'Content-Disposition: form-data; name="field2"; filename="example.txt"\r\n'
            '\r\n'
            'value2\r\n')
        common_resp_code = 204

    elif method == "PUT":
        common_req_headers += sample_headers
        common_req_body = sample_body
        common_resp_code = 204

    elif method == "DELETE":
        common_resp_code = 204

    else:
        common_resp_headers += ['Content-Length: 0']

    #
    # Build requests and responses
    #

    client_req = deproxy.Request.create(method=method,
                                        headers=common_req_headers +
                                        client_req_headers_addn,
                                        uri=uri,
                                        body=common_req_body)

    tempesta_resp = deproxy.Response.create(
        status=common_resp_code,
        headers=common_resp_headers + tempesta_resp_headers_addn,
        date=common_resp_date,
        body=common_resp_body,
        method=method,
    )

    if forward:
        tempesta_req = deproxy.Request.create(method=method,
                                              headers=common_req_headers +
                                              tempesta_req_headers_addn,
                                              uri=uri,
                                              body=common_req_body)

        backend_resp = deproxy.Response.create(
            status=common_resp_code,
            headers=common_resp_headers + backend_resp_headers_addn,
            date=common_resp_date,
            body=common_resp_body,
            method=method,
        )
    else:
        tempesta_req = None
        backend_resp = None

    base_chain = deproxy.MessageChain(request=client_req,
                                      expected_response=tempesta_resp,
                                      forwarded_request=tempesta_req,
                                      server_response=backend_resp)
    return copy.copy(base_chain)