File: header_tests.py

package info (click to toggle)
jython 2.7.3%2Brepack1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 62,820 kB
  • sloc: python: 641,384; java: 306,981; xml: 2,066; sh: 514; ansic: 126; makefile: 77
file content (138 lines) | stat: -rw-r--r-- 4,085 bytes parent folder | download | duplicates (7)
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# -*- coding: windows-1252 -*-

###
#
# Copyright Alan Kennedy. 
# 
# You may contact the copyright holder at this uri:
# 
# http://www.xhaus.com/contact/modjy
# 
# The licence under which this code is released is the Apache License v2.0.
# 
# The terms and conditions of this license are listed in a file contained
# in the distribution that also contained this file, under the name
# LICENSE.txt.
# 
# You may also read a copy of the license at the following web address.
# 
# http://modjy.xhaus.com/LICENSE.txt
#
###

"""
    A variety of app callables used to test the WSGI headers.
"""

def test_invalid_status_code(environ, start_response):
    writer = start_response("twohundred ok", [])
    # Should never get here
    writer("D'oh!")
    return []

def test_non_latin1_status_string(environ, start_response):
    writer = start_response(u"200 \u03c9\u03ba", []) # "200 Omega Kappa"
    # Should never get here
    writer("D'oh!")
    return []

def test_control_chars_in_status_string(environ, start_response):
    writer = start_response(u"200 OK\x08\x08Hoopy", []) # "200 OK^H^HHoopy"
    # Should never get here
    writer("D'oh!")
    return []

def test_headers_not_list(environ, start_response):
    qstring = environ['QUERY_STRING']
    if qstring == '1':
        headers = {}
    elif qstring == '2':
        headers = ()
    elif qstring == '3':
        headers = 1
    else:
        headers = None
    writer = start_response("200 OK", headers)
    # Should never get here
    writer("D'oh!")
    return []

def test_headers_list_non_tuples(environ, start_response):
    qstring = environ['QUERY_STRING']
    if qstring == '1':
        header = {}
    elif qstring == '2':
        header = []
    elif qstring == '3':
        header = 1
    else:
        header = None
    headers = [header]
    writer = start_response("200 OK", headers)
    # Should never get here
    writer("D'oh!")
    return []

def test_headers_list_wrong_length_tuples(environ, start_response):
    qstring = environ['QUERY_STRING']
    length = int(qstring)
    if length == 2: length = 3
    header_tuple = tuple(range(int(qstring)))
    headers = [header_tuple]
    writer = start_response("200 OK", headers)
    # Should never get here
    writer("D'oh!")
    return []

def test_headers_list_wrong_types_in_tuples(environ, start_response):
    qstring = environ['QUERY_STRING']
    if qstring == '1':
        headers = [(1, 1)]
    elif qstring == '2':
        headers = [('header_name', 1L)]
    elif qstring == '3':
        headers = [('header_name', None)]
    elif qstring == '4':
        headers = [('header_name', 42.0)]
    else:
        headers = [(None, 'value')]
    writer = start_response("200 OK", headers)
    # Should never get here
    writer("D'oh!")
    return []

def test_headers_list_contains_non_latin1_values(environ, start_response):
    headers = [('x-unicoded-header', u'\u03b1\u03b2\u03b3\u03b4\u03b5')]
    writer = start_response("200 OK", headers)
    # Should never get here
    writer("D'oh!")
    return []

def test_headers_list_contains_values_with_control_chars(environ, start_response):
    headers = [('x-control-coded-header', 'your father smelled of elder\x08\x08\x08\x08\x08loganberries')]
    writer = start_response("200 OK", headers)
    # Should never get here
    writer("D'oh!")
    return []

def test_headers_list_contains_accented_latin1_values(environ, start_response):
    name, value = environ['QUERY_STRING'].split('=')
    headers = [(name, value)]
    writer = start_response("200 OK", headers)
    writer("Doesn't matter")
    return []

def test_headers_list_contains_accented_latin1_values(environ, start_response):
    name, value = environ['QUERY_STRING'].split('=')
    headers = [(name, value)]
    writer = start_response("200 OK", headers)
    writer("Doesn't matter")
    return []

def test_hop_by_hop(environ, start_response):
    qstring = environ['QUERY_STRING']
    headers = [(qstring, 'doesnt matter')]
    writer = start_response("200 OK", headers)
    # Should never get here
    writer("D'oh!")
    return []