forked from orbit-oss/flask
session expiration datetime is UTC timezone-aware
This commit is contained in:
parent
cec5f74110
commit
ed42e92928
3 changed files with 7 additions and 3 deletions
|
|
@ -36,6 +36,8 @@ Unreleased
|
||||||
- It is no longer required to decorate custom CLI commands on
|
- It is no longer required to decorate custom CLI commands on
|
||||||
``app.cli`` or ``blueprint.cli`` with ``@with_appcontext``, an app
|
``app.cli`` or ``blueprint.cli`` with ``@with_appcontext``, an app
|
||||||
context will already be active at that point. :issue:`2410`
|
context will already be active at that point. :issue:`2410`
|
||||||
|
- ``SessionInterface.get_expiration_time`` uses a timezone-aware
|
||||||
|
value. :pr:`4645`
|
||||||
|
|
||||||
|
|
||||||
Version 2.1.3
|
Version 2.1.3
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import typing as t
|
||||||
import warnings
|
import warnings
|
||||||
from collections.abc import MutableMapping
|
from collections.abc import MutableMapping
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from datetime import timezone
|
||||||
|
|
||||||
from itsdangerous import BadSignature
|
from itsdangerous import BadSignature
|
||||||
from itsdangerous import URLSafeTimedSerializer
|
from itsdangerous import URLSafeTimedSerializer
|
||||||
|
|
@ -277,7 +278,7 @@ class SessionInterface:
|
||||||
lifetime configured on the application.
|
lifetime configured on the application.
|
||||||
"""
|
"""
|
||||||
if session.permanent:
|
if session.permanent:
|
||||||
return datetime.utcnow() + app.permanent_session_lifetime
|
return datetime.now(timezone.utc) + app.permanent_session_lifetime
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def should_set_cookie(self, app: "Flask", session: SessionMixin) -> bool:
|
def should_set_cookie(self, app: "Flask", session: SessionMixin) -> bool:
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import uuid
|
||||||
import warnings
|
import warnings
|
||||||
import weakref
|
import weakref
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from datetime import timezone
|
||||||
from platform import python_implementation
|
from platform import python_implementation
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
|
|
@ -436,7 +437,7 @@ def test_session_expiration(app, client):
|
||||||
assert "set-cookie" in rv.headers
|
assert "set-cookie" in rv.headers
|
||||||
match = re.search(r"(?i)\bexpires=([^;]+)", rv.headers["set-cookie"])
|
match = re.search(r"(?i)\bexpires=([^;]+)", rv.headers["set-cookie"])
|
||||||
expires = parse_date(match.group())
|
expires = parse_date(match.group())
|
||||||
expected = datetime.utcnow() + app.permanent_session_lifetime
|
expected = datetime.now(timezone.utc) + app.permanent_session_lifetime
|
||||||
assert expires.year == expected.year
|
assert expires.year == expected.year
|
||||||
assert expires.month == expected.month
|
assert expires.month == expected.month
|
||||||
assert expires.day == expected.day
|
assert expires.day == expected.day
|
||||||
|
|
@ -466,7 +467,7 @@ def test_session_stored_last(app, client):
|
||||||
|
|
||||||
|
|
||||||
def test_session_special_types(app, client):
|
def test_session_special_types(app, client):
|
||||||
now = datetime.utcnow().replace(microsecond=0)
|
now = datetime.now(timezone.utc).replace(microsecond=0)
|
||||||
the_uuid = uuid.uuid4()
|
the_uuid = uuid.uuid4()
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue