-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFieldStorage.py
More file actions
107 lines (100 loc) · 5.48 KB
/
Copy pathFieldStorage.py
File metadata and controls
107 lines (100 loc) · 5.48 KB
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
from WebKit.SidebarPage import SidebarPage
class FieldStorage(SidebarPage):
"""Test the FieldStorage class.
Since WebKit 0.6, WebKit uses a modified FieldStorage class that
parses GET parameters even in a POST request. However, the parameter
names must be different. A GET parameters with the same name as a
POST parameter is ignored, these values are not appended. In other words,
POST parameters always override GET parameters with the same name.
"""
def cornerTitle(self):
return 'Testing'
def writeContent(self):
request = self.request()
method = request.method()
fields = request.fields()
writeln = self.writeln
if method == 'GET' and not fields:
get_fields = [('getfield1', 'getvalue1'),
('getfield2', 'getvalue21'), ('getfield2', 'getvalue22'),
('dualfield1', 'getdual1'),
('dualfield2', 'getdual21'), ('dualfield2', 'getdual22'),
('getempty', '')]
post_fields = [('postfield1', 'postvalue1'),
('postfield2', 'postvalue21'), ('postfield2', 'postvalue22'),
('dualfield1', 'postdual1'),
('dualfield2', 'postdual21'), ('dualfield2', 'postdual22'),
('postempty', '')]
writeln('<p>The WebKit FieldStorage class can be tested here.</p>')
writeln('<form action="FieldStorage?%s" method="POST">'
% '&'.join('%s=%s' % field for field in get_fields))
writeln('<p>Please press the button to run the test:')
for field in post_fields:
writeln('<input type="hidden" name="%s" value="%s">' % field)
writeln('<input type="submit" name="testbutton" value="Submit">')
writeln('</p></form>')
else:
errors = []
error = errors.append
if method != 'POST':
error('The method is %s instead of POST' % method)
if len(fields) != 9:
error('We got %d instead of 9 fields' % len(fields))
if not request.hasField('testbutton'):
error('We did not get the submit button')
elif request.field('testbutton') != 'Submit':
error('The submit button field got a wrong value')
if not request.hasField('getempty'):
error('We did not get the empty GET parameter')
elif request.field('getempty') != '':
error('The empty GET field got a non-empty value')
if not request.hasField('postempty'):
error('We did not get the empty POST parameter')
elif request.field('postempty') != '':
error('The empty POST field got a non-empty value')
if not request.hasField('getfield1'):
error('The first GET parameter has not been passed')
elif request.field('getfield1') != 'getvalue1':
error('The first GET field got a wrong value')
if not request.hasField('postfield1'):
error('The first POST parameter has not been passed')
elif request.field('postfield1') != 'postvalue1':
error('The first POST field got a wrong value')
if not request.hasField('getfield2'):
error('The second GET parameter has not been passed')
elif request.field('getfield2') != ['getvalue21', 'getvalue22']:
error('The second GET field got a wrong value')
if not request.hasField('postfield2'):
error('The second POST parameter has not been passed')
elif request.field('postfield2') != ['postvalue21', 'postvalue22']:
error('The second POST field got a wrong value')
if not request.hasField('dualfield1'):
error('The first dual parameter has not been passed')
elif request.field('dualfield1') == 'getdual1':
error('The first dual field was not overridden via POST')
elif request.field('dualfield1') in (
['getdual1', 'postdual1'], ['postdual1', 'getdual1']):
error('The first dual field'
' was extended instead of overridden via POST')
elif request.field('dualfield1') != 'postdual1':
error('The first dual field got a wrong value')
if not request.hasField('dualfield2'):
error('The second dual parameter has not been passed')
elif request.field('dualfield2') == ['getdual21', 'getdual22']:
error('The second dual field was not overridden via POST')
elif request.field('dualfield2') in (
['getdual21', 'getdual22', 'postdual21', 'postdual22'],
['postdual21', 'postdual22', 'getdual21', 'getdual22']):
error('The second dual field'
' was extended instead of overridden via POST')
elif request.field('dualfield2') != ['postdual21', 'postdual22']:
error('The second dual field got a wrong value')
if errors:
writeln('<p>FieldStorage does <b>not</b> work as expected:</p>')
writeln('<ul>')
for error in errors:
writeln('<li>%s.</li>' % error)
writeln('</ul>')
else:
writeln('<p>Everything ok, FieldStorage works as expected.</p>')
writeln('<p><a href="./">Back to the test cases overview.</a></p>')