Skip to content

Commit

Permalink
Fix issue #180 - KeyError when loading deleted session (#199)
Browse files Browse the repository at this point in the history
Session.load does not properly handle state after .delete and .save was called.

This happens when user logs out, but saves session id, and then tries to use it again.
  • Loading branch information
kotofos authored Oct 8, 2020
1 parent edb8f52 commit 889d305
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions beaker/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ def load(self):
self.is_new = True

if self.timeout is not None and \
'_accessed_time' in session_data and \
now - session_data['_accessed_time'] > self.timeout:
timed_out = True
else:
Expand Down
10 changes: 10 additions & 0 deletions tests/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,16 @@ def test_invalidate_invalid_signed_cookie_invalidate_corrupt():
assert "foo" not in dict(session)


def test_load_deleted_from_storage_session__not_loaded():
req = {'cookie': {'beaker.session.id': 123}}
session = Session(req, timeout=1)

session.delete()
session.save()

Session(req, timeout=1)


class TestSaveAccessedTime(unittest.TestCase):
# These tests can't use the memory session type since it seems that loading
# winds up with references to the underlying storage and makes changes to
Expand Down

0 comments on commit 889d305

Please sign in to comment.