mirror of
https://github.com/rwf2/Rocket.git
synced 2024-12-29 05:42:35 +00:00
ad36b769bc
...because loading up a Rocket while it's ignited is a bad idea. More seriously, because 'Rocket.ignite()' will become an "execute everything up to here" method.
25 lines
685 B
Rust
25 lines
685 B
Rust
#![cfg(feature = "secrets")]
|
|
|
|
use rocket::http::{CookieJar, Cookie};
|
|
|
|
#[rocket::get("/")]
|
|
fn index(jar: &CookieJar<'_>) {
|
|
let session_cookie = Cookie::build("key", "value").expires(None);
|
|
jar.add_private(session_cookie.finish());
|
|
}
|
|
|
|
mod test_session_cookies {
|
|
use super::*;
|
|
use rocket::local::blocking::Client;
|
|
|
|
#[test]
|
|
fn session_cookie_is_session() {
|
|
let rocket = rocket::build().mount("/", rocket::routes![index]);
|
|
let client = Client::debug(rocket).unwrap();
|
|
|
|
let response = client.get("/").dispatch();
|
|
let cookie = response.cookies().get_private("key").unwrap();
|
|
assert_eq!(cookie.expires_datetime(), None);
|
|
}
|
|
}
|