Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean the session files upon unpackling Error in FileSession clean up #2012

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cherrypy/lib/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,10 @@ def clean_up(self):
if expiration_time < now:
# Session expired: deleting it
os.unlink(path)

except pickle.UnpicklingError:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a test for this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish I am able to write a test for this - but with limited skill, I couldn't figure out how to write one - if possible could you please provide some guidance and thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure either. It would probably be an integration test that sets up a server with sessions, makes a query (which results in a session file appearing on disk), then corrupts that file by writing arbitrary data into it (a random byte might be enough), followed by tearing down the server and that should raise the exception. Maybe, it'd be easier (or more stable) with calling clean_up() and checking that the file disappeared from disk. Additionally, it would be wise to use pytest-mocker's mocker.spy() on the _load() method to verify that the exception was raised, indeed.

os.unlink(path)

finally:
self.release_lock(path)

Expand Down
Loading