poc2_worked
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import os
|
||||
import tempfile
|
||||
import unittest
|
||||
from types import SimpleNamespace
|
||||
|
||||
from app.auth import SESSION_COOKIE, SessionAuth
|
||||
from app.store import AlertStore
|
||||
|
||||
|
||||
class AuthTests(unittest.TestCase):
|
||||
def test_sqlite_backed_cookie_session_survives_auth_object_recreation(self):
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
store = AlertStore(os.path.join(td, "ids.db"))
|
||||
cfg = SimpleNamespace(
|
||||
admin_username="operator", admin_password="correct horse battery staple", admin_token="",
|
||||
session_hours=24, session_cookie_secure=True,
|
||||
)
|
||||
auth = SessionAuth(cfg, store)
|
||||
self.assertTrue(auth.authenticate("operator", "correct horse battery staple"))
|
||||
self.assertFalse(auth.authenticate("operator", "wrong"))
|
||||
token, created = auth.create_session("operator")
|
||||
header = auth.cookie_header(token)
|
||||
self.assertIn(SESSION_COOKIE + "=", header)
|
||||
self.assertIn("HttpOnly", header)
|
||||
self.assertIn("SameSite=Strict", header)
|
||||
self.assertIn("Secure", header)
|
||||
auth2 = SessionAuth(cfg, store)
|
||||
session = auth2.session_from_cookie(header)
|
||||
self.assertEqual(session["username"], created["username"])
|
||||
auth2.delete_session_from_cookie(header)
|
||||
self.assertIsNone(auth.session_from_cookie(header))
|
||||
store.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user