Skip to content

Commit

Permalink
Fixes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
vladtcvs committed Mar 15, 2018
1 parent f2b6bdf commit fbe7b9c
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def prepare(self):
self.tester.current_chain = copy.copy(self.chain)
self.tester.recieved_chain = deproxy.MessageChain.empty()
self.client.clear()
self.client.set_request(self.tester.current_chain.request)
self.client.set_request(self.tester.current_chain)

def check_transition(self, messages):
expected = None
Expand Down
13 changes: 7 additions & 6 deletions tempesta_fw/t/functional/helpers/chains.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@ def response_403(date=None, connection=None):
return deproxy.Response.create(status=403, headers=headers,
date=date, body='')

def response_400(date=None):
def response_400(date=None, connection=None):
if date is None:
date = deproxy.HttpMessage.date_time_string()
resp = deproxy.Response.create(status=400,
headers=['Content-Length: 0',
'Connection: keep-alive'],
date=date,
body='')
headers = ['Content-Length: 0']
if connection != None:
headers.append('Connection: %s' % connection)

resp = deproxy.Response.create(status=400, headers=headers,
date=date, body='')
return resp

def base(uri='/', method='GET', forward=True, date=None):
Expand Down
4 changes: 2 additions & 2 deletions tempesta_fw/t/functional/helpers/deproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,11 +547,11 @@ def handle_read(self):
self.response_buffer = self.response_buffer[len(response.msg):]
except IncompliteMessage:
return
except ParseError:
except ParseError as err:
tf_cfg.dbg(4, ('Deproxy: Client: Can\'t parse message\n'
'<<<<<\n%s>>>>>'
% self.response_buffer))
raise
raise err
if len(self.response_buffer) > 0:
# TODO: take care about pipelined case
raise ParseError('Garbage after response end:\n```\n%s\n```\n' % \
Expand Down
16 changes: 8 additions & 8 deletions tempesta_fw/t/functional/long_body/test_request_wrong_length.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ def req_body_length(base, length):
base.request.build_message()
return base

def generate_chain(method='GET', expect_403=False):
def generate_chain(method='GET', expect_400=False, connection=None):
base = chains.base(method=method)
chain = tester.BadLengthMessageChain(request=base.request,
expected_responses=[base.response],
forwarded_request=base.fwd_request,
server_response=base.server_response)
if expect_403:
chain.responses.append(chains.response_403())
if expect_400:
chain.responses.append(chains.response_400(connection=connection))
return chain

class TesterCorrectBodyLength(tester.BadLengthDeproxy):
Expand All @@ -50,13 +50,13 @@ def __init__(self, *args, **kwargs):
class TesterMissingBodyLength(TesterCorrectBodyLength):
""" Tester """
def create_base(self):
base = generate_chain(method='PUT', expect_403=True)
base = generate_chain(method='PUT', expect_400=True)
return (base, None)

class TesterSmallBodyLength(TesterCorrectBodyLength):
""" Tester """
def create_base(self):
base = generate_chain(method='PUT', expect_403=True)
base = generate_chain(method='PUT', expect_400=True)
return (base, len(base.request.body) - 15)

class TesterDuplicateBodyLength(deproxy.Deproxy):
Expand All @@ -70,7 +70,7 @@ def __init__(self, *args, **kwargs):

base.fwd_request = deproxy.Request()

base.response = chains.response_403(connection='keep-alive')
base.response = chains.response_400(connection='keep-alive')

self.message_chains = [base]
self.cookies = []
Expand All @@ -81,7 +81,7 @@ def __init__(self, *args, **kwargs):
base = chains.base(method='PUT')
base.request.headers['Content-Length'] = 'invalid'
base.request.build_message()
base.response = chains.response_400()
base.response = chains.response_400(connection='keep-alive')
base.fwd_request = deproxy.Request()
self.message_chains = [base]
self.cookies = []
Expand All @@ -92,7 +92,7 @@ def second_length(self, content_length):
return "%i" % (len - 1)

def expected_response(self):
return chains.response_400()
return chains.response_400(connection='keep-alive')

def __init__(self, *args, **kwargs):
deproxy.Deproxy.__init__(self, *args, **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion tempesta_fw/t/functional/msg_sequence/test_pairing.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def send_reqs(self, req_n):

for i in range(b_req, e_req):
self.client.clear()
self.client.set_request(self.message_chains[i].request)
self.client.set_request(self.message_chains[i])

while self.client.request_buffer:
self.loop(timeout=0.1)
Expand Down
2 changes: 1 addition & 1 deletion tempesta_fw/t/functional/regression/test_shutdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def run(self):
self.recieved_chain = deproxy.MessageChain.empty()
for client in self.clients:
client.clear()
client.set_request(self.current_chain.request)
client.set_request(self.current_chain)
self.loop()

def close_all(self):
Expand Down
6 changes: 5 additions & 1 deletion tempesta_fw/t/functional/testers/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import copy
import asyncore
from helpers import tf_cfg, control, tempesta, deproxy, stateful
from helpers.deproxy import ParseError

__author__ = 'Tempesta Technologies, Inc.'
__copyright__ = 'Copyright (C) 2017 Tempesta Technologies, Inc.'
Expand Down Expand Up @@ -146,7 +147,10 @@ def generic_test_routine(self, tempesta_defconfig, message_chains):
self.tester.start()
tf_cfg.dbg(3, "\tStarting completed")

self.tester.run()
try:
self.tester.run()
except ParseError as err:
self.assertTrue(False, msg=str(type(err)))

self.tempesta.get_stats()
self.assert_tempesta()
Expand Down

0 comments on commit fbe7b9c

Please sign in to comment.