@@ -114,13 +114,51 @@ def test_special_attrs(self):
114114 self .assertEqual (C .output (),
115115 'Set-Cookie: Customer="WILE_E_COYOTE"; Max-Age=10' )
116116
117- # others
117+ def test_set_secure_httponly_attrs ( self ):
118118 C = cookies .SimpleCookie ('Customer="WILE_E_COYOTE"' )
119119 C ['Customer' ]['secure' ] = True
120120 C ['Customer' ]['httponly' ] = True
121121 self .assertEqual (C .output (),
122122 'Set-Cookie: Customer="WILE_E_COYOTE"; httponly; secure' )
123123
124+ def test_secure_httponly_false_if_not_present (self ):
125+ C = cookies .SimpleCookie ()
126+ C .load ('eggs=scrambled; Path=/bacon' )
127+ self .assertFalse (C ['eggs' ]['httponly' ])
128+ self .assertFalse (C ['eggs' ]['secure' ])
129+
130+ def test_secure_httponly_true_if_present (self ):
131+ # Issue 16611
132+ C = cookies .SimpleCookie ()
133+ C .load ('eggs=scrambled; httponly; secure; Path=/bacon' )
134+ self .assertTrue (C ['eggs' ]['httponly' ])
135+ self .assertTrue (C ['eggs' ]['secure' ])
136+
137+ def test_secure_httponly_true_if_have_value (self ):
138+ # This isn't really valid, but demonstrates what the current code
139+ # is expected to do in this case.
140+ C = cookies .SimpleCookie ()
141+ C .load ('eggs=scrambled; httponly=foo; secure=bar; Path=/bacon' )
142+ self .assertTrue (C ['eggs' ]['httponly' ])
143+ self .assertTrue (C ['eggs' ]['secure' ])
144+ # Here is what it actually does; don't depend on this behavior. These
145+ # checks are testing backward compatibility for issue 16611.
146+ self .assertEqual (C ['eggs' ]['httponly' ], 'foo' )
147+ self .assertEqual (C ['eggs' ]['secure' ], 'bar' )
148+
149+ def test_bad_attrs (self ):
150+ # issue 16611: make sure we don't break backward compatibility.
151+ C = cookies .SimpleCookie ()
152+ C .load ('cookie=with; invalid; version; second=cookie;' )
153+ self .assertEqual (C .output (),
154+ 'Set-Cookie: cookie=with\r \n Set-Cookie: second=cookie' )
155+
156+ def test_extra_spaces (self ):
157+ C = cookies .SimpleCookie ()
158+ C .load ('eggs = scrambled ; secure ; path = bar ; foo=foo ' )
159+ self .assertEqual (C .output (),
160+ 'Set-Cookie: eggs=scrambled; Path=bar; secure\r \n Set-Cookie: foo=foo' )
161+
124162 def test_quoted_meta (self ):
125163 # Try cookie with quoted meta-data
126164 C = cookies .SimpleCookie ()
0 commit comments