v3 : relecture de cf634c2 — renouvellement sans effet sur la réponse, lien en attente fermé avec les sessions

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Yvv
2026-10-23 09:02:26 +02:00
co-authored by Claude Opus 5.5
parent cf634c25d2
commit decbc0ba7b
9 changed files with 107 additions and 30 deletions
+39 -2
View File
@@ -497,6 +497,27 @@ async fn a_session_lasts_until_it_is_closed() {
.await
.expect("count");
assert_eq!(far, 1);
let seen: i64 = sqlx::query_scalar(
"SELECT COUNT(*) FROM identities WHERE id = 'dev:chiara' AND last_seen_at > strftime('%Y-%m-%dT%H:%M:%SZ', 'now', '-1 minute')",
)
.fetch_one(&state.db)
.await
.expect("count");
assert_eq!(seen, 1, "the renewal says when the person was last seen");
// A session already over does not come back.
let mut old = chiara.with(None);
old.login("Chiara", false).await;
let old_cookie = old.cookie.clone();
sqlx::query(
"UPDATE sessions SET expires_at = strftime('%Y-%m-%dT%H:%M:%SZ', 'now', '-1 day')
WHERE rowid = (SELECT MAX(rowid) FROM sessions)",
)
.execute(&state.db)
.await
.expect("end the session");
let (_, v) = old.call("GET", "/api/me", None).await;
assert_eq!((v["me"].clone(), old.set_cookie.clone()), (Value::Null, None));
assert_eq!(old.cookie, old_cookie);
// Until an administrator closes them: a lost device, a person who left.
let mut phone = chiara.with(None);
@@ -508,15 +529,31 @@ async fn a_session_lasts_until_it_is_closed() {
let sessions_of = |ov: &Value, id: &str| {
ov["identities"].as_array().expect("i").iter().find(|i| i["id"] == id).expect("identity")["sessions"].clone()
};
// A sign-in link sent to the lost device goes with the sessions.
sqlx::query(
"INSERT INTO invitations (token_hash, label, admin, groups, created_by, created_at, expires_at, identity_id)
VALUES ('waiting', 'Chiara', 0, '[]', 'dev:yvv', strftime('%Y-%m-%dT%H:%M:%SZ', 'now'),
strftime('%Y-%m-%dT%H:%M:%SZ', 'now', '+14 days'), 'dev:chiara')",
)
.execute(&state.db)
.await
.expect("a sign-in link waiting");
let (_, ov) = admin.call("GET", "/api/access", None).await;
assert_eq!(sessions_of(&ov, "dev:chiara"), 2);
assert_eq!(sessions_of(&ov, "dev:chiara"), 2, "the session already over is not counted");
assert_eq!(sessions_of(&ov, "dev:yvv"), 0, "the session this page is read with is not counted");
let (s, v) = admin.call("DELETE", "/api/access/identities/dev:chiara/sessions", None).await;
assert_eq!((s, v["closed"].as_u64()), (StatusCode::OK, Some(2)));
assert_eq!((s, v["closed"].as_u64(), v["links"].as_u64()), (StatusCode::OK, Some(2), Some(1)));
for c in [&mut chiara, &mut phone] {
let (_, v) = c.call("GET", "/api/me", None).await;
assert_eq!(v["me"], Value::Null);
}
let waiting: i64 = sqlx::query_scalar(
"SELECT COUNT(*) FROM invitations WHERE token_hash = 'waiting' AND expires_at > strftime('%Y-%m-%dT%H:%M:%SZ', 'now')",
)
.fetch_one(&state.db)
.await
.expect("count");
assert_eq!(waiting, 0);
// An administrator's own: the others close, this one stays open.
let mut laptop = admin.with(None);
laptop.login("Yvv", true).await;