summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorAndrey Zelenkov <zelenkov@nginx.com>2018-07-30 16:40:52 +0300
committerAndrey Zelenkov <zelenkov@nginx.com>2018-07-30 16:40:52 +0300
commita458f50d59ddddfd9de331f45c712fc3600295ec (patch)
tree04dbdfb3c9eda2019ed6bccde5c9b6f08b39c707 /test
parent4b67de4bbb7f7cc6e1337ab9b7479695fd068b74 (diff)
downloadunit-a458f50d59ddddfd9de331f45c712fc3600295ec.tar.gz
unit-a458f50d59ddddfd9de331f45c712fc3600295ec.tar.bz2
Tests: fixed header value char tests.
Use byte strings to avoid problems with encoding.
Diffstat (limited to '')
-rw-r--r--test/test_http_header.py19
-rw-r--r--test/test_settings.py2
-rw-r--r--test/unit.py5
3 files changed, 17 insertions, 9 deletions
diff --git a/test/test_http_header.py b/test/test_http_header.py
index f5388e9e..b787b382 100644
--- a/test/test_http_header.py
+++ b/test/test_http_header.py
@@ -83,12 +83,16 @@ class TestUnitHTTPHeader(unit.TestUnitApplicationPython):
self.assertEqual(resp['headers']['Custom-Header'],
'(),/:;<=>?@[\]{}\t !#$%&\'*+-.^_`|~', 'value chars custom header')
+ @unittest.expectedFailure
def test_http_header_value_chars_edge(self):
self.load('custom_header')
- resp = self.get(headers={
- 'Custom-Header': '\x20\xFF'
- })
+ resp = self.http(b"""GET / HTTP/1.1
+Host: localhost
+Custom-Header: \x20\xFF
+Connection: close
+
+""", raw=True, encoding='latin1')
self.assertEqual(resp['status'], 200, 'value chars edge status')
self.assertEqual(resp['headers']['Custom-Header'], '\xFF',
@@ -97,9 +101,12 @@ class TestUnitHTTPHeader(unit.TestUnitApplicationPython):
def test_http_header_value_chars_below(self):
self.load('custom_header')
- resp = self.get(headers={
- 'Custom-Header': '\x1F'
- })
+ resp = self.http(b"""GET / HTTP/1.1
+Host: localhost
+Custom-Header: \x1F
+Connection: close
+
+""", raw=True)
self.assertEqual(resp['status'], 400, 'value chars below')
diff --git a/test/test_settings.py b/test/test_settings.py
index 8a4d0892..f8e83c8f 100644
--- a/test/test_settings.py
+++ b/test/test_settings.py
@@ -70,7 +70,7 @@ Content-Length: %d
time.sleep(3)
- data += self.recvall(sock)
+ data += self.recvall(sock).decode()
sock.close()
diff --git a/test/unit.py b/test/unit.py
index c8820280..dfd8f4fc 100644
--- a/test/unit.py
+++ b/test/unit.py
@@ -250,7 +250,8 @@ class TestUnitHTTP(TestUnit):
if '--verbose' in sys.argv:
print('>>>', req, sep='\n')
- resp = self.recvall(sock)
+ encoding = 'utf-8' if 'encoding' not in kwargs else kwargs['encoding']
+ resp = self.recvall(sock).decode(encoding)
if '--verbose' in sys.argv:
print('<<<', resp.encode('utf-8'), sep='\n')
@@ -289,7 +290,7 @@ class TestUnitHTTP(TestUnit):
if not len(part):
break
- return data.decode()
+ return data
def _resp_to_dict(self, resp):
m = re.search('(.*?\x0d\x0a?)\x0d\x0a?(.*)', resp, re.M | re.S)