Rocket/core/lib/tests/form_method-issue-45.rs
Sergio Benitez 5d9035ddc1 Keep an op-log for sync 'CookieJar'.
In brief, this commit:

  * Updates to the latest upstream 'cookie', fixing a memory leak.
  * Make changes to 'CookieJar' observable only through 'pending()'.
  * Deprecates 'Client::new()' in favor of 'Client::tracked()'.
  * Makes 'dispatch()' on tracked 'Client's synchronize on cookies.
  * Makes 'Client::untracked()' actually untracked.

This commit updates to the latest 'cookie' which removes support for
'Sync' cookie jars. Instead of relying on 'cookie', this commit
implements an op-log based 'CookieJar' which internally keeps track of
changes. The API is such that changes are only observable through
specialized '_pending()' methods.
2020-10-14 21:37:16 -07:00

43 lines
1.1 KiB
Rust

#[macro_use] extern crate rocket;
use rocket::request::Form;
#[derive(FromForm)]
struct FormData {
form_data: String,
}
#[patch("/", data = "<form_data>")]
fn bug(form_data: Form<FormData>) -> &'static str {
assert_eq!("Form data", form_data.form_data);
"OK"
}
mod tests {
use super::*;
use rocket::local::blocking::Client;
use rocket::http::{Status, ContentType};
#[test]
fn method_eval() {
let client = Client::tracked(rocket::ignite().mount("/", routes![bug])).unwrap();
let response = client.post("/")
.header(ContentType::Form)
.body("_method=patch&form_data=Form+data")
.dispatch();
assert_eq!(response.into_string(), Some("OK".into()));
}
#[test]
fn get_passes_through() {
let client = Client::tracked(rocket::ignite().mount("/", routes![bug])).unwrap();
let response = client.get("/")
.header(ContentType::Form)
.body("_method=patch&form_data=Form+data")
.dispatch();
assert_eq!(response.status(), Status::NotFound);
}
}