mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
gh-99576: Fix cookiejar file that was not truncated for some classes (GH-99616)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
This commit is contained in:
parent
cb60b6131b
commit
44892d45b0
3 changed files with 36 additions and 2 deletions
|
@ -397,6 +397,32 @@ class FileCookieJarTests(unittest.TestCase):
|
|||
finally:
|
||||
os_helper.unlink(filename)
|
||||
|
||||
@unittest.skipIf(mswindows, "windows file permissions are incompatible with file modes")
|
||||
@os_helper.skip_unless_working_chmod
|
||||
def test_cookie_files_are_truncated(self):
|
||||
filename = os_helper.TESTFN
|
||||
for cookiejar_class in (LWPCookieJar, MozillaCookieJar):
|
||||
c = cookiejar_class(filename)
|
||||
|
||||
req = urllib.request.Request("http://www.acme.com/")
|
||||
headers = ["Set-Cookie: pll_lang=en; Max-Age=31536000; path=/"]
|
||||
res = FakeResponse(headers, "http://www.acme.com/")
|
||||
c.extract_cookies(res, req)
|
||||
self.assertEqual(len(c), 1)
|
||||
|
||||
try:
|
||||
# Save the first version with contents:
|
||||
c.save()
|
||||
# Now, clear cookies and re-save:
|
||||
c.clear()
|
||||
c.save()
|
||||
# Check that file was truncated:
|
||||
c.load()
|
||||
finally:
|
||||
os_helper.unlink(filename)
|
||||
|
||||
self.assertEqual(len(c), 0)
|
||||
|
||||
def test_bad_magic(self):
|
||||
# OSErrors (eg. file doesn't exist) are allowed to propagate
|
||||
filename = os_helper.TESTFN
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue