diff --git a/forum/forum.py b/forum/forum.py index 1b81d9f..0bfffdd 100644 --- a/forum/forum.py +++ b/forum/forum.py @@ -51,7 +51,7 @@ class Forum: jeton = secrets.token_urlsafe(32) self.con.execute("DELETE FROM sessions WHERE expires_at < datetime('now')") self.con.execute("INSERT INTO sessions(id_hache, user_id, expires_at) VALUES (?, ?, datetime('now', ?))", - (self._hache(portee + jeton), user["id"], "+%d days" % jours)) + (self._hache(portee + ":" + jeton), user["id"], "+%d days" % jours)) self.con.commit() return jeton @@ -59,10 +59,10 @@ class Forum: if not jeton: return None return self.con.execute("SELECT u.* FROM sessions s JOIN users u ON u.id=s.user_id" - " WHERE s.id_hache=? AND s.expires_at > datetime('now')", (self._hache(portee + jeton),)).fetchone() + " WHERE s.id_hache=? AND s.expires_at > datetime('now')", (self._hache(portee + ":" + jeton),)).fetchone() def fermer_session(self, jeton, portee=""): - self.con.execute("DELETE FROM sessions WHERE id_hache=?", (self._hache(portee + (jeton or "")),)) + self.con.execute("DELETE FROM sessions WHERE id_hache=?", (self._hache(portee + ":" + (jeton or "")),)) self.con.commit() def noter_etat(self, etat, verifier): diff --git a/forum/tests/test_forum.py b/forum/tests/test_forum.py index e29b8e8..fda03ec 100644 --- a/forum/tests/test_forum.py +++ b/forum/tests/test_forum.py @@ -391,7 +391,7 @@ class TestConnexionGastinel(BaseHTTP): u = self.f.con.execute("SELECT * FROM users WHERE hub_id='g-42'").fetchone() self.assertEqual(u["display_name"], "Lucie") stocke = self.f.con.execute("SELECT id_hache FROM sessions WHERE user_id=?", (u["id"],)).fetchone()[0] - self.assertEqual(stocke, hashlib.sha256(jeton.encode()).hexdigest()) # seul le haché est en base + self.assertEqual(stocke, hashlib.sha256((":" + jeton).encode()).hexdigest()) # seul le haché est en base b = self.req("/", cookie="forum_session=" + jeton)[2].decode() self.assertIn("Lucie", b) self.assertIn("action='/deconnexion'", b)