Repository navigation
Fix handling of expired cookies so they are not stored in CookieJar - #4066
Conversation
|
There are client functional tests in aiohttp/tests/test_client_functional.py Lines 1959 to 1983 in dc39183 I'd copy that test as |
|
Can I get this reviewed please? Looking at the failed tests it's either related to 3.5 syntax which I believe you are deprecating or components I didn't touch. Please note I added one dev dependency for freezegun because mocking datetime is a pain because it's a builtin. |
Co-Authored-By: Martijn Pieters <github.com@zopatista.com>
Co-Authored-By: Martijn Pieters <github.com@zopatista.com>
Co-Authored-By: Martijn Pieters <github.com@zopatista.com>
Co-Authored-By: Martijn Pieters <github.com@zopatista.com>
Codecov Report
@@ Coverage Diff @@
## master #4066 +/- ##
==========================================
- Coverage 97.77% 97.73% -0.05%
==========================================
Files 43 43
Lines 8763 8771 +8
Branches 1374 1374
==========================================
+ Hits 8568 8572 +4
- Misses 82 85 +3
- Partials 113 114 +1
Continue to review full report at Codecov.
|
mjpieters
left a comment
There was a problem hiding this comment.
Thanks for making the requested changes!
Codecov shows coverage drops slightly because the max_age OverflowError exception handling isn’t covered by tests, see https://codecov.io/gh/aio-libs/aiohttp/compare/6cb18a2a904e0bc50ecb6e1a4f1745f4f5009fec...e76316626350a527349cce3721e12a7f628b6873/src/aiohttp/connector.py. @asvetlov, how much do we need to care about that here? I guess it should be easy enough to add a cookie test with a huge max_age value; 252e9 or more should suffice:
>>> from datetime import datetime, timezone
>>> int((datetime.max.replace(tzinfo=timezone.utc) - datetime.now(timezone.utc)).total_seconds())
251833046966(And 316e9 will cause an overflow with any datetime from datetime.min onwards)
|
Decided to just add the test for max-age overflow since it wasn't hard. |
|
I honestly don't know why the Travis build failed. Edit: Nevermind, figured it out. |
asvetlov
left a comment
There was a problem hiding this comment.
LGTM
The fix worth backporting to 3.x release line
What do these changes do?
Properly schedule expiration date for cookies that are provided to the CookieJar with a date in the past which will result in such cookies being immediately expired by
_do_expiration(). Currently, the expiration date is set to thetimestamp()(i.e., unix timestamp) which will make almost all values far in the future since it's compared to theevent_loop.time()which increments from the start of the loop.Marked WIP because this fix breaks the tests in
tests/test_cookiejar.pyfortest_constructorandTestCookieJarSafe.test_expires. I believe there are incorrect assumptions about behavior but I wanted to verify the test assumptions before making changes to the test suite. Mainly, should expired cookies be stored in the CookieJar and just never sent in requests? Or should they automatically be deleted?The current test suite assumes expired cookies will not be deleted automatically.
I can complete the PR and the remaining steps once I understand the architecture.
Are there changes in behavior for the user?
CookieJar will automatically reject expired cookies and not store in the CookieJar
Related issue number
#4063
Checklist
CONTRIBUTORS.txtCHANGESfolder<issue_id>.<type>for example (588.bugfix)issue_idchange it to the pr id after creating the pr.feature: Signifying a new feature..bugfix: Signifying a bug fix..doc: Signifying a documentation improvement..removal: Signifying a deprecation or removal of public API..misc: A ticket has been closed, but it is not of interest to users.