Skip to content

Commit

Permalink
Fix bug in CookieJar when a cookie would be expires by mistake
Browse files Browse the repository at this point in the history
  • Loading branch information
roganov authored and Yegor Roganov committed Jul 13, 2017
1 parent 3516905 commit 1865f6e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion aiohttp/cookiejar.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _do_expiration(self):
cookies = self._cookies
expirations = self._expirations
for (domain, name), when in expirations.items():
if when < now:
if when <= now:
cookies[domain].pop(name, None)
to_del.append((domain, name))
self._host_only_cookies.discard((domain, name))
Expand Down
19 changes: 19 additions & 0 deletions tests/test_cookiejar.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import datetime
import itertools
import os
import tempfile
import unittest
Expand Down Expand Up @@ -577,3 +578,21 @@ def test_invalid_values(self):

cookie = cookies_sent["invalid-expires-cookie"]
self.assertEqual(cookie["expires"], "")

def test_cookie_not_expired_when_added_after_removal(self):
"""Test case for https://github.com/aio-libs/aiohttp/issues/2084"""
timestamps = [533588.993, 533588.993, 533588.993,
533588.993, 533589.093, 533589.093]

loop = mock.Mock()
loop.time.side_effect = itertools.chain(
timestamps, itertools.cycle([timestamps[-1]]))

jar = CookieJar(unsafe=True, loop=loop)
# Remove`foo` cookie.
jar.update_cookies(SimpleCookie('foo=""; Max-Age=0'))
# Set `foo` cookie to `bar`.
jar.update_cookies(SimpleCookie('foo="bar"'))

# Assert that there a cookie.
assert jar

0 comments on commit 1865f6e

Please sign in to comment.