@@ -2048,6 +2048,35 @@ def test_session_cookies(self):
20482048 # we didn't have session cookies in the first place
20492049 self .assertNotEqual (counter ["session_before" ], 0 )
20502050
2051+ def test_save_session_cookies (self ):
2052+ # Session cookies are saved with 0 in the expiration time field,
2053+ # as curl and Wget do (gh-61366).
2054+ filename = os_helper .TESTFN
2055+ self .addCleanup (os_helper .unlink , filename )
2056+ expires = int (time .time () + 3600 )
2057+ c = MozillaCookieJar ()
2058+ c .set_cookie (Cookie (0 , "perm" , "bar" , None , False ,
2059+ "www.foo.com" , True , False , "/" , False , False ,
2060+ expires , False , None , None , {}))
2061+ c .set_cookie (Cookie (0 , "session" , "bar" , None , False ,
2062+ "www.foo.com" , True , False , "/" , False , False ,
2063+ None , True , None , None , {}))
2064+ c .save (filename , ignore_discard = True )
2065+
2066+ saved = {}
2067+ with open (filename ) as f :
2068+ for line in f :
2069+ if line .strip () and not line .startswith ("#" ):
2070+ fields = line .split ("\t " )
2071+ saved [fields [5 ]] = fields [4 ]
2072+ self .assertEqual (saved , {"perm" : str (expires ), "session" : "0" })
2073+
2074+ # The saved file can be read back.
2075+ c = MozillaCookieJar ()
2076+ c .revert (filename , ignore_discard = True )
2077+ self .assertEqual (sorted (cookie .name for cookie in c ),
2078+ ["perm" , "session" ])
2079+
20512080 def test_load_session_cookies (self ):
20522081 # curl and Wget write 0 in the expires field for session cookies,
20532082 # while we write an empty field. Both should be read (gh-61366).
0 commit comments