From f0df93ee3bb59923505e34c6b302fb2b7325ee80 Mon Sep 17 00:00:00 2001 From: Andrey Zelenkov Date: Fri, 16 Mar 2018 17:45:25 +0300 Subject: Tests: HTTP header field and value tests. --- test/python/custom_header/wsgi.py | 7 +++ test/test_http_header.py | 123 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+) create mode 100644 test/python/custom_header/wsgi.py create mode 100644 test/test_http_header.py (limited to 'test') 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() -- cgit