diff options
author | Andrey Zelenkov <zelenkov@nginx.com> | 2018-03-16 17:45:25 +0300 |
---|---|---|
committer | Andrey Zelenkov <zelenkov@nginx.com> | 2018-03-16 17:45:25 +0300 |
commit | f0df93ee3bb59923505e34c6b302fb2b7325ee80 (patch) | |
tree | 070fe5552663af833b7449aec447446fc60870af /test | |
parent | 701a54c177466c9cbcb82f68c27880281850bd93 (diff) | |
download | unit-f0df93ee3bb59923505e34c6b302fb2b7325ee80.tar.gz unit-f0df93ee3bb59923505e34c6b302fb2b7325ee80.tar.bz2 |
Tests: HTTP header field and value tests.
Diffstat (limited to 'test')
-rw-r--r-- | test/python/custom_header/wsgi.py | 7 | ||||
-rw-r--r-- | test/test_http_header.py | 123 |
2 files changed, 130 insertions, 0 deletions
diff --git a/test/python/custom_header/wsgi.py b/test/python/custom_header/wsgi.py new file mode 100644 index 00000000..44f145d1 --- /dev/null +++ b/test/python/custom_header/wsgi.py @@ -0,0 +1,7 @@ +def application(environ, start_response): + + start_response('200', [ + ('Content-Length', '0'), + ('Custom-Header', environ.get('HTTP_CUSTOM_HEADER')) + ]) + return [] 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() |