Skip to content

Commit c6ae8b9

Browse files
committed
strand-bui-backend-session: don't test expired cookie
1 parent 2f4bc91 commit c6ae8b9

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

strand-bui-backend-session/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ strand-cam-bui-types.workspace = true
3131

3232
[dev-dependencies]
3333
serde_json.workspace = true
34+
chrono.workspace = true

strand-bui-backend-session/src/lib.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,13 +449,28 @@ fn test_serialized_cookie_store() {
449449
// Test that we can upgrade `cookie_store` crate without invalidating on-disk stored cookies.
450450

451451
// Load CookieStore from json like we have previously saved to disk.
452-
let serialized_json = r#"[{"raw_cookie":"abc=def; Expires=Thu, 20 Nov 2025 12:19:29 GMT","path":["/",false],"domain":{"HostOnly":"127.0.0.1"},"expires":{"AtUtc":"2025-11-20T12:19:29Z"}}]"#;
453-
let loaded: cookie_store::CookieStore = serde_json::from_str(serialized_json).unwrap();
452+
let serialized_json1 = r#"[{"raw_cookie":"abc=def; Expires="#;
453+
let expires = chrono::Utc::now()
454+
.checked_add_signed(chrono::Duration::days(365))
455+
.unwrap();
456+
let expires_str1 = expires.format("%a, %d %b %Y %H:%M:%S GMT").to_string();
457+
// e.g. "Thu, 20 Nov 2025 12:19:29 GMT"
458+
let serialized_json2 =
459+
r#"","path":["/",false],"domain":{"HostOnly":"127.0.0.1"},"expires":{"AtUtc":""#;
460+
// e.g. "2025-11-20T12:19:29Z"
461+
let expires_str2 = expires.format("%Y-%m-%dT%H:%M:%SZ").to_string();
462+
let serialized_json3 = r#""}}]"#;
463+
let serialized_json = format!(
464+
"{}{}{}{}{}",
465+
serialized_json1, expires_str1, serialized_json2, expires_str2, serialized_json3
466+
);
467+
let loaded: cookie_store::CookieStore = serde_json::from_str(&serialized_json).unwrap();
454468

455469
// What do we expect?
456470
let expected = {
457471
let mut expected = cookie_store::CookieStore::new(None);
458-
let cookie_str = "abc=def; Expires=Thu, 20 Nov 2025 12:19:29 GMT";
472+
let cookie_str1 = "abc=def; Expires=";
473+
let cookie_str = format!("{}{}", cookie_str1, expires_str1);
459474
let request_url = "http://127.0.0.1/".try_into().unwrap();
460475

461476
let cookie = cookie_store::Cookie::parse(cookie_str, &request_url).unwrap();

0 commit comments

Comments
 (0)