|
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 |
@@ -175,17 +175,19 @@ def test_load(self): |
175 | 175 |
|
176 | 176 | self.assertEqual(C.output(['path']), |
177 | 177 | 'Set-Cookie: Customer="WILE_E_COYOTE"; Path=/acme') |
178 | | - self.assertEqual(C.js_output(), r""" |
| 178 | + cookie_encoded = base64.b64encode(b'Customer="WILE_E_COYOTE"; Path=/acme; Version=1').decode('ascii') |
| 179 | + self.assertEqual(C.js_output(), fr""" |
179 | 180 | <script type="text/javascript"> |
180 | 181 | <!-- begin hiding |
181 | | - document.cookie = "Customer=\"WILE_E_COYOTE\"; Path=/acme; Version=1"; |
| 182 | + document.cookie = atob("{cookie_encoded}"); |
182 | 183 | // end hiding --> |
183 | 184 | </script> |
184 | 185 | """) |
185 | | - self.assertEqual(C.js_output(['path']), r""" |
| 186 | + cookie_encoded = base64.b64encode(b'Customer="WILE_E_COYOTE"; Path=/acme').decode('ascii') |
| 187 | + self.assertEqual(C.js_output(['path']), fr""" |
186 | 188 | <script type="text/javascript"> |
187 | 189 | <!-- begin hiding |
188 | | - document.cookie = "Customer=\"WILE_E_COYOTE\"; Path=/acme"; |
| 190 | + document.cookie = atob("{cookie_encoded}"); |
189 | 191 | // end hiding --> |
190 | 192 | </script> |
191 | 193 | """) |
@@ -290,17 +292,19 @@ def test_quoted_meta(self): |
290 | 292 |
|
291 | 293 | self.assertEqual(C.output(['path']), |
292 | 294 | 'Set-Cookie: Customer="WILE_E_COYOTE"; Path=/acme') |
293 | | - self.assertEqual(C.js_output(), r""" |
| 295 | + expected_encoded_cookie = base64.b64encode(b'Customer=\"WILE_E_COYOTE\"; Path=/acme; Version=1').decode('ascii') |
| 296 | + self.assertEqual(C.js_output(), fr""" |
294 | 297 | <script type="text/javascript"> |
295 | 298 | <!-- begin hiding |
296 | | - document.cookie = "Customer=\"WILE_E_COYOTE\"; Path=/acme; Version=1"; |
| 299 | + document.cookie = atob("{expected_encoded_cookie}"); |
297 | 300 | // end hiding --> |
298 | 301 | </script> |
299 | 302 | """) |
300 | | - self.assertEqual(C.js_output(['path']), r""" |
| 303 | + expected_encoded_cookie = base64.b64encode(b'Customer=\"WILE_E_COYOTE\"; Path=/acme').decode('ascii') |
| 304 | + self.assertEqual(C.js_output(['path']), fr""" |
301 | 305 | <script type="text/javascript"> |
302 | 306 | <!-- begin hiding |
303 | | - document.cookie = "Customer=\"WILE_E_COYOTE\"; Path=/acme"; |
| 307 | + document.cookie = atob("{expected_encoded_cookie}"); |
304 | 308 | // end hiding --> |
305 | 309 | </script> |
306 | 310 | """) |
@@ -391,13 +395,16 @@ def test_setter(self): |
391 | 395 | self.assertEqual( |
392 | 396 | M.output(), |
393 | 397 | "Set-Cookie: %s=%s; Path=/foo" % (i, "%s_coded_val" % i)) |
| 398 | + expected_encoded_cookie = base64.b64encode( |
| 399 | + ("%s=%s; Path=/foo" % (i, "%s_coded_val" % i)).encode("ascii") |
| 400 | + ).decode('ascii') |
394 | 401 | expected_js_output = """ |
395 | 402 | <script type="text/javascript"> |
396 | 403 | <!-- begin hiding |
397 | | - document.cookie = "%s=%s; Path=/foo"; |
| 404 | + document.cookie = atob("%s"); |
398 | 405 | // end hiding --> |
399 | 406 | </script> |
400 | | - """ % (i, "%s_coded_val" % i) |
| 407 | + """ % (expected_encoded_cookie,) |
401 | 408 | self.assertEqual(M.js_output(), expected_js_output) |
402 | 409 | for i in ["foo bar", "foo@bar"]: |
403 | 410 | # Try some illegal characters |
|
0 commit comments