Fix tests

This commit is contained in:
Yong Wen Chua 2019-03-12 14:17:52 +08:00
parent 3349c972cf
commit 9537fc7b32
No known key found for this signature in database
GPG Key ID: A70BD30B21497EA9
12 changed files with 45 additions and 45 deletions

View File

@ -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,

View File

@ -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,

View File

@ -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)

View File

@ -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,

View File

@ -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,

View File

@ -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<String> =
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()],

View File

@ -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()
}

View File

@ -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()));
}

View File

@ -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()));

View File

@ -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

View File

@ -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

View File

@ -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