Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gh-79096: Fix/improve http cookiejar tests
Fixup of GH-93463:
- remove stray print
- use proper way to check file mode
- add working chmod decorator
  • Loading branch information
tiran committed Jun 8, 2022
commit f914ac4620d3fe3fbfb69234a4dcbb58758f502a
18 changes: 9 additions & 9 deletions Lib/test/test_http_cookiejar.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Tests for http/cookiejar.py."""

import os
import stat
import sys
import re
import test.support
Expand Down Expand Up @@ -371,33 +372,32 @@ def test_lwp_valueless_cookie(self):
self.assertEqual(c._cookies["www.acme.com"]["/"]["boo"].value, None)

@unittest.skipIf(mswindows, "windows file permissions are incompatible with file modes")
@os_helper.skip_unless_working_chmod
def test_lwp_filepermissions(self):
# Cookie file should only be readable by the creator
filename = os_helper.TESTFN
c = LWPCookieJar()
interact_netscape(c, "http://www.acme.com/", 'boo')
try:
c.save(filename, ignore_discard=True)
status = os.stat(filename)
print(status.st_mode)
self.assertEqual(oct(status.st_mode)[-3:], '600')
st = os.stat(filename)
self.assertEqual(stat.S_IMODE(st.st_mode), 0o600)
finally:
try: os.unlink(filename)
except OSError: pass
test.support.unlink(filename)

@unittest.skipIf(mswindows, "windows file permissions are incompatible with file modes")
@os_helper.skip_unless_working_chmod
def test_mozilla_filepermissions(self):
# Cookie file should only be readable by the creator
filename = os_helper.TESTFN
c = MozillaCookieJar()
interact_netscape(c, "http://www.acme.com/", 'boo')
try:
c.save(filename, ignore_discard=True)
status = os.stat(filename)
self.assertEqual(oct(status.st_mode)[-3:], '600')
st = os.stat(filename)
self.assertEqual(stat.S_IMODE(st.st_mode), 0o600)
finally:
try: os.unlink(filename)
except OSError: pass
test.support.unlink(filename)

def test_bad_magic(self):
# OSErrors (eg. file doesn't exist) are allowed to propagate
Expand Down