fastapi-sessions icon indicating copy to clipboard operation
fastapi-sessions copied to clipboard

added tests

Open aekasitt opened this issue 2 years ago • 3 comments

Wanted to try out how it works so I turned the Getting Started section from the docs into a test suite with minor changes.

aekasitt avatar Aug 18 '21 10:08 aekasitt

Thanks for the contribution sorry for the slow response. I will try and get around to looking it over this week.

jordanisaacs avatar Sep 11 '21 18:09 jordanisaacs

no worries. I'm a bit confused with the frontends/backends separation of implementations so I started a project of my own similar to what you're doing, called fastapi-backstage-sesh on the backbone of starsessions, with less emphasis on authentication.

let me know how you plan to take the project forward, maybe I can contribute more.

aekasitt avatar Sep 14 '21 14:09 aekasitt

The frontend contains the methods that interact with the requests/responses. For example the signed cookie signs the session id and then creates a cookie and attaches it to the response. It also is responsible for extracting and verifying session id wasn't tampered with in a request. Then it attaches the ID to the request in a consistent manner so the verifier/backend can access the ID. That's what the abstract class is for (https://github.com/jordanisaacs/fastapi-sessions/blob/master/fastapi_sessions/frontends/session_frontend.py). This enables combining different frontends with different backends enabling code reuse (and having one database for all types of session frontends).

The backend contains the methods that interact with the database to actually find the information that is attached to the corresponding session id.

The verifier is an extra function that acts on the information found in the database. For example if there is an expiration date of the session and sessions don't get automatically deleted from the database. (otherwise can just return True as in the example).

My path to a stable 1.0 release is to have comprehensive testing (so thank you for this PR), a basic signed header frontend ( #12 ), and some more backend examples for other databases.

jordanisaacs avatar Sep 14 '21 16:09 jordanisaacs