blob: cf0f6b9a40a317fbfd55a094eba03de104ae754d [file] [log] [blame]
Georg Brandl24420152008-05-26 16:32:26 +00001# Simple test suite for http/cookies.py
Andrew M. Kuchlingcdec8c72000-08-19 15:21:12 +00002
Serhiy Storchaka6c325852015-03-18 18:03:40 +02003import copy
Brett Cannond3791ed2010-03-20 21:51:10 +00004from test.support import run_unittest, run_doctest, check_warnings
Thomas Wouters89f507f2006-12-13 04:49:30 +00005import unittest
Georg Brandl24420152008-05-26 16:32:26 +00006from http import cookies
Serhiy Storchaka8cf7c1c2014-11-02 22:18:25 +02007import pickle
Andrew M. Kuchling44644322002-12-29 16:45:06 +00008import warnings
Andrew M. Kuchling44644322002-12-29 16:45:06 +00009
Thomas Wouters89f507f2006-12-13 04:49:30 +000010class CookieTests(unittest.TestCase):
Brett Cannond3791ed2010-03-20 21:51:10 +000011
12 def setUp(self):
13 self._warnings_manager = check_warnings()
14 self._warnings_manager.__enter__()
15 warnings.filterwarnings("ignore", ".* class is insecure.*",
16 DeprecationWarning)
17
18 def tearDown(self):
19 self._warnings_manager.__exit__(None, None, None)
20
Thomas Wouters89f507f2006-12-13 04:49:30 +000021 def test_basic(self):
22 cases = [
Georg Brandl76e155a2010-07-31 21:04:00 +000023 {'data': 'chips=ahoy; vienna=finger',
24 'dict': {'chips':'ahoy', 'vienna':'finger'},
25 'repr': "<SimpleCookie: chips='ahoy' vienna='finger'>",
26 'output': 'Set-Cookie: chips=ahoy\nSet-Cookie: vienna=finger'},
Andrew M. Kuchlingcdec8c72000-08-19 15:21:12 +000027
Georg Brandl76e155a2010-07-31 21:04:00 +000028 {'data': 'keebler="E=mc2; L=\\"Loves\\"; fudge=\\012;"',
29 'dict': {'keebler' : 'E=mc2; L="Loves"; fudge=\012;'},
30 'repr': '''<SimpleCookie: keebler='E=mc2; L="Loves"; fudge=\\n;'>''',
31 'output': 'Set-Cookie: keebler="E=mc2; L=\\"Loves\\"; fudge=\\012;"'},
Andrew M. Kuchling8b94b1c2001-02-21 01:17:54 +000032
Thomas Wouters89f507f2006-12-13 04:49:30 +000033 # Check illegal cookies that have an '=' char in an unquoted value
Georg Brandl76e155a2010-07-31 21:04:00 +000034 {'data': 'keebler=E=mc2',
35 'dict': {'keebler' : 'E=mc2'},
36 'repr': "<SimpleCookie: keebler='E=mc2'>",
37 'output': 'Set-Cookie: keebler=E=mc2'},
Senthil Kumaran3a441c12012-04-22 09:19:04 +080038
39 # Cookies with ':' character in their name. Though not mentioned in
40 # RFC, servers / browsers allow it.
41
42 {'data': 'key:term=value:term',
43 'dict': {'key:term' : 'value:term'},
44 'repr': "<SimpleCookie: key:term='value:term'>",
45 'output': 'Set-Cookie: key:term=value:term'},
46
Thomas Wouters89f507f2006-12-13 04:49:30 +000047 ]
Andrew M. Kuchlingcdec8c72000-08-19 15:21:12 +000048
Thomas Wouters89f507f2006-12-13 04:49:30 +000049 for case in cases:
Georg Brandl24420152008-05-26 16:32:26 +000050 C = cookies.SimpleCookie()
Thomas Wouters89f507f2006-12-13 04:49:30 +000051 C.load(case['data'])
52 self.assertEqual(repr(C), case['repr'])
53 self.assertEqual(C.output(sep='\n'), case['output'])
Guido van Rossumcc2b0162007-02-11 06:12:03 +000054 for k, v in sorted(case['dict'].items()):
Thomas Wouters89f507f2006-12-13 04:49:30 +000055 self.assertEqual(C[k].value, v)
Andrew M. Kuchlingcdec8c72000-08-19 15:21:12 +000056
Thomas Wouters89f507f2006-12-13 04:49:30 +000057 def test_load(self):
Georg Brandl24420152008-05-26 16:32:26 +000058 C = cookies.SimpleCookie()
Thomas Wouters89f507f2006-12-13 04:49:30 +000059 C.load('Customer="WILE_E_COYOTE"; Version=1; Path=/acme')
Andrew M. Kuchlingcdec8c72000-08-19 15:21:12 +000060
Thomas Wouters89f507f2006-12-13 04:49:30 +000061 self.assertEqual(C['Customer'].value, 'WILE_E_COYOTE')
62 self.assertEqual(C['Customer']['version'], '1')
63 self.assertEqual(C['Customer']['path'], '/acme')
Moshe Zadka514a1022000-08-19 15:57:33 +000064
Thomas Wouters89f507f2006-12-13 04:49:30 +000065 self.assertEqual(C.output(['path']),
66 'Set-Cookie: Customer="WILE_E_COYOTE"; Path=/acme')
Senthil Kumaran3e2ea792009-04-02 03:02:03 +000067 self.assertEqual(C.js_output(), r"""
Thomas Wouters89f507f2006-12-13 04:49:30 +000068 <script type="text/javascript">
69 <!-- begin hiding
Senthil Kumaran3e2ea792009-04-02 03:02:03 +000070 document.cookie = "Customer=\"WILE_E_COYOTE\"; Path=/acme; Version=1";
Thomas Wouters89f507f2006-12-13 04:49:30 +000071 // end hiding -->
72 </script>
73 """)
Senthil Kumaran3e2ea792009-04-02 03:02:03 +000074 self.assertEqual(C.js_output(['path']), r"""
Thomas Wouters89f507f2006-12-13 04:49:30 +000075 <script type="text/javascript">
76 <!-- begin hiding
Senthil Kumaran3e2ea792009-04-02 03:02:03 +000077 document.cookie = "Customer=\"WILE_E_COYOTE\"; Path=/acme";
Thomas Wouters89f507f2006-12-13 04:49:30 +000078 // end hiding -->
79 </script>
80 """)
Moshe Zadka514a1022000-08-19 15:57:33 +000081
R. David Murraye05ca2a2010-12-28 18:54:13 +000082 def test_extended_encode(self):
83 # Issue 9824: some browsers don't follow the standard; we now
84 # encode , and ; to keep them from tripping up.
85 C = cookies.SimpleCookie()
86 C['val'] = "some,funky;stuff"
87 self.assertEqual(C.output(['val']),
88 'Set-Cookie: val="some\\054funky\\073stuff"')
89
Georg Brandl76e155a2010-07-31 21:04:00 +000090 def test_special_attrs(self):
91 # 'expires'
92 C = cookies.SimpleCookie('Customer="WILE_E_COYOTE"')
93 C['Customer']['expires'] = 0
94 # can't test exact output, it always depends on current date/time
95 self.assertTrue(C.output().endswith('GMT'))
96
Georg Brandlb16e38b2010-08-01 09:06:34 +000097 # loading 'expires'
98 C = cookies.SimpleCookie()
Senthil Kumaran00c2ec22012-05-20 12:05:16 +080099 C.load('Customer="W"; expires=Wed, 01 Jan 2010 00:00:00 GMT')
Georg Brandlb16e38b2010-08-01 09:06:34 +0000100 self.assertEqual(C['Customer']['expires'],
Senthil Kumaran00c2ec22012-05-20 12:05:16 +0800101 'Wed, 01 Jan 2010 00:00:00 GMT')
Georg Brandlb16e38b2010-08-01 09:06:34 +0000102 C = cookies.SimpleCookie()
Senthil Kumaran00c2ec22012-05-20 12:05:16 +0800103 C.load('Customer="W"; expires=Wed, 01 Jan 98 00:00:00 GMT')
Georg Brandlb16e38b2010-08-01 09:06:34 +0000104 self.assertEqual(C['Customer']['expires'],
Senthil Kumaran00c2ec22012-05-20 12:05:16 +0800105 'Wed, 01 Jan 98 00:00:00 GMT')
Georg Brandlb16e38b2010-08-01 09:06:34 +0000106
Georg Brandl76e155a2010-07-31 21:04:00 +0000107 # 'max-age'
108 C = cookies.SimpleCookie('Customer="WILE_E_COYOTE"')
109 C['Customer']['max-age'] = 10
110 self.assertEqual(C.output(),
111 'Set-Cookie: Customer="WILE_E_COYOTE"; Max-Age=10')
112
R David Murraycd0f74b2013-08-25 11:09:02 -0400113 def test_set_secure_httponly_attrs(self):
Georg Brandl76e155a2010-07-31 21:04:00 +0000114 C = cookies.SimpleCookie('Customer="WILE_E_COYOTE"')
115 C['Customer']['secure'] = True
116 C['Customer']['httponly'] = True
117 self.assertEqual(C.output(),
Benjamin Petersonbd341622015-01-16 20:43:55 -0500118 'Set-Cookie: Customer="WILE_E_COYOTE"; HttpOnly; Secure')
Georg Brandl76e155a2010-07-31 21:04:00 +0000119
R David Murraycd0f74b2013-08-25 11:09:02 -0400120 def test_secure_httponly_false_if_not_present(self):
121 C = cookies.SimpleCookie()
122 C.load('eggs=scrambled; Path=/bacon')
123 self.assertFalse(C['eggs']['httponly'])
124 self.assertFalse(C['eggs']['secure'])
125
126 def test_secure_httponly_true_if_present(self):
127 # Issue 16611
128 C = cookies.SimpleCookie()
129 C.load('eggs=scrambled; httponly; secure; Path=/bacon')
130 self.assertTrue(C['eggs']['httponly'])
131 self.assertTrue(C['eggs']['secure'])
132
133 def test_secure_httponly_true_if_have_value(self):
134 # This isn't really valid, but demonstrates what the current code
135 # is expected to do in this case.
136 C = cookies.SimpleCookie()
137 C.load('eggs=scrambled; httponly=foo; secure=bar; Path=/bacon')
138 self.assertTrue(C['eggs']['httponly'])
139 self.assertTrue(C['eggs']['secure'])
140 # Here is what it actually does; don't depend on this behavior. These
141 # checks are testing backward compatibility for issue 16611.
142 self.assertEqual(C['eggs']['httponly'], 'foo')
143 self.assertEqual(C['eggs']['secure'], 'bar')
144
R David Murraycd0f74b2013-08-25 11:09:02 -0400145 def test_extra_spaces(self):
146 C = cookies.SimpleCookie()
147 C.load('eggs = scrambled ; secure ; path = bar ; foo=foo ')
148 self.assertEqual(C.output(),
Benjamin Petersonbd341622015-01-16 20:43:55 -0500149 'Set-Cookie: eggs=scrambled; Path=bar; Secure\r\nSet-Cookie: foo=foo')
R David Murraycd0f74b2013-08-25 11:09:02 -0400150
Thomas Wouters89f507f2006-12-13 04:49:30 +0000151 def test_quoted_meta(self):
152 # Try cookie with quoted meta-data
Georg Brandl24420152008-05-26 16:32:26 +0000153 C = cookies.SimpleCookie()
Thomas Wouters89f507f2006-12-13 04:49:30 +0000154 C.load('Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"')
155 self.assertEqual(C['Customer'].value, 'WILE_E_COYOTE')
156 self.assertEqual(C['Customer']['version'], '1')
157 self.assertEqual(C['Customer']['path'], '/acme')
Tim Peterseb26f952001-04-06 21:20:58 +0000158
Georg Brandl76e155a2010-07-31 21:04:00 +0000159 self.assertEqual(C.output(['path']),
160 'Set-Cookie: Customer="WILE_E_COYOTE"; Path=/acme')
161 self.assertEqual(C.js_output(), r"""
162 <script type="text/javascript">
163 <!-- begin hiding
164 document.cookie = "Customer=\"WILE_E_COYOTE\"; Path=/acme; Version=1";
165 // end hiding -->
166 </script>
167 """)
168 self.assertEqual(C.js_output(['path']), r"""
169 <script type="text/javascript">
170 <!-- begin hiding
171 document.cookie = "Customer=\"WILE_E_COYOTE\"; Path=/acme";
172 // end hiding -->
173 </script>
174 """)
175
Antoine Pitrou7d0b8f92014-09-17 00:23:55 +0200176 def test_invalid_cookies(self):
177 # Accepting these could be a security issue
178 C = cookies.SimpleCookie()
Antoine Pitroub1e36072014-11-21 01:20:57 +0100179 for s in (']foo=x', '[foo=x', 'blah]foo=x', 'blah[foo=x',
180 'Set-Cookie: foo=bar', 'Set-Cookie: foo',
181 'foo=bar; baz', 'baz; foo=bar',
182 'secure;foo=bar', 'Version=1;foo=bar'):
Antoine Pitrou7d0b8f92014-09-17 00:23:55 +0200183 C.load(s)
184 self.assertEqual(dict(C), {})
185 self.assertEqual(C.output(), '')
186
Serhiy Storchaka8cf7c1c2014-11-02 22:18:25 +0200187 def test_pickle(self):
188 rawdata = 'Customer="WILE_E_COYOTE"; Path=/acme; Version=1'
189 expected_output = 'Set-Cookie: %s' % rawdata
190
191 C = cookies.SimpleCookie()
192 C.load(rawdata)
193 self.assertEqual(C.output(), expected_output)
194
195 for proto in range(pickle.HIGHEST_PROTOCOL + 1):
196 with self.subTest(proto=proto):
197 C1 = pickle.loads(pickle.dumps(C, protocol=proto))
198 self.assertEqual(C1.output(), expected_output)
199
Antoine Pitrou7d0b8f92014-09-17 00:23:55 +0200200
Georg Brandl76e155a2010-07-31 21:04:00 +0000201class MorselTests(unittest.TestCase):
202 """Tests for the Morsel object."""
203
Serhiy Storchaka9c1a9b22015-03-18 10:59:57 +0200204 def test_defaults(self):
205 morsel = cookies.Morsel()
206 self.assertIsNone(morsel.key)
207 self.assertIsNone(morsel.value)
208 self.assertIsNone(morsel.coded_value)
209 self.assertEqual(morsel.keys(), cookies.Morsel._reserved.keys())
210 for key, val in morsel.items():
211 self.assertEqual(val, '', key)
212
Georg Brandl76e155a2010-07-31 21:04:00 +0000213 def test_reserved_keys(self):
214 M = cookies.Morsel()
215 # tests valid and invalid reserved keys for Morsels
216 for i in M._reserved:
217 # Test that all valid keys are reported as reserved and set them
218 self.assertTrue(M.isReservedKey(i))
219 M[i] = '%s_value' % i
220 for i in M._reserved:
221 # Test that valid key values come out fine
222 self.assertEqual(M[i], '%s_value' % i)
223 for i in "the holy hand grenade".split():
224 # Test that invalid keys raise CookieError
225 self.assertRaises(cookies.CookieError,
226 M.__setitem__, i, '%s_value' % i)
227
228 def test_setter(self):
229 M = cookies.Morsel()
230 # tests the .set method to set keys and their values
231 for i in M._reserved:
232 # Makes sure that all reserved keys can't be set this way
233 self.assertRaises(cookies.CookieError,
234 M.set, i, '%s_value' % i, '%s_value' % i)
235 for i in "thou cast _the- !holy! ^hand| +*grenade~".split():
236 # Try typical use case. Setting decent values.
237 # Check output and js_output.
238 M['path'] = '/foo' # Try a reserved key as well
239 M.set(i, "%s_val" % i, "%s_coded_val" % i)
240 self.assertEqual(
241 M.output(),
242 "Set-Cookie: %s=%s; Path=/foo" % (i, "%s_coded_val" % i))
243 expected_js_output = """
244 <script type="text/javascript">
245 <!-- begin hiding
246 document.cookie = "%s=%s; Path=/foo";
247 // end hiding -->
248 </script>
249 """ % (i, "%s_coded_val" % i)
250 self.assertEqual(M.js_output(), expected_js_output)
251 for i in ["foo bar", "foo@bar"]:
252 # Try some illegal characters
253 self.assertRaises(cookies.CookieError,
254 M.set, i, '%s_value' % i, '%s_value' % i)
255
Serhiy Storchaka9c1a9b22015-03-18 10:59:57 +0200256 def test_deprecation(self):
257 morsel = cookies.Morsel()
258 with self.assertWarnsRegex(DeprecationWarning, r'\bkey\b'):
259 morsel.key = ''
260 with self.assertWarnsRegex(DeprecationWarning, r'\bvalue\b'):
261 morsel.value = ''
262 with self.assertWarnsRegex(DeprecationWarning, r'\bcoded_value\b'):
263 morsel.coded_value = ''
R David Murray1813c172015-03-29 17:09:21 -0400264 with self.assertWarnsRegex(DeprecationWarning, r'\bLegalChars\b'):
265 morsel.set('key', 'value', 'coded_value', LegalChars='.*')
Serhiy Storchaka9c1a9b22015-03-18 10:59:57 +0200266
267 def test_eq(self):
268 base_case = ('key', 'value', '"value"')
269 attribs = {
270 'path': '/',
271 'comment': 'foo',
272 'domain': 'example.com',
273 'version': 2,
274 }
275 morsel_a = cookies.Morsel()
276 morsel_a.update(attribs)
277 morsel_a.set(*base_case)
278 morsel_b = cookies.Morsel()
279 morsel_b.update(attribs)
280 morsel_b.set(*base_case)
281 self.assertTrue(morsel_a == morsel_b)
282 self.assertFalse(morsel_a != morsel_b)
283 cases = (
284 ('key', 'value', 'mismatch'),
285 ('key', 'mismatch', '"value"'),
286 ('mismatch', 'value', '"value"'),
287 )
288 for case_b in cases:
289 with self.subTest(case_b):
290 morsel_b = cookies.Morsel()
291 morsel_b.update(attribs)
292 morsel_b.set(*case_b)
293 self.assertFalse(morsel_a == morsel_b)
294 self.assertTrue(morsel_a != morsel_b)
295
296 morsel_b = cookies.Morsel()
297 morsel_b.update(attribs)
298 morsel_b.set(*base_case)
299 morsel_b['comment'] = 'bar'
300 self.assertFalse(morsel_a == morsel_b)
301 self.assertTrue(morsel_a != morsel_b)
302
303 # test mismatched types
304 self.assertFalse(cookies.Morsel() == 1)
305 self.assertTrue(cookies.Morsel() != 1)
306 self.assertFalse(cookies.Morsel() == '')
307 self.assertTrue(cookies.Morsel() != '')
308 items = list(cookies.Morsel().items())
309 self.assertFalse(cookies.Morsel() == items)
310 self.assertTrue(cookies.Morsel() != items)
311
312 # morsel/dict
313 morsel = cookies.Morsel()
314 morsel.set(*base_case)
315 morsel.update(attribs)
316 self.assertTrue(morsel == dict(morsel))
317 self.assertFalse(morsel != dict(morsel))
318
319 def test_copy(self):
320 morsel_a = cookies.Morsel()
321 morsel_a.set('foo', 'bar', 'baz')
322 morsel_a.update({
323 'version': 2,
324 'comment': 'foo',
325 })
326 morsel_b = morsel_a.copy()
327 self.assertIsInstance(morsel_b, cookies.Morsel)
328 self.assertIsNot(morsel_a, morsel_b)
329 self.assertEqual(morsel_a, morsel_b)
330
Serhiy Storchaka6c325852015-03-18 18:03:40 +0200331 morsel_b = copy.copy(morsel_a)
332 self.assertIsInstance(morsel_b, cookies.Morsel)
333 self.assertIsNot(morsel_a, morsel_b)
334 self.assertEqual(morsel_a, morsel_b)
335
Serhiy Storchaka9c1a9b22015-03-18 10:59:57 +0200336 def test_setitem(self):
337 morsel = cookies.Morsel()
338 morsel['expires'] = 0
339 self.assertEqual(morsel['expires'], 0)
340 morsel['Version'] = 2
341 self.assertEqual(morsel['version'], 2)
342 morsel['DOMAIN'] = 'example.com'
343 self.assertEqual(morsel['domain'], 'example.com')
344
345 with self.assertRaises(cookies.CookieError):
346 morsel['invalid'] = 'value'
347 self.assertNotIn('invalid', morsel)
348
349 def test_setdefault(self):
350 morsel = cookies.Morsel()
351 morsel.update({
352 'domain': 'example.com',
353 'version': 2,
354 })
355 # this shouldn't override the default value
356 self.assertEqual(morsel.setdefault('expires', 'value'), '')
357 self.assertEqual(morsel['expires'], '')
358 self.assertEqual(morsel.setdefault('Version', 1), 2)
359 self.assertEqual(morsel['version'], 2)
360 self.assertEqual(morsel.setdefault('DOMAIN', 'value'), 'example.com')
361 self.assertEqual(morsel['domain'], 'example.com')
362
363 with self.assertRaises(cookies.CookieError):
364 morsel.setdefault('invalid', 'value')
365 self.assertNotIn('invalid', morsel)
366
367 def test_update(self):
368 attribs = {'expires': 1, 'Version': 2, 'DOMAIN': 'example.com'}
369 # test dict update
370 morsel = cookies.Morsel()
371 morsel.update(attribs)
372 self.assertEqual(morsel['expires'], 1)
373 self.assertEqual(morsel['version'], 2)
374 self.assertEqual(morsel['domain'], 'example.com')
375 # test iterable update
376 morsel = cookies.Morsel()
377 morsel.update(list(attribs.items()))
378 self.assertEqual(morsel['expires'], 1)
379 self.assertEqual(morsel['version'], 2)
380 self.assertEqual(morsel['domain'], 'example.com')
381 # test iterator update
382 morsel = cookies.Morsel()
383 morsel.update((k, v) for k, v in attribs.items())
384 self.assertEqual(morsel['expires'], 1)
385 self.assertEqual(morsel['version'], 2)
386 self.assertEqual(morsel['domain'], 'example.com')
387
388 with self.assertRaises(cookies.CookieError):
389 morsel.update({'invalid': 'value'})
390 self.assertNotIn('invalid', morsel)
391 self.assertRaises(TypeError, morsel.update)
392 self.assertRaises(TypeError, morsel.update, 0)
393
Serhiy Storchaka6c325852015-03-18 18:03:40 +0200394 def test_pickle(self):
395 morsel_a = cookies.Morsel()
396 morsel_a.set('foo', 'bar', 'baz')
397 morsel_a.update({
398 'version': 2,
399 'comment': 'foo',
400 })
401 for proto in range(pickle.HIGHEST_PROTOCOL + 1):
402 with self.subTest(proto=proto):
403 morsel_b = pickle.loads(pickle.dumps(morsel_a, proto))
404 self.assertIsInstance(morsel_b, cookies.Morsel)
405 self.assertEqual(morsel_b, morsel_a)
406 self.assertEqual(str(morsel_b), str(morsel_a))
407
Serhiy Storchaka9c1a9b22015-03-18 10:59:57 +0200408 def test_repr(self):
409 morsel = cookies.Morsel()
410 self.assertEqual(repr(morsel), '<Morsel: None=None>')
411 self.assertEqual(str(morsel), 'Set-Cookie: None=None')
412 morsel.set('key', 'val', 'coded_val')
413 self.assertEqual(repr(morsel), '<Morsel: key=coded_val>')
414 self.assertEqual(str(morsel), 'Set-Cookie: key=coded_val')
415 morsel.update({
416 'path': '/',
417 'comment': 'foo',
418 'domain': 'example.com',
419 'max-age': 0,
420 'secure': 0,
421 'version': 1,
422 })
423 self.assertEqual(repr(morsel),
424 '<Morsel: key=coded_val; Comment=foo; Domain=example.com; '
425 'Max-Age=0; Path=/; Version=1>')
426 self.assertEqual(str(morsel),
427 'Set-Cookie: key=coded_val; Comment=foo; Domain=example.com; '
428 'Max-Age=0; Path=/; Version=1')
429 morsel['secure'] = True
430 morsel['httponly'] = 1
431 self.assertEqual(repr(morsel),
432 '<Morsel: key=coded_val; Comment=foo; Domain=example.com; '
433 'HttpOnly; Max-Age=0; Path=/; Secure; Version=1>')
434 self.assertEqual(str(morsel),
435 'Set-Cookie: key=coded_val; Comment=foo; Domain=example.com; '
436 'HttpOnly; Max-Age=0; Path=/; Secure; Version=1')
437
438 morsel = cookies.Morsel()
439 morsel.set('key', 'val', 'coded_val')
440 morsel['expires'] = 0
441 self.assertRegex(repr(morsel),
442 r'<Morsel: key=coded_val; '
443 r'expires=\w+, \d+ \w+ \d+ \d+:\d+:\d+ \w+>')
444 self.assertRegex(str(morsel),
445 r'Set-Cookie: key=coded_val; '
446 r'expires=\w+, \d+ \w+ \d+ \d+:\d+:\d+ \w+')
Georg Brandl76e155a2010-07-31 21:04:00 +0000447
Thomas Wouters89f507f2006-12-13 04:49:30 +0000448def test_main():
Georg Brandl76e155a2010-07-31 21:04:00 +0000449 run_unittest(CookieTests, MorselTests)
Georg Brandl24420152008-05-26 16:32:26 +0000450 run_doctest(cookies)
Thomas Wouters89f507f2006-12-13 04:49:30 +0000451
452if __name__ == '__main__':
453 test_main()