summaryrefslogtreecommitdiffhomepage
path: root/test/test_http_header.py
diff options
context:
space:
mode:
authorAndrey Zelenkov <zelenkov@nginx.com>2018-03-16 17:45:25 +0300
committerAndrey Zelenkov <zelenkov@nginx.com>2018-03-16 17:45:25 +0300
commitf0df93ee3bb59923505e34c6b302fb2b7325ee80 (patch)
tree070fe5552663af833b7449aec447446fc60870af /test/test_http_header.py
parent701a54c177466c9cbcb82f68c27880281850bd93 (diff)
downloadunit-f0df93ee3bb59923505e34c6b302fb2b7325ee80.tar.gz
unit-f0df93ee3bb59923505e34c6b302fb2b7325ee80.tar.bz2
Tests: HTTP header field and value tests.
Diffstat (limited to 'test/test_http_header.py')
-rw-r--r--test/test_http_header.py123
1 files changed, 123 insertions, 0 deletions
diff --git a/test/test_http_header.py b/test/test_http_header.py
new file mode 100644
index 00000000..364ac9bd
--- /dev/null
+++ b/test/test_http_header.py
@@ -0,0 +1,123 @@
+import unittest
+import unit
+
+class TestUnitHTTPHeader(unit.TestUnitApplicationPython):
+
+ def setUpClass():
+ unit.TestUnit().check_modules('python')
+
+ def test_http_header_value_leading_sp(self):
+ self.load('custom_header')
+
+ resp = self.get(headers={
+ 'Custom-Header': ' ,'
+ })
+
+ self.assertEqual(resp['status'], 200, 'value leading sp status')
+ self.assertEqual(resp['headers']['Custom-Header'], ',',
+ 'value leading sp custom header')
+
+ def test_http_header_value_leading_htab(self):
+ self.load('custom_header')
+
+ resp = self.get(headers={
+ 'Custom-Header': '\t,'
+ })
+
+ self.assertEqual(resp['status'], 200, 'value leading htab status')
+ self.assertEqual(resp['headers']['Custom-Header'], ',',
+ 'value leading htab custom header')
+
+ def test_http_header_value_trailing_sp(self):
+ self.load('custom_header')
+
+ resp = self.get(headers={
+ 'Custom-Header': ', '
+ })
+
+ self.assertEqual(resp['status'], 200, 'value trailing sp status')
+ self.assertEqual(resp['headers']['Custom-Header'], ',',
+ 'value trailing sp custom header')
+
+ def test_http_header_value_trailing_htab(self):
+ self.load('custom_header')
+
+ resp = self.get(headers={
+ 'Custom-Header': ',\t'
+ })
+
+ self.assertEqual(resp['status'], 200, 'value trailing htab status')
+ self.assertEqual(resp['headers']['Custom-Header'], ',',
+ 'value trailing htab custom header')
+
+ def test_http_header_value_both_sp(self):
+ self.load('custom_header')
+
+ resp = self.get(headers={
+ 'Custom-Header': ' , '
+ })
+
+ self.assertEqual(resp['status'], 200, 'value both sp status')
+ self.assertEqual(resp['headers']['Custom-Header'], ',',
+ 'value both sp custom header')
+
+ def test_http_header_value_both_htab(self):
+ self.load('custom_header')
+
+ resp = self.get(headers={
+ 'Custom-Header': '\t,\t'
+ })
+
+ self.assertEqual(resp['status'], 200, 'value both htab status')
+ self.assertEqual(resp['headers']['Custom-Header'], ',',
+ 'value both htab custom header')
+
+ def test_http_header_value_chars(self):
+ self.load('custom_header')
+
+ resp = self.get(headers={
+ 'Custom-Header': '(),/:;<=>?@[\]{}\t !#$%&\'*+-.^_`|~'
+ })
+
+ self.assertEqual(resp['status'], 200, 'value chars status')
+ self.assertEqual(resp['headers']['Custom-Header'],
+ '(),/:;<=>?@[\]{}\t !#$%&\'*+-.^_`|~', 'value chars custom header')
+
+ def test_http_header_field_leading_sp(self):
+ self.load('empty')
+
+ resp = self.get(headers={
+ ' Custom-Header': 'blah'
+ })
+
+ self.assertEqual(resp['status'], 400, 'field leading sp')
+
+ def test_http_header_field_leading_htab(self):
+ self.load('empty')
+
+ resp = self.get(headers={
+ '\tCustom-Header': 'blah'
+ })
+
+ self.assertEqual(resp['status'], 400, 'field leading htab')
+
+ def test_http_header_field_trailing_sp(self):
+ self.load('empty')
+
+ resp = self.get(headers={
+ 'Custom-Header ': 'blah'
+ })
+
+ self.assertEqual(resp['status'], 400, 'field trailing sp')
+
+ def test_http_header_field_trailing_htab(self):
+ self.load('empty')
+
+ resp = self.get(headers={
+ 'Custom-Header\t': 'blah'
+ })
+
+ self.assertEqual(resp['status'], 400, 'field trailing htab')
+
+if __name__ == '__main__':
+ unittest.main()