Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_cgi.py @ 80661:94de77bd0b4b 2.7
Issue #16194: document imp.load_dynamic problems
when read several extension modules from the same binary object file.
| author | Andrew Svetlov <andrew.svetlov@gmail.com> |
|---|---|
| date | Thu, 29 Nov 2012 19:51:28 +0200 |
| parents | 757afb3af762 |
| children | 63058453a4cc |
| rev | line source |
|---|---|
|
58605
f0bc6d8aa21e
#7092: silence more -3 and -Wd warnings
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58198
diff
changeset
|
1 from test.test_support import run_unittest, check_warnings |
|
13842
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
2 import cgi |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
3 import os |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
4 import sys |
|
39427
9f08516a4d0c
Chris McDonough's patch to defend against certain DoS attacks on FieldStorage.
Guido van Rossum <guido@python.org>
parents:
32919
diff
changeset
|
5 import tempfile |
|
40264
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
6 import unittest |
|
13842
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
7 |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
8 class HackedSysModule: |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
9 # The regression test will have real values in sys.argv, which |
|
15305
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14606
diff
changeset
|
10 # will completely confuse the test of the cgi module |
|
13842
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
11 argv = [] |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
12 stdin = sys.stdin |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
13 |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
14 cgi.sys = HackedSysModule() |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
15 |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
16 try: |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
17 from cStringIO import StringIO |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
18 except ImportError: |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
19 from StringIO import StringIO |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
20 |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
21 class ComparableException: |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
22 def __init__(self, err): |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
23 self.err = err |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
24 |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
25 def __str__(self): |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
26 return str(self.err) |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
27 |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
28 def __cmp__(self, anExc): |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
29 if not isinstance(anExc, Exception): |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
30 return -1 |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
31 x = cmp(self.err.__class__, anExc.__class__) |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
32 if x != 0: |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
33 return x |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
34 return cmp(self.err.args, anExc.args) |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
35 |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
36 def __getattr__(self, attr): |
|
15936
bec0f61cfcd5
Fix a bizarre typo in the helper class ComparableException: the
Guido van Rossum <guido@python.org>
parents:
15305
diff
changeset
|
37 return getattr(self.err, attr) |
|
13842
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
38 |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
39 def do_test(buf, method): |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
40 env = {} |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
41 if method == "GET": |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
42 fp = None |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
43 env['REQUEST_METHOD'] = 'GET' |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
44 env['QUERY_STRING'] = buf |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
45 elif method == "POST": |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
46 fp = StringIO(buf) |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
47 env['REQUEST_METHOD'] = 'POST' |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
48 env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded' |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
49 env['CONTENT_LENGTH'] = str(len(buf)) |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
50 else: |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
51 raise ValueError, "unknown method: %s" % method |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
52 try: |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
53 return cgi.parse(fp, env, strict_parsing=1) |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
54 except StandardError, err: |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
55 return ComparableException(err) |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
56 |
|
32758
859ea8612eb0
Don't return spurious empty fields if 'keep_empty_values' is True.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
24442
diff
changeset
|
57 parse_strict_test_cases = [ |
|
13842
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
58 ("", ValueError("bad query field: ''")), |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
59 ("&", ValueError("bad query field: ''")), |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
60 ("&&", ValueError("bad query field: ''")), |
|
14606
f2fc66a6153b
fix bug #110661 (PR#356) -- accept either & or ; as separator for CGI
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14196
diff
changeset
|
61 (";", ValueError("bad query field: ''")), |
|
f2fc66a6153b
fix bug #110661 (PR#356) -- accept either & or ; as separator for CGI
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14196
diff
changeset
|
62 (";&;", ValueError("bad query field: ''")), |
|
13842
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
63 # Should the next few really be valid? |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
64 ("=", {}), |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
65 ("=&=", {}), |
|
14606
f2fc66a6153b
fix bug #110661 (PR#356) -- accept either & or ; as separator for CGI
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14196
diff
changeset
|
66 ("=;=", {}), |
|
13842
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
67 # This rest seem to make sense |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
68 ("=a", {'': ['a']}), |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
69 ("&=a", ValueError("bad query field: ''")), |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
70 ("=a&", ValueError("bad query field: ''")), |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
71 ("=&a", ValueError("bad query field: 'a'")), |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
72 ("b=a", {'b': ['a']}), |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
73 ("b+=a", {'b ': ['a']}), |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
74 ("a=b=a", {'a': ['b=a']}), |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
75 ("a=+b=a", {'a': [' b=a']}), |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
76 ("&b=a", ValueError("bad query field: ''")), |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
77 ("b&=a", ValueError("bad query field: 'b'")), |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
78 ("a=a+b&b=b+c", {'a': ['a b'], 'b': ['b c']}), |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
79 ("a=a+b&a=b+a", {'a': ['a b', 'b a']}), |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
80 ("x=1&y=2.0&z=2-3.%2b0", {'x': ['1'], 'y': ['2.0'], 'z': ['2-3.+0']}), |
|
14606
f2fc66a6153b
fix bug #110661 (PR#356) -- accept either & or ; as separator for CGI
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14196
diff
changeset
|
81 ("x=1;y=2.0&z=2-3.%2b0", {'x': ['1'], 'y': ['2.0'], 'z': ['2-3.+0']}), |
|
f2fc66a6153b
fix bug #110661 (PR#356) -- accept either & or ; as separator for CGI
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14196
diff
changeset
|
82 ("x=1;y=2.0;z=2-3.%2b0", {'x': ['1'], 'y': ['2.0'], 'z': ['2-3.+0']}), |
|
13842
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
83 ("Hbc5161168c542333633315dee1182227:key_store_seqid=400006&cuyer=r&view=bustomer&order_id=0bb2e248638833d48cb7fed300000f1b&expire=964546263&lobale=en-US&kid=130003.300038&ss=env", |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
84 {'Hbc5161168c542333633315dee1182227:key_store_seqid': ['400006'], |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
85 'cuyer': ['r'], |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
86 'expire': ['964546263'], |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
87 'kid': ['130003.300038'], |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
88 'lobale': ['en-US'], |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
89 'order_id': ['0bb2e248638833d48cb7fed300000f1b'], |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
90 'ss': ['env'], |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
91 'view': ['bustomer'], |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
92 }), |
|
15305
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14606
diff
changeset
|
93 |
|
13842
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
94 ("group_id=5470&set=custom&_assigned_to=31392&_status=1&_category=100&SUBMIT=Browse", |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
95 {'SUBMIT': ['Browse'], |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
96 '_assigned_to': ['31392'], |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
97 '_category': ['100'], |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
98 '_status': ['1'], |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
99 'group_id': ['5470'], |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
100 'set': ['custom'], |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
101 }) |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
102 ] |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
103 |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
104 def first_elts(list): |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
105 return map(lambda x:x[0], list) |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
106 |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
107 def first_second_elts(list): |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
108 return map(lambda p:(p[0], p[1][0]), list) |
|
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
109 |
|
47798
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
110 def gen_result(data, environ): |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
111 fake_stdin = StringIO(data) |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
112 fake_stdin.seek(0) |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
113 form = cgi.FieldStorage(fp=fake_stdin, environ=environ) |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
114 |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
115 result = {} |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
116 for k, v in dict(form).items(): |
|
59669
7df3e13d3e50
Cleanup some test cases using check_warnings and check_py3k_warnings.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58605
diff
changeset
|
117 result[k] = isinstance(v, list) and form.getlist(k) or v.value |
|
47798
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
118 |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
119 return result |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
120 |
|
40264
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
121 class CgiTests(unittest.TestCase): |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
122 |
|
75581
757afb3af762
Fix closes Issue14281 - Test for cgi.escape by Brian Landers
Senthil Kumaran <senthil@uthcode.com>
parents:
72988
diff
changeset
|
123 def test_escape(self): |
|
757afb3af762
Fix closes Issue14281 - Test for cgi.escape by Brian Landers
Senthil Kumaran <senthil@uthcode.com>
parents:
72988
diff
changeset
|
124 self.assertEqual("test & string", cgi.escape("test & string")) |
|
757afb3af762
Fix closes Issue14281 - Test for cgi.escape by Brian Landers
Senthil Kumaran <senthil@uthcode.com>
parents:
72988
diff
changeset
|
125 self.assertEqual("<test string>", cgi.escape("<test string>")) |
|
757afb3af762
Fix closes Issue14281 - Test for cgi.escape by Brian Landers
Senthil Kumaran <senthil@uthcode.com>
parents:
72988
diff
changeset
|
126 self.assertEqual(""test string"", cgi.escape('"test string"', True)) |
|
757afb3af762
Fix closes Issue14281 - Test for cgi.escape by Brian Landers
Senthil Kumaran <senthil@uthcode.com>
parents:
72988
diff
changeset
|
127 |
|
40264
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
128 def test_strict(self): |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
129 for orig, expect in parse_strict_test_cases: |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
130 # Test basic parsing |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
131 d = do_test(orig, "GET") |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
132 self.assertEqual(d, expect, "Error parsing %s" % repr(orig)) |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
133 d = do_test(orig, "POST") |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
134 self.assertEqual(d, expect, "Error parsing %s" % repr(orig)) |
|
13842
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
135 |
|
40264
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
136 env = {'QUERY_STRING': orig} |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
137 fcd = cgi.FormContentDict(env) |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
138 sd = cgi.SvFormContentDict(env) |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
139 fs = cgi.FieldStorage(environ=env) |
|
59669
7df3e13d3e50
Cleanup some test cases using check_warnings and check_py3k_warnings.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58605
diff
changeset
|
140 if isinstance(expect, dict): |
|
40264
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
141 # test dict interface |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
142 self.assertEqual(len(expect), len(fcd)) |
|
59754
a682b7087acb
Issue 7832: renaming unittest.TestCase.assertSameElements to assertItemsEqual and changing behaviour
Michael Foord <fuzzyman@voidspace.org.uk>
parents:
59670
diff
changeset
|
143 self.assertItemsEqual(expect.keys(), fcd.keys()) |
|
a682b7087acb
Issue 7832: renaming unittest.TestCase.assertSameElements to assertItemsEqual and changing behaviour
Michael Foord <fuzzyman@voidspace.org.uk>
parents:
59670
diff
changeset
|
144 self.assertItemsEqual(expect.values(), fcd.values()) |
|
a682b7087acb
Issue 7832: renaming unittest.TestCase.assertSameElements to assertItemsEqual and changing behaviour
Michael Foord <fuzzyman@voidspace.org.uk>
parents:
59670
diff
changeset
|
145 self.assertItemsEqual(expect.items(), fcd.items()) |
|
40264
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
146 self.assertEqual(fcd.get("nonexistent field", "default"), "default") |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
147 self.assertEqual(len(sd), len(fs)) |
|
59754
a682b7087acb
Issue 7832: renaming unittest.TestCase.assertSameElements to assertItemsEqual and changing behaviour
Michael Foord <fuzzyman@voidspace.org.uk>
parents:
59670
diff
changeset
|
148 self.assertItemsEqual(sd.keys(), fs.keys()) |
|
40264
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
149 self.assertEqual(fs.getvalue("nonexistent field", "default"), "default") |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
150 # test individual fields |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
151 for key in expect.keys(): |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
152 expect_val = expect[key] |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
49974
diff
changeset
|
153 self.assertTrue(fcd.has_key(key)) |
|
59754
a682b7087acb
Issue 7832: renaming unittest.TestCase.assertSameElements to assertItemsEqual and changing behaviour
Michael Foord <fuzzyman@voidspace.org.uk>
parents:
59670
diff
changeset
|
154 self.assertItemsEqual(fcd[key], expect[key]) |
|
40264
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
155 self.assertEqual(fcd.get(key, "default"), fcd[key]) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
49974
diff
changeset
|
156 self.assertTrue(fs.has_key(key)) |
|
40264
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
157 if len(expect_val) > 1: |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
158 single_value = 0 |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
159 else: |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
160 single_value = 1 |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
161 try: |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
162 val = sd[key] |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
163 except IndexError: |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
49974
diff
changeset
|
164 self.assertFalse(single_value) |
|
40264
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
165 self.assertEqual(fs.getvalue(key), expect_val) |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
166 else: |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
49974
diff
changeset
|
167 self.assertTrue(single_value) |
|
40264
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
168 self.assertEqual(val, expect_val[0]) |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
169 self.assertEqual(fs.getvalue(key), expect_val[0]) |
|
59754
a682b7087acb
Issue 7832: renaming unittest.TestCase.assertSameElements to assertItemsEqual and changing behaviour
Michael Foord <fuzzyman@voidspace.org.uk>
parents:
59670
diff
changeset
|
170 self.assertItemsEqual(sd.getlist(key), expect_val) |
|
40264
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
171 if single_value: |
|
59754
a682b7087acb
Issue 7832: renaming unittest.TestCase.assertSameElements to assertItemsEqual and changing behaviour
Michael Foord <fuzzyman@voidspace.org.uk>
parents:
59670
diff
changeset
|
172 self.assertItemsEqual(sd.values(), |
|
58605
f0bc6d8aa21e
#7092: silence more -3 and -Wd warnings
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58198
diff
changeset
|
173 first_elts(expect.values())) |
|
59754
a682b7087acb
Issue 7832: renaming unittest.TestCase.assertSameElements to assertItemsEqual and changing behaviour
Michael Foord <fuzzyman@voidspace.org.uk>
parents:
59670
diff
changeset
|
174 self.assertItemsEqual(sd.items(), |
|
58605
f0bc6d8aa21e
#7092: silence more -3 and -Wd warnings
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58198
diff
changeset
|
175 first_second_elts(expect.items())) |
|
13842
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
176 |
|
40264
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
177 def test_weird_formcontentdict(self): |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
178 # Test the weird FormContentDict classes |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
179 env = {'QUERY_STRING': "x=1&y=2.0&z=2-3.%2b0&1=1abc"} |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
180 expect = {'x': 1, 'y': 2.0, 'z': '2-3.+0', '1': '1abc'} |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
181 d = cgi.InterpFormContentDict(env) |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
182 for k, v in expect.items(): |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
183 self.assertEqual(d[k], v) |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
184 for k, v in d.items(): |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
185 self.assertEqual(expect[k], v) |
|
59754
a682b7087acb
Issue 7832: renaming unittest.TestCase.assertSameElements to assertItemsEqual and changing behaviour
Michael Foord <fuzzyman@voidspace.org.uk>
parents:
59670
diff
changeset
|
186 self.assertItemsEqual(expect.values(), d.values()) |
|
13842
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
187 |
|
40264
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
188 def test_log(self): |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
189 cgi.log("Testing") |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
190 |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
191 cgi.logfp = StringIO() |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
192 cgi.initlog("%s", "Testing initlog 1") |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
193 cgi.log("%s", "Testing log 2") |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
194 self.assertEqual(cgi.logfp.getvalue(), "Testing initlog 1\nTesting log 2\n") |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
195 if os.path.exists("/dev/null"): |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
196 cgi.logfp = None |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
197 cgi.logfile = "/dev/null" |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
198 cgi.initlog("%s", "Testing log 3") |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
199 cgi.log("Testing log 4") |
|
13842
87488c3113f2
test the non-multipart sections of the cgi module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
200 |
|
40264
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
201 def test_fieldstorage_readline(self): |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
202 # FieldStorage uses readline, which has the capacity to read all |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
203 # contents of the input file into memory; we use readline's size argument |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
204 # to prevent that for files that do not contain any newlines in |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
205 # non-GET/HEAD requests |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
206 class TestReadlineFile: |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
207 def __init__(self, file): |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
208 self.file = file |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
209 self.numcalls = 0 |
|
39427
9f08516a4d0c
Chris McDonough's patch to defend against certain DoS attacks on FieldStorage.
Guido van Rossum <guido@python.org>
parents:
32919
diff
changeset
|
210 |
|
40264
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
211 def readline(self, size=None): |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
212 self.numcalls += 1 |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
213 if size: |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
214 return self.file.readline(size) |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
215 else: |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
216 return self.file.readline() |
|
39427
9f08516a4d0c
Chris McDonough's patch to defend against certain DoS attacks on FieldStorage.
Guido van Rossum <guido@python.org>
parents:
32919
diff
changeset
|
217 |
|
40264
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
218 def __getattr__(self, name): |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
219 file = self.__dict__['file'] |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
220 a = getattr(file, name) |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
221 if not isinstance(a, int): |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
222 setattr(self, name, a) |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
223 return a |
|
39427
9f08516a4d0c
Chris McDonough's patch to defend against certain DoS attacks on FieldStorage.
Guido van Rossum <guido@python.org>
parents:
32919
diff
changeset
|
224 |
|
40264
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
225 f = TestReadlineFile(tempfile.TemporaryFile()) |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
226 f.write('x' * 256 * 1024) |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
227 f.seek(0) |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
228 env = {'REQUEST_METHOD':'PUT'} |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
229 fs = cgi.FieldStorage(fp=f, environ=env) |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
230 # if we're not chunking properly, readline is only called twice |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
231 # (by read_binary); if we are chunking properly, it will be called 5 times |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
232 # as long as the chunksize is 1 << 16. |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
49974
diff
changeset
|
233 self.assertTrue(f.numcalls > 2) |
|
39427
9f08516a4d0c
Chris McDonough's patch to defend against certain DoS attacks on FieldStorage.
Guido van Rossum <guido@python.org>
parents:
32919
diff
changeset
|
234 |
|
40264
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
235 def test_fieldstorage_multipart(self): |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
236 #Test basic FieldStorage multipart parsing |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
237 env = {'REQUEST_METHOD':'POST', 'CONTENT_TYPE':'multipart/form-data; boundary=---------------------------721837373350705526688164684', 'CONTENT_LENGTH':'558'} |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
238 postdata = """-----------------------------721837373350705526688164684 |
|
39427
9f08516a4d0c
Chris McDonough's patch to defend against certain DoS attacks on FieldStorage.
Guido van Rossum <guido@python.org>
parents:
32919
diff
changeset
|
239 Content-Disposition: form-data; name="id" |
|
9f08516a4d0c
Chris McDonough's patch to defend against certain DoS attacks on FieldStorage.
Guido van Rossum <guido@python.org>
parents:
32919
diff
changeset
|
240 |
|
9f08516a4d0c
Chris McDonough's patch to defend against certain DoS attacks on FieldStorage.
Guido van Rossum <guido@python.org>
parents:
32919
diff
changeset
|
241 1234 |
|
9f08516a4d0c
Chris McDonough's patch to defend against certain DoS attacks on FieldStorage.
Guido van Rossum <guido@python.org>
parents:
32919
diff
changeset
|
242 -----------------------------721837373350705526688164684 |
|
9f08516a4d0c
Chris McDonough's patch to defend against certain DoS attacks on FieldStorage.
Guido van Rossum <guido@python.org>
parents:
32919
diff
changeset
|
243 Content-Disposition: form-data; name="title" |
|
9f08516a4d0c
Chris McDonough's patch to defend against certain DoS attacks on FieldStorage.
Guido van Rossum <guido@python.org>
parents:
32919
diff
changeset
|
244 |
|
9f08516a4d0c
Chris McDonough's patch to defend against certain DoS attacks on FieldStorage.
Guido van Rossum <guido@python.org>
parents:
32919
diff
changeset
|
245 |
|
9f08516a4d0c
Chris McDonough's patch to defend against certain DoS attacks on FieldStorage.
Guido van Rossum <guido@python.org>
parents:
32919
diff
changeset
|
246 -----------------------------721837373350705526688164684 |
|
9f08516a4d0c
Chris McDonough's patch to defend against certain DoS attacks on FieldStorage.
Guido van Rossum <guido@python.org>
parents:
32919
diff
changeset
|
247 Content-Disposition: form-data; name="file"; filename="test.txt" |
|
9f08516a4d0c
Chris McDonough's patch to defend against certain DoS attacks on FieldStorage.
Guido van Rossum <guido@python.org>
parents:
32919
diff
changeset
|
248 Content-Type: text/plain |
|
9f08516a4d0c
Chris McDonough's patch to defend against certain DoS attacks on FieldStorage.
Guido van Rossum <guido@python.org>
parents:
32919
diff
changeset
|
249 |
|
9f08516a4d0c
Chris McDonough's patch to defend against certain DoS attacks on FieldStorage.
Guido van Rossum <guido@python.org>
parents:
32919
diff
changeset
|
250 Testing 123. |
|
9f08516a4d0c
Chris McDonough's patch to defend against certain DoS attacks on FieldStorage.
Guido van Rossum <guido@python.org>
parents:
32919
diff
changeset
|
251 |
|
9f08516a4d0c
Chris McDonough's patch to defend against certain DoS attacks on FieldStorage.
Guido van Rossum <guido@python.org>
parents:
32919
diff
changeset
|
252 -----------------------------721837373350705526688164684 |
|
9f08516a4d0c
Chris McDonough's patch to defend against certain DoS attacks on FieldStorage.
Guido van Rossum <guido@python.org>
parents:
32919
diff
changeset
|
253 Content-Disposition: form-data; name="submit" |
|
9f08516a4d0c
Chris McDonough's patch to defend against certain DoS attacks on FieldStorage.
Guido van Rossum <guido@python.org>
parents:
32919
diff
changeset
|
254 |
|
39433
2aca4f040012
Whitespace normalization broke test_cgi, because a line
Tim Peters <tim.peters@gmail.com>
parents:
39432
diff
changeset
|
255 Add\x20 |
|
39427
9f08516a4d0c
Chris McDonough's patch to defend against certain DoS attacks on FieldStorage.
Guido van Rossum <guido@python.org>
parents:
32919
diff
changeset
|
256 -----------------------------721837373350705526688164684-- |
|
9f08516a4d0c
Chris McDonough's patch to defend against certain DoS attacks on FieldStorage.
Guido van Rossum <guido@python.org>
parents:
32919
diff
changeset
|
257 """ |
|
40264
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
258 fs = cgi.FieldStorage(fp=StringIO(postdata), environ=env) |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
59754
diff
changeset
|
259 self.assertEqual(len(fs.list), 4) |
|
40264
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
260 expect = [{'name':'id', 'filename':None, 'value':'1234'}, |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
261 {'name':'title', 'filename':None, 'value':''}, |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
262 {'name':'file', 'filename':'test.txt','value':'Testing 123.\n'}, |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
263 {'name':'submit', 'filename':None, 'value':' Add '}] |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
264 for x in range(len(fs.list)): |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
265 for k, exp in expect[x].items(): |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
266 got = getattr(fs.list[x], k) |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
59754
diff
changeset
|
267 self.assertEqual(got, exp) |
|
39427
9f08516a4d0c
Chris McDonough's patch to defend against certain DoS attacks on FieldStorage.
Guido van Rossum <guido@python.org>
parents:
32919
diff
changeset
|
268 |
|
47798
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
269 _qs_result = { |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
270 'key1': 'value1', |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
271 'key2': ['value2x', 'value2y'], |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
272 'key3': 'value3', |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
273 'key4': 'value4' |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
274 } |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
275 def testQSAndUrlEncode(self): |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
276 data = "key2=value2x&key3=value3&key4=value4" |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
277 environ = { |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
278 'CONTENT_LENGTH': str(len(data)), |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
279 'CONTENT_TYPE': 'application/x-www-form-urlencoded', |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
280 'QUERY_STRING': 'key1=value1&key2=value2y', |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
281 'REQUEST_METHOD': 'POST', |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
282 } |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
283 v = gen_result(data, environ) |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
284 self.assertEqual(self._qs_result, v) |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
285 |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
286 def testQSAndFormData(self): |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
287 data = """ |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
288 ---123 |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
289 Content-Disposition: form-data; name="key2" |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
290 |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
291 value2y |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
292 ---123 |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
293 Content-Disposition: form-data; name="key3" |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
294 |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
295 value3 |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
296 ---123 |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
297 Content-Disposition: form-data; name="key4" |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
298 |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
299 value4 |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
300 ---123-- |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
301 """ |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
302 environ = { |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
303 'CONTENT_LENGTH': str(len(data)), |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
304 'CONTENT_TYPE': 'multipart/form-data; boundary=-123', |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
305 'QUERY_STRING': 'key1=value1&key2=value2x', |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
306 'REQUEST_METHOD': 'POST', |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
307 } |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
308 v = gen_result(data, environ) |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
309 self.assertEqual(self._qs_result, v) |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
310 |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
311 def testQSAndFormDataFile(self): |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
312 data = """ |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
313 ---123 |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
314 Content-Disposition: form-data; name="key2" |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
315 |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
316 value2y |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
317 ---123 |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
318 Content-Disposition: form-data; name="key3" |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
319 |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
320 value3 |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
321 ---123 |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
322 Content-Disposition: form-data; name="key4" |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
323 |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
324 value4 |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
325 ---123 |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
326 Content-Disposition: form-data; name="upload"; filename="fake.txt" |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
327 Content-Type: text/plain |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
328 |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
329 this is the content of the fake file |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
330 |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
331 ---123-- |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
332 """ |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
333 environ = { |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
334 'CONTENT_LENGTH': str(len(data)), |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
335 'CONTENT_TYPE': 'multipart/form-data; boundary=-123', |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
336 'QUERY_STRING': 'key1=value1&key2=value2x', |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
337 'REQUEST_METHOD': 'POST', |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
338 } |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
339 result = self._qs_result.copy() |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
340 result.update({ |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
341 'upload': 'this is the content of the fake file\n' |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
342 }) |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
343 v = gen_result(data, environ) |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
344 self.assertEqual(result, v) |
|
5e8a7f9d9523
Now a from submitted via POST that also has a query string
Facundo Batista <facundobatista@gmail.com>
parents:
40264
diff
changeset
|
345 |
|
49080
7b1f8ede9b53
Issue 3801. Fixing a dumb error in the deprecated parse_qsl()
Facundo Batista <facundobatista@gmail.com>
parents:
48995
diff
changeset
|
346 def test_deprecated_parse_qs(self): |
|
59670
7409b5a7c81a
Fix and check cgi module deprecation warnings. Revert an unwanted rename in test_import.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59669
diff
changeset
|
347 # this func is moved to urlparse, this is just a sanity check |
|
7409b5a7c81a
Fix and check cgi module deprecation warnings. Revert an unwanted rename in test_import.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59669
diff
changeset
|
348 with check_warnings(('cgi.parse_qs is deprecated, use urlparse.' |
|
7409b5a7c81a
Fix and check cgi module deprecation warnings. Revert an unwanted rename in test_import.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59669
diff
changeset
|
349 'parse_qs instead', PendingDeprecationWarning)): |
|
63534
2dc0b7131c72
Merged revisions 77871,77910,77913 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
49974
diff
changeset
|
350 self.assertEqual({'a': ['A1'], 'B': ['B3'], 'b': ['B2']}, |
|
2dc0b7131c72
Merged revisions 77871,77910,77913 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
49974
diff
changeset
|
351 cgi.parse_qs('a=A1&b=B2&B=B3')) |
|
49080
7b1f8ede9b53
Issue 3801. Fixing a dumb error in the deprecated parse_qsl()
Facundo Batista <facundobatista@gmail.com>
parents:
48995
diff
changeset
|
352 |
|
7b1f8ede9b53
Issue 3801. Fixing a dumb error in the deprecated parse_qsl()
Facundo Batista <facundobatista@gmail.com>
parents:
48995
diff
changeset
|
353 def test_deprecated_parse_qsl(self): |
|
59670
7409b5a7c81a
Fix and check cgi module deprecation warnings. Revert an unwanted rename in test_import.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59669
diff
changeset
|
354 # this func is moved to urlparse, this is just a sanity check |
|
7409b5a7c81a
Fix and check cgi module deprecation warnings. Revert an unwanted rename in test_import.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59669
diff
changeset
|
355 with check_warnings(('cgi.parse_qsl is deprecated, use urlparse.' |
|
7409b5a7c81a
Fix and check cgi module deprecation warnings. Revert an unwanted rename in test_import.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59669
diff
changeset
|
356 'parse_qsl instead', PendingDeprecationWarning)): |
|
63534
2dc0b7131c72
Merged revisions 77871,77910,77913 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
49974
diff
changeset
|
357 self.assertEqual([('a', 'A1'), ('b', 'B2'), ('B', 'B3')], |
|
2dc0b7131c72
Merged revisions 77871,77910,77913 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
49974
diff
changeset
|
358 cgi.parse_qsl('a=A1&b=B2&B=B3')) |
|
49080
7b1f8ede9b53
Issue 3801. Fixing a dumb error in the deprecated parse_qsl()
Facundo Batista <facundobatista@gmail.com>
parents:
48995
diff
changeset
|
359 |
|
49974
74bfeb364a23
Merged revisions 67528 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49080
diff
changeset
|
360 def test_parse_header(self): |
|
74bfeb364a23
Merged revisions 67528 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49080
diff
changeset
|
361 self.assertEqual( |
|
74bfeb364a23
Merged revisions 67528 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49080
diff
changeset
|
362 cgi.parse_header("text/plain"), |
|
74bfeb364a23
Merged revisions 67528 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49080
diff
changeset
|
363 ("text/plain", {})) |
|
74bfeb364a23
Merged revisions 67528 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49080
diff
changeset
|
364 self.assertEqual( |
|
74bfeb364a23
Merged revisions 67528 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49080
diff
changeset
|
365 cgi.parse_header("text/vnd.just.made.this.up ; "), |
|
74bfeb364a23
Merged revisions 67528 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49080
diff
changeset
|
366 ("text/vnd.just.made.this.up", {})) |
|
74bfeb364a23
Merged revisions 67528 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49080
diff
changeset
|
367 self.assertEqual( |
|
74bfeb364a23
Merged revisions 67528 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49080
diff
changeset
|
368 cgi.parse_header("text/plain;charset=us-ascii"), |
|
74bfeb364a23
Merged revisions 67528 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49080
diff
changeset
|
369 ("text/plain", {"charset": "us-ascii"})) |
|
74bfeb364a23
Merged revisions 67528 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49080
diff
changeset
|
370 self.assertEqual( |
|
74bfeb364a23
Merged revisions 67528 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49080
diff
changeset
|
371 cgi.parse_header('text/plain ; charset="us-ascii"'), |
|
74bfeb364a23
Merged revisions 67528 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49080
diff
changeset
|
372 ("text/plain", {"charset": "us-ascii"})) |
|
74bfeb364a23
Merged revisions 67528 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49080
diff
changeset
|
373 self.assertEqual( |
|
74bfeb364a23
Merged revisions 67528 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49080
diff
changeset
|
374 cgi.parse_header('text/plain ; charset="us-ascii"; another=opt'), |
|
74bfeb364a23
Merged revisions 67528 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49080
diff
changeset
|
375 ("text/plain", {"charset": "us-ascii", "another": "opt"})) |
|
74bfeb364a23
Merged revisions 67528 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49080
diff
changeset
|
376 self.assertEqual( |
|
74bfeb364a23
Merged revisions 67528 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49080
diff
changeset
|
377 cgi.parse_header('attachment; filename="silly.txt"'), |
|
74bfeb364a23
Merged revisions 67528 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49080
diff
changeset
|
378 ("attachment", {"filename": "silly.txt"})) |
|
74bfeb364a23
Merged revisions 67528 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49080
diff
changeset
|
379 self.assertEqual( |
|
74bfeb364a23
Merged revisions 67528 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49080
diff
changeset
|
380 cgi.parse_header('attachment; filename="strange;name"'), |
|
74bfeb364a23
Merged revisions 67528 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49080
diff
changeset
|
381 ("attachment", {"filename": "strange;name"})) |
|
74bfeb364a23
Merged revisions 67528 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49080
diff
changeset
|
382 self.assertEqual( |
|
74bfeb364a23
Merged revisions 67528 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49080
diff
changeset
|
383 cgi.parse_header('attachment; filename="strange;name";size=123;'), |
|
74bfeb364a23
Merged revisions 67528 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49080
diff
changeset
|
384 ("attachment", {"filename": "strange;name", "size": "123"})) |
|
72988
489237756488
Fix closes Issue12529 - cgi.parse_header failure on double quotes and
Senthil Kumaran <senthil@uthcode.com>
parents:
68256
diff
changeset
|
385 self.assertEqual( |
|
489237756488
Fix closes Issue12529 - cgi.parse_header failure on double quotes and
Senthil Kumaran <senthil@uthcode.com>
parents:
68256
diff
changeset
|
386 cgi.parse_header('form-data; name="files"; filename="fo\\"o;bar"'), |
|
489237756488
Fix closes Issue12529 - cgi.parse_header failure on double quotes and
Senthil Kumaran <senthil@uthcode.com>
parents:
68256
diff
changeset
|
387 ("form-data", {"name": "files", "filename": 'fo"o;bar'})) |
|
49974
74bfeb364a23
Merged revisions 67528 via svnmerge from
Fred Drake <fdrake@acm.org>
parents:
49080
diff
changeset
|
388 |
|
49080
7b1f8ede9b53
Issue 3801. Fixing a dumb error in the deprecated parse_qsl()
Facundo Batista <facundobatista@gmail.com>
parents:
48995
diff
changeset
|
389 |
|
40264
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
390 def test_main(): |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
391 run_unittest(CgiTests) |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
392 |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
393 if __name__ == '__main__': |
|
ca3d1d3c4d8c
Convert test_cgi to unittest.
Georg Brandl <georg@python.org>
parents:
39433
diff
changeset
|
394 test_main() |
