|
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 |
@@ -152,17 +152,19 @@ def test_load(self): |
152 | 152 |
|
153 | 153 | self.assertEqual(C.output(['path']), |
154 | 154 | 'Set-Cookie: Customer="WILE_E_COYOTE"; Path=/acme') |
155 | | - self.assertEqual(C.js_output(), r""" |
| 155 | + cookie_encoded = base64.b64encode(b'Customer="WILE_E_COYOTE"; Path=/acme; Version=1').decode('ascii') |
| 156 | + self.assertEqual(C.js_output(), fr""" |
156 | 157 | <script type="text/javascript"> |
157 | 158 | <!-- begin hiding |
158 | | - document.cookie = "Customer=\"WILE_E_COYOTE\"; Path=/acme; Version=1"; |
| 159 | + document.cookie = atob("{cookie_encoded}"); |
159 | 160 | // end hiding --> |
160 | 161 | </script> |
161 | 162 | """) |
162 | | - self.assertEqual(C.js_output(['path']), r""" |
| 163 | + cookie_encoded = base64.b64encode(b'Customer="WILE_E_COYOTE"; Path=/acme').decode('ascii') |
| 164 | + self.assertEqual(C.js_output(['path']), fr""" |
163 | 165 | <script type="text/javascript"> |
164 | 166 | <!-- begin hiding |
165 | | - document.cookie = "Customer=\"WILE_E_COYOTE\"; Path=/acme"; |
| 167 | + document.cookie = atob("{cookie_encoded}"); |
166 | 168 | // end hiding --> |
167 | 169 | </script> |
168 | 170 | """) |
@@ -267,17 +269,19 @@ def test_quoted_meta(self): |
267 | 269 |
|
268 | 270 | self.assertEqual(C.output(['path']), |
269 | 271 | 'Set-Cookie: Customer="WILE_E_COYOTE"; Path=/acme') |
270 | | - self.assertEqual(C.js_output(), r""" |
| 272 | + expected_encoded_cookie = base64.b64encode(b'Customer=\"WILE_E_COYOTE\"; Path=/acme; Version=1').decode('ascii') |
| 273 | + self.assertEqual(C.js_output(), fr""" |
271 | 274 | <script type="text/javascript"> |
272 | 275 | <!-- begin hiding |
273 | | - document.cookie = "Customer=\"WILE_E_COYOTE\"; Path=/acme; Version=1"; |
| 276 | + document.cookie = atob("{expected_encoded_cookie}"); |
274 | 277 | // end hiding --> |
275 | 278 | </script> |
276 | 279 | """) |
277 | | - self.assertEqual(C.js_output(['path']), r""" |
| 280 | + expected_encoded_cookie = base64.b64encode(b'Customer=\"WILE_E_COYOTE\"; Path=/acme').decode('ascii') |
| 281 | + self.assertEqual(C.js_output(['path']), fr""" |
278 | 282 | <script type="text/javascript"> |
279 | 283 | <!-- begin hiding |
280 | | - document.cookie = "Customer=\"WILE_E_COYOTE\"; Path=/acme"; |
| 284 | + document.cookie = atob("{expected_encoded_cookie}"); |
281 | 285 | // end hiding --> |
282 | 286 | </script> |
283 | 287 | """) |
@@ -368,13 +372,16 @@ def test_setter(self): |
368 | 372 | self.assertEqual( |
369 | 373 | M.output(), |
370 | 374 | "Set-Cookie: %s=%s; Path=/foo" % (i, "%s_coded_val" % i)) |
| 375 | + expected_encoded_cookie = base64.b64encode( |
| 376 | + ("%s=%s; Path=/foo" % (i, "%s_coded_val" % i)).encode("ascii") |
| 377 | + ).decode('ascii') |
371 | 378 | expected_js_output = """ |
372 | 379 | <script type="text/javascript"> |
373 | 380 | <!-- begin hiding |
374 | | - document.cookie = "%s=%s; Path=/foo"; |
| 381 | + document.cookie = atob("%s"); |
375 | 382 | // end hiding --> |
376 | 383 | </script> |
377 | | - """ % (i, "%s_coded_val" % i) |
| 384 | + """ % (expected_encoded_cookie,) |
378 | 385 | self.assertEqual(M.js_output(), expected_js_output) |
379 | 386 | for i in ["foo bar", "foo@bar"]: |
380 | 387 | # Try some illegal characters |
|
0 commit comments