Cotton code
27 lines · 1.5 KB · RustRaw
//! Invented cookies only: no profile is opened.use super::holds_session;use serde_json::json;const NOW: f64 = 1_800_000_000.0;/// RULE: A profile is signed in to a site when it holds a live cookie of the/// definition's session name for the site's host or a parent domain — and/// presence is all the broker answers: never a value, never another cookie's/// name. An expired, empty, other-domain or look-alike-domain cookie is not/// a session.#[test]fn a_session_is_a_live_named_cookie_for_the_sites_domain() {    let cookie = |name: &str, domain: &str, value: &str, expires: f64| {        json!({"name": name, "domain": domain, "value": value, "expires": expires})    };    let held = |cookies: serde_json::Value| holds_session(&cookies, "www.example-food.test", "session", NOW);    assert!(held(json!([cookie("session", ".example-food.test", "invented", -1.0)])));    assert!(held(json!([cookie("session", "www.example-food.test", "invented", NOW + 60.0)])));    assert!(!held(json!([cookie("session", ".example-food.test", "invented", NOW - 60.0)])), "expired");    assert!(!held(json!([cookie("session", ".example-food.test", "", -1.0)])), "emptied on sign-out");    assert!(!held(json!([cookie("other", ".example-food.test", "invented", -1.0)])), "another cookie");    assert!(!held(json!([cookie("session", ".elsewhere.test", "invented", -1.0)])), "another site");    assert!(!held(json!([cookie("session", "ample-food.test", "invented", -1.0)])), "a look-alike domain");    assert!(!held(json!([])));    assert!(!held(json!(null)));}