|
1 | 1 | # Simple test suite for http/cookies.py |
2 | | - |
| 2 | +import base64 |
3 | 3 | import copy |
4 | 4 | import unittest |
5 | 5 | import doctest |
@@ -153,17 +153,19 @@ def test_load(self): |
153 | 153 |
|
154 | 154 | self.assertEqual(C.output(['path']), |
155 | 155 | 'Set-Cookie: Customer="WILE_E_COYOTE"; Path=/acme') |
156 | | - self.assertEqual(C.js_output(), r""" |
| 156 | + cookie_encoded = base64.b64encode(b'Customer="WILE_E_COYOTE"; Path=/acme; Version=1').decode('ascii') |
| 157 | + self.assertEqual(C.js_output(), fr""" |
157 | 158 | <script type="text/javascript"> |
158 | 159 | <!-- begin hiding |
159 | | - document.cookie = "Customer=\"WILE_E_COYOTE\"; Path=/acme; Version=1"; |
| 160 | + document.cookie = atob("{cookie_encoded}"); |
160 | 161 | // end hiding --> |
161 | 162 | </script> |
162 | 163 | """) |
163 | | - self.assertEqual(C.js_output(['path']), r""" |
| 164 | + cookie_encoded = base64.b64encode(b'Customer="WILE_E_COYOTE"; Path=/acme').decode('ascii') |
| 165 | + self.assertEqual(C.js_output(['path']), fr""" |
164 | 166 | <script type="text/javascript"> |
165 | 167 | <!-- begin hiding |
166 | | - document.cookie = "Customer=\"WILE_E_COYOTE\"; Path=/acme"; |
| 168 | + document.cookie = atob("{cookie_encoded}"); |
167 | 169 | // end hiding --> |
168 | 170 | </script> |
169 | 171 | """) |
@@ -260,17 +262,19 @@ def test_quoted_meta(self): |
260 | 262 |
|
261 | 263 | self.assertEqual(C.output(['path']), |
262 | 264 | 'Set-Cookie: Customer="WILE_E_COYOTE"; Path=/acme') |
263 | | - self.assertEqual(C.js_output(), r""" |
| 265 | + expected_encoded_cookie = base64.b64encode(b'Customer=\"WILE_E_COYOTE\"; Path=/acme; Version=1').decode('ascii') |
| 266 | + self.assertEqual(C.js_output(), fr""" |
264 | 267 | <script type="text/javascript"> |
265 | 268 | <!-- begin hiding |
266 | | - document.cookie = "Customer=\"WILE_E_COYOTE\"; Path=/acme; Version=1"; |
| 269 | + document.cookie = atob("{expected_encoded_cookie}"); |
267 | 270 | // end hiding --> |
268 | 271 | </script> |
269 | 272 | """) |
270 | | - self.assertEqual(C.js_output(['path']), r""" |
| 273 | + expected_encoded_cookie = base64.b64encode(b'Customer=\"WILE_E_COYOTE\"; Path=/acme').decode('ascii') |
| 274 | + self.assertEqual(C.js_output(['path']), fr""" |
271 | 275 | <script type="text/javascript"> |
272 | 276 | <!-- begin hiding |
273 | | - document.cookie = "Customer=\"WILE_E_COYOTE\"; Path=/acme"; |
| 277 | + document.cookie = atob("{expected_encoded_cookie}"); |
274 | 278 | // end hiding --> |
275 | 279 | </script> |
276 | 280 | """) |
@@ -361,13 +365,16 @@ def test_setter(self): |
361 | 365 | self.assertEqual( |
362 | 366 | M.output(), |
363 | 367 | "Set-Cookie: %s=%s; Path=/foo" % (i, "%s_coded_val" % i)) |
| 368 | + expected_encoded_cookie = base64.b64encode( |
| 369 | + ("%s=%s; Path=/foo" % (i, "%s_coded_val" % i)).encode("ascii") |
| 370 | + ).decode('ascii') |
364 | 371 | expected_js_output = """ |
365 | 372 | <script type="text/javascript"> |
366 | 373 | <!-- begin hiding |
367 | | - document.cookie = "%s=%s; Path=/foo"; |
| 374 | + document.cookie = atob("%s"); |
368 | 375 | // end hiding --> |
369 | 376 | </script> |
370 | | - """ % (i, "%s_coded_val" % i) |
| 377 | + """ % (expected_encoded_cookie,) |
371 | 378 | self.assertEqual(M.js_output(), expected_js_output) |
372 | 379 | for i in ["foo bar", "foo@bar"]: |
373 | 380 | # Try some illegal characters |
|
0 commit comments