summaryrefslogtreecommitdiffhomepage
path: root/test/test_http_header.py
blob: 364ac9bd0cd2f137cb773b28260dfac17bcd5539 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
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()