From 9537fc7b321e9bdecd3d42fa4bab87c30b01ed77 Mon Sep 17 00:00:00 2001 From: Yong Wen Chua Date: Tue, 12 Mar 2019 14:17:52 +0800 Subject: [PATCH] Fix tests --- examples/fairing.rs | 2 +- examples/guard.rs | 2 +- examples/json.rs | 2 +- examples/manual.rs | 2 +- examples/mix.rs | 2 +- src/headers.rs | 4 ++-- src/lib.rs | 10 +++++----- tests/fairing.rs | 12 ++++++------ tests/guard.rs | 14 +++++++------- tests/headers.rs | 6 +++--- tests/manual.rs | 20 ++++++++++---------- tests/mix.rs | 14 +++++++------- 12 files changed, 45 insertions(+), 45 deletions(-) diff --git a/examples/fairing.rs b/examples/fairing.rs index 56cdd8d..814aa3c 100644 --- a/examples/fairing.rs +++ b/examples/fairing.rs @@ -16,7 +16,7 @@ fn main() -> Result<(), Error> { // You can also deserialize this let cors = rocket_cors::CorsOptions { - allowed_origins: allowed_origins, + allowed_origins, allowed_methods: vec![Method::Get].into_iter().map(From::from).collect(), allowed_headers: AllowedHeaders::some(&["Authorization", "Accept"]), allow_credentials: true, diff --git a/examples/guard.rs b/examples/guard.rs index cd3d2d0..b8faa39 100644 --- a/examples/guard.rs +++ b/examples/guard.rs @@ -40,7 +40,7 @@ fn main() -> Result<(), Error> { // You can also deserialize this let cors = rocket_cors::CorsOptions { - allowed_origins: allowed_origins, + allowed_origins, allowed_methods: vec![Method::Get].into_iter().map(From::from).collect(), allowed_headers: AllowedHeaders::some(&["Authorization", "Accept"]), allow_credentials: true, diff --git a/examples/json.rs b/examples/json.rs index e77c1d9..5cee758 100644 --- a/examples/json.rs +++ b/examples/json.rs @@ -16,7 +16,7 @@ fn main() { let allowed_origins = AllowedOrigins::some_exact(&["https://www.acme.com"]); let options = cors::CorsOptions { - allowed_origins: allowed_origins, + allowed_origins, allowed_methods: vec![Method::Get, Method::Post, Method::Delete] .into_iter() .map(From::from) diff --git a/examples/manual.rs b/examples/manual.rs index 0768d2e..db83c25 100644 --- a/examples/manual.rs +++ b/examples/manual.rs @@ -63,7 +63,7 @@ fn cors_options() -> CorsOptions { // You can also deserialize this rocket_cors::CorsOptions { - allowed_origins: allowed_origins, + allowed_origins, allowed_methods: vec![Method::Get].into_iter().map(From::from).collect(), allowed_headers: AllowedHeaders::some(&["Authorization", "Accept"]), allow_credentials: true, diff --git a/examples/mix.rs b/examples/mix.rs index 9bae94f..3f8d350 100644 --- a/examples/mix.rs +++ b/examples/mix.rs @@ -40,7 +40,7 @@ fn cors_options() -> CorsOptions { // You can also deserialize this rocket_cors::CorsOptions { - allowed_origins: allowed_origins, + allowed_origins, allowed_methods: vec![Method::Get].into_iter().map(From::from).collect(), allowed_headers: AllowedHeaders::some(&["Authorization", "Accept"]), allow_credentials: true, diff --git a/src/headers.rs b/src/headers.rs index b947fbf..6e0a099 100644 --- a/src/headers.rs +++ b/src/headers.rs @@ -266,7 +266,7 @@ mod tests { ); let method = "INVALID"; - let _ = is_err!(AccessControlRequestMethod::from_str(method)); + is_err!(AccessControlRequestMethod::from_str(method)); } #[test] @@ -308,7 +308,7 @@ mod tests { let parsed_header = assert_matches!(outcome, Outcome::Success(s), s); let AccessControlRequestHeaders(parsed_headers) = parsed_header; let mut parsed_headers: Vec = - parsed_headers.iter().map(|s| s.to_string()).collect(); + parsed_headers.iter().map(ToString::to_string).collect(); parsed_headers.sort(); assert_eq!( vec!["accept-language".to_string(), "date".to_string()], diff --git a/src/lib.rs b/src/lib.rs index a7e323e..f845c52 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -727,9 +727,9 @@ impl AllowedHeaders { /// ```json /// { /// "allowed_origins": { -/// "Some": [ -/// "https://www.acme.com" -/// ] +/// "Some": { +/// "exact": ["https://www.acme.com"] +/// } /// }, /// "allowed_methods": [ /// "POST", @@ -1759,8 +1759,8 @@ mod tests { allowed_headers: AllowedHeaders::some(&[&"Authorization", "Accept"]), allow_credentials: true, expose_headers: ["Content-Type", "X-Custom"] - .into_iter() - .map(|s| s.to_string().into()) + .iter() + .map(|s| s.to_string()) .collect(), ..Default::default() } diff --git a/tests/fairing.rs b/tests/fairing.rs index 943cb26..055e015 100644 --- a/tests/fairing.rs +++ b/tests/fairing.rs @@ -1,14 +1,14 @@ //! This crate tests using `rocket_cors` using Fairings #![feature(proc_macro_hygiene, decl_macro)] use hyper; -#[macro_use] -extern crate rocket; use std::str::FromStr; use rocket::http::Method; use rocket::http::{Header, Status}; use rocket::local::Client; +use rocket::response::Body; +use rocket::{get, routes}; use rocket_cors::*; #[get("/")] @@ -25,7 +25,7 @@ fn make_cors() -> Cors { let allowed_origins = AllowedOrigins::some_exact(&["https://www.acme.com"]); CorsOptions { - allowed_origins: allowed_origins, + allowed_origins, allowed_methods: vec![Method::Get].into_iter().map(From::from).collect(), allowed_headers: AllowedHeaders::some(&["Authorization", "Accept"]), allow_credentials: true, @@ -73,7 +73,7 @@ fn smoke_test() { let mut response = req.dispatch(); assert!(response.status().class().is_success()); - let body_str = response.body().and_then(|body| body.into_string()); + let body_str = response.body().and_then(Body::into_string); assert_eq!(body_str, Some("Hello CORS".to_string())); let origin_header = response @@ -124,7 +124,7 @@ fn cors_get_check() { let mut response = req.dispatch(); assert!(response.status().class().is_success()); - let body_str = response.body().and_then(|body| body.into_string()); + let body_str = response.body().and_then(Body::into_string); assert_eq!(body_str, Some("Hello CORS".to_string())); let origin_header = response @@ -144,7 +144,7 @@ fn cors_get_no_origin() { let mut response = req.dispatch(); assert!(response.status().class().is_success()); - let body_str = response.body().and_then(|body| body.into_string()); + let body_str = response.body().and_then(Body::into_string); assert_eq!(body_str, Some("Hello CORS".to_string())); } diff --git a/tests/guard.rs b/tests/guard.rs index c3010e4..d929616 100644 --- a/tests/guard.rs +++ b/tests/guard.rs @@ -1,8 +1,6 @@ //! This crate tests using `rocket_cors` using the per-route handling with request guard #![feature(proc_macro_hygiene, decl_macro)] use hyper; -#[macro_use] -extern crate rocket; use rocket_cors as cors; use std::str::FromStr; @@ -10,6 +8,8 @@ use std::str::FromStr; use rocket::http::Method; use rocket::http::{Header, Status}; use rocket::local::Client; +use rocket::response::Body; +use rocket::{get, options, routes}; use rocket::{Response, State}; #[get("/")] @@ -63,7 +63,7 @@ fn make_cors() -> cors::Cors { let allowed_origins = cors::AllowedOrigins::some_exact(&["https://www.acme.com"]); cors::CorsOptions { - allowed_origins: allowed_origins, + allowed_origins, allowed_methods: vec![Method::Get].into_iter().map(From::from).collect(), allowed_headers: cors::AllowedHeaders::some(&["Authorization", "Accept"]), allow_credentials: true, @@ -119,7 +119,7 @@ fn smoke_test() { let mut response = req.dispatch(); assert!(response.status().class().is_success()); - let body_str = response.body().and_then(|body| body.into_string()); + let body_str = response.body().and_then(Body::into_string); assert_eq!(body_str, Some("Hello CORS".to_string())); let origin_header = response @@ -205,7 +205,7 @@ fn cors_get_check() { let mut response = req.dispatch(); assert!(response.status().class().is_success()); - let body_str = response.body().and_then(|body| body.into_string()); + let body_str = response.body().and_then(Body::into_string); assert_eq!(body_str, Some("Hello CORS".to_string())); let origin_header = response @@ -226,7 +226,7 @@ fn cors_get_no_origin() { let mut response = req.dispatch(); assert!(response.status().class().is_success()); - let body_str = response.body().and_then(|body| body.into_string()); + let body_str = response.body().and_then(Body::into_string); assert_eq!(body_str, Some("Hello CORS".to_string())); assert!(response .headers() @@ -408,7 +408,7 @@ fn overridden_options_routes_are_used() { .header(request_headers); let mut response = req.dispatch(); - let body_str = response.body().and_then(|body| body.into_string()); + let body_str = response.body().and_then(Body::into_string); assert!(response.status().class().is_success()); assert_eq!(body_str, Some("Manual CORS Preflight".to_string())); diff --git a/tests/headers.rs b/tests/headers.rs index c6b63f8..603c25c 100644 --- a/tests/headers.rs +++ b/tests/headers.rs @@ -1,14 +1,14 @@ //! This crate tests that all the request headers are parsed correctly in the round trip #![feature(proc_macro_hygiene, decl_macro)] use hyper; -#[macro_use] -extern crate rocket; use std::ops::Deref; use std::str::FromStr; use rocket::http::Header; use rocket::local::Client; +use rocket::response::Body; +use rocket::{get, routes}; use rocket_cors::headers::*; #[get("/request_headers")] @@ -53,7 +53,7 @@ fn request_headers_round_trip_smoke_test() { assert!(response.status().class().is_success()); let body_str = response .body() - .and_then(|body| body.into_string()) + .and_then(Body::into_string) .expect("Non-empty body"); let expected_body = r#"https://foo.bar.xyz GET diff --git a/tests/manual.rs b/tests/manual.rs index 54b08ba..db4cc83 100644 --- a/tests/manual.rs +++ b/tests/manual.rs @@ -1,8 +1,6 @@ //! This crate tests using `rocket_cors` using manual mode #![feature(proc_macro_hygiene, decl_macro)] use hyper; -#[macro_use] -extern crate rocket; use std::str::FromStr; @@ -11,6 +9,8 @@ use rocket::http::{Header, Status}; use rocket::local::Client; use rocket::response::Responder; use rocket::State; +use rocket::{get, options, routes}; +use rocket::response::Body; use rocket_cors::*; /// Using a borrowed `Cors` @@ -23,7 +23,7 @@ fn cors(options: State<'_, Cors>) -> impl Responder<'_> { #[get("/panic")] fn panicking_route(options: State<'_, Cors>) -> impl Responder<'_> { - options.inner().respond_borrowed(|_| -> () { + options.inner().respond_borrowed(|_| { panic!("This route will panic"); }) } @@ -69,7 +69,7 @@ fn make_cors_options() -> CorsOptions { let allowed_origins = AllowedOrigins::some_exact(&["https://www.acme.com"]); CorsOptions { - allowed_origins: allowed_origins, + allowed_origins, allowed_methods: vec![Method::Get].into_iter().map(From::from).collect(), allowed_headers: AllowedHeaders::some(&["Authorization", "Accept"]), allow_credentials: true, @@ -81,7 +81,7 @@ fn make_different_cors_options() -> CorsOptions { let allowed_origins = AllowedOrigins::some_exact(&["https://www.example.com"]); CorsOptions { - allowed_origins: allowed_origins, + allowed_origins, allowed_methods: vec![Method::Get].into_iter().map(From::from).collect(), allowed_headers: AllowedHeaders::some(&["Authorization", "Accept"]), allow_credentials: true, @@ -129,7 +129,7 @@ fn smoke_test() { let mut response = req.dispatch(); assert!(response.status().class().is_success()); - let body_str = response.body().and_then(|body| body.into_string()); + let body_str = response.body().and_then(Body::into_string); assert_eq!(body_str, Some("Hello CORS".to_string())); let origin_header = response @@ -180,7 +180,7 @@ fn cors_get_borrowed_check() { let mut response = req.dispatch(); assert!(response.status().class().is_success()); - let body_str = response.body().and_then(|body| body.into_string()); + let body_str = response.body().and_then(Body::into_string); assert_eq!(body_str, Some("Hello CORS".to_string())); let origin_header = response @@ -200,7 +200,7 @@ fn cors_get_no_origin() { let mut response = req.dispatch(); assert!(response.status().class().is_success()); - let body_str = response.body().and_then(|body| body.into_string()); + let body_str = response.body().and_then(Body::into_string); assert_eq!(body_str, Some("Hello CORS".to_string())); } @@ -378,7 +378,7 @@ fn cors_options_owned_check() { .header(request_headers); let mut response = req.dispatch(); - let body_str = response.body().and_then(|body| body.into_string()); + let body_str = response.body().and_then(Body::into_string); assert!(response.status().class().is_success()); assert_eq!(body_str, Some("Manual CORS Preflight".to_string())); @@ -404,7 +404,7 @@ fn cors_get_owned_check() { let mut response = req.dispatch(); assert!(response.status().class().is_success()); - let body_str = response.body().and_then(|body| body.into_string()); + let body_str = response.body().and_then(Body::into_string); assert_eq!(body_str, Some("Hello CORS Owned".to_string())); let origin_header = response diff --git a/tests/mix.rs b/tests/mix.rs index 25dd65a..08ffbf0 100644 --- a/tests/mix.rs +++ b/tests/mix.rs @@ -4,15 +4,15 @@ //! `ping` route that you want to allow all Origins to access. #![feature(proc_macro_hygiene, decl_macro)] use hyper; -#[macro_use] -extern crate rocket; use rocket_cors; use std::str::FromStr; use rocket::http::{Header, Method, Status}; use rocket::local::Client; +use rocket::response::Body; use rocket::response::Responder; +use rocket::{get, options, routes}; use rocket_cors::{AllowedHeaders, AllowedOrigins, CorsOptions, Guard}; @@ -44,7 +44,7 @@ fn cors_options() -> CorsOptions { // You can also deserialize this rocket_cors::CorsOptions { - allowed_origins: allowed_origins, + allowed_origins, allowed_methods: vec![Method::Get].into_iter().map(From::from).collect(), allowed_headers: AllowedHeaders::some(&["Authorization", "Accept"]), allow_credentials: true, @@ -100,7 +100,7 @@ fn smoke_test() { let mut response = req.dispatch(); assert!(response.status().class().is_success()); - let body_str = response.body().and_then(|body| body.into_string()); + let body_str = response.body().and_then(Body::into_string); assert_eq!(body_str, Some("Hello CORS!".to_string())); let origin_header = response @@ -151,7 +151,7 @@ fn cors_get_check() { let mut response = req.dispatch(); assert!(response.status().class().is_success()); - let body_str = response.body().and_then(|body| body.into_string()); + let body_str = response.body().and_then(Body::into_string); assert_eq!(body_str, Some("Hello CORS!".to_string())); let origin_header = response @@ -171,7 +171,7 @@ fn cors_get_no_origin() { let mut response = req.dispatch(); assert!(response.status().class().is_success()); - let body_str = response.body().and_then(|body| body.into_string()); + let body_str = response.body().and_then(Body::into_string); assert_eq!(body_str, Some("Hello CORS!".to_string())); } @@ -333,7 +333,7 @@ fn cors_get_ping_check() { let mut response = req.dispatch(); assert!(response.status().class().is_success()); - let body_str = response.body().and_then(|body| body.into_string()); + let body_str = response.body().and_then(Body::into_string); assert_eq!(body_str, Some("Pong!".to_string())); let origin_header = response