|
1 | 1 | """Tests for http/cookiejar.py."""
|
2 | 2 |
|
3 | 3 | import os
|
| 4 | +import sys |
4 | 5 | import re
|
5 | 6 | import test.support
|
6 | 7 | from test.support import os_helper
|
|
17 | 18 | reach, is_HDN, domain_match, user_domain_match, request_path,
|
18 | 19 | request_port, request_host)
|
19 | 20 |
|
| 21 | +mswindows = (sys.platform == "win32") |
20 | 22 |
|
21 | 23 | class DateTimeTests(unittest.TestCase):
|
22 | 24 |
|
@@ -368,6 +370,35 @@ def test_lwp_valueless_cookie(self):
|
368 | 370 | except OSError: pass
|
369 | 371 | self.assertEqual(c._cookies["www.acme.com"]["/"]["boo"].value, None)
|
370 | 372 |
|
| 373 | + @unittest.skipIf(mswindows, "windows file permissions are incompatible with file modes") |
| 374 | + def test_lwp_filepermissions(self): |
| 375 | + # Cookie file should only be readable by the creator |
| 376 | + filename = os_helper.TESTFN |
| 377 | + c = LWPCookieJar() |
| 378 | + interact_netscape(c, "http://www.acme.com/", 'boo') |
| 379 | + try: |
| 380 | + c.save(filename, ignore_discard=True) |
| 381 | + status = os.stat(filename) |
| 382 | + print(status.st_mode) |
| 383 | + self.assertEqual(oct(status.st_mode)[-3:], '600') |
| 384 | + finally: |
| 385 | + try: os.unlink(filename) |
| 386 | + except OSError: pass |
| 387 | + |
| 388 | + @unittest.skipIf(mswindows, "windows file permissions are incompatible with file modes") |
| 389 | + def test_mozilla_filepermissions(self): |
| 390 | + # Cookie file should only be readable by the creator |
| 391 | + filename = os_helper.TESTFN |
| 392 | + c = MozillaCookieJar() |
| 393 | + interact_netscape(c, "http://www.acme.com/", 'boo') |
| 394 | + try: |
| 395 | + c.save(filename, ignore_discard=True) |
| 396 | + status = os.stat(filename) |
| 397 | + self.assertEqual(oct(status.st_mode)[-3:], '600') |
| 398 | + finally: |
| 399 | + try: os.unlink(filename) |
| 400 | + except OSError: pass |
| 401 | + |
371 | 402 | def test_bad_magic(self):
|
372 | 403 | # OSErrors (eg. file doesn't exist) are allowed to propagate
|
373 | 404 | filename = os_helper.TESTFN
|
|
0 commit comments