Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async: blocking client API #1346

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions contrib/lib/src/templates/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,20 +328,18 @@ impl Template {
/// use std::collections::HashMap;
///
/// use rocket_contrib::templates::Template;
/// use rocket::local::Client;
/// use rocket::local::blocking::Client;
///
/// fn main() {
/// # rocket::async_test(async {
/// let rocket = rocket::ignite().attach(Template::fairing());
/// let client = Client::new(rocket).await.expect("valid rocket");
/// let client = Client::new(rocket).expect("valid rocket");
///
/// // Create a `context`. Here, just an empty `HashMap`.
/// let mut context = HashMap::new();
///
/// # context.insert("test", "test");
/// # #[allow(unused_variables)]
/// let template = Template::show(client.cargo(), "index", context);
/// # });
/// }
/// ```
#[inline]
Expand Down
18 changes: 9 additions & 9 deletions contrib/lib/tests/compress_responder.rs.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod compress_responder_tests {
use rocket::http::hyper::header::{ContentEncoding, Encoding};
use rocket::http::Status;
use rocket::http::{ContentType, Header};
use rocket::local::Client;
use rocket::local::blocking::Client;
use rocket::response::{Content, Response};
use rocket_contrib::compression::Compress;

Expand Down Expand Up @@ -80,7 +80,7 @@ mod compress_responder_tests {
.any(|x| x == "br"));
let mut body_plain = Cursor::new(Vec::<u8>::new());
brotli::BrotliDecompress(
&mut Cursor::new(response.body_bytes().unwrap()),
&mut Cursor::new(response.into_bytes().unwrap()),
&mut body_plain,
)
.expect("decompress response");
Expand All @@ -104,7 +104,7 @@ mod compress_responder_tests {
.any(|x| x == "br"));
let mut body_plain = Cursor::new(Vec::<u8>::new());
brotli::BrotliDecompress(
&mut Cursor::new(response.body_bytes().unwrap()),
&mut Cursor::new(response.into_bytes().unwrap()),
&mut body_plain,
)
.expect("decompress response");
Expand All @@ -131,7 +131,7 @@ mod compress_responder_tests {
.get("Content-Encoding")
.any(|x| x == "gzip"));
let mut s = String::new();
GzDecoder::new(&response.body_bytes().unwrap()[..])
GzDecoder::new(&response.into_bytes().unwrap()[..])
.read_to_string(&mut s)
.expect("decompress response");
assert_eq!(s, String::from(HELLO));
Expand All @@ -154,7 +154,7 @@ mod compress_responder_tests {
.get("Content-Encoding")
.any(|x| x == "gzip"));
let mut s = String::new();
GzDecoder::new(&response.body_bytes().unwrap()[..])
GzDecoder::new(&response.into_bytes().unwrap()[..])
.read_to_string(&mut s)
.expect("decompress response");
assert_eq!(s, String::from(HELLO));
Expand All @@ -173,7 +173,7 @@ mod compress_responder_tests {
.get("Content-Encoding")
.any(|x| x != "identity"));
assert_eq!(
String::from_utf8(response.body_bytes().unwrap()).unwrap(),
String::from_utf8(response.into_bytes().unwrap()).unwrap(),
String::from(HELLO)
);
}
Expand All @@ -192,7 +192,7 @@ mod compress_responder_tests {
.any(|x| x == "br"));
let mut body_plain = Cursor::new(Vec::<u8>::new());
brotli::BrotliDecompress(
&mut Cursor::new(response.body_bytes().unwrap()),
&mut Cursor::new(response.into_bytes().unwrap()),
&mut body_plain,
)
.expect("decompress response");
Expand All @@ -215,7 +215,7 @@ mod compress_responder_tests {
.get("Content-Encoding")
.any(|x| x != "identity"));
assert_eq!(
String::from_utf8(response.body_bytes().unwrap()).unwrap(),
String::from_utf8(response.into_bytes().unwrap()).unwrap(),
String::from(HELLO)
);
}
Expand All @@ -233,7 +233,7 @@ mod compress_responder_tests {
.get("Content-Encoding")
.any(|x| x != "identity"));
assert_eq!(
String::from_utf8(response.body_bytes().unwrap()).unwrap(),
String::from_utf8(response.into_bytes().unwrap()).unwrap(),
String::from(HELLO)
);
}
Expand Down
22 changes: 11 additions & 11 deletions contrib/lib/tests/compression_fairing.rs.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod compression_fairing_tests {
use rocket::http::hyper::header::{ContentEncoding, Encoding};
use rocket::http::Status;
use rocket::http::{ContentType, Header};
use rocket::local::Client;
use rocket::local::blocking::Client;
use rocket::response::{Content, Response};
use rocket_contrib::compression::Compression;

Expand Down Expand Up @@ -99,7 +99,7 @@ mod compression_fairing_tests {
.any(|x| x == "br"));
let mut body_plain = Cursor::new(Vec::<u8>::new());
brotli::BrotliDecompress(
&mut Cursor::new(response.body_bytes().unwrap()),
&mut Cursor::new(response.into_bytes().unwrap()),
&mut body_plain,
)
.expect("decompress response");
Expand All @@ -123,7 +123,7 @@ mod compression_fairing_tests {
.any(|x| x == "br"));
let mut body_plain = Cursor::new(Vec::<u8>::new());
brotli::BrotliDecompress(
&mut Cursor::new(response.body_bytes().unwrap()),
&mut Cursor::new(response.into_bytes().unwrap()),
&mut body_plain,
)
.expect("decompress response");
Expand All @@ -150,7 +150,7 @@ mod compression_fairing_tests {
.get("Content-Encoding")
.any(|x| x == "gzip"));
let mut s = String::new();
GzDecoder::new(&response.body_bytes().unwrap()[..])
GzDecoder::new(&response.into_bytes().unwrap()[..])
.read_to_string(&mut s)
.expect("decompress response");
assert_eq!(s, String::from(HELLO));
Expand All @@ -173,7 +173,7 @@ mod compression_fairing_tests {
.get("Content-Encoding")
.any(|x| x == "gzip"));
let mut s = String::new();
GzDecoder::new(&response.body_bytes().unwrap()[..])
GzDecoder::new(&response.into_bytes().unwrap()[..])
.read_to_string(&mut s)
.expect("decompress response");
assert_eq!(s, String::from(HELLO));
Expand All @@ -192,7 +192,7 @@ mod compression_fairing_tests {
.get("Content-Encoding")
.any(|x| x != "identity"));
assert_eq!(
String::from_utf8(response.body_bytes().unwrap()).unwrap(),
String::from_utf8(response.into_bytes().unwrap()).unwrap(),
String::from(HELLO)
);
}
Expand All @@ -210,7 +210,7 @@ mod compression_fairing_tests {
.get("Content-Encoding")
.any(|x| x != "identity"));
assert_eq!(
String::from_utf8(response.body_bytes().unwrap()).unwrap(),
String::from_utf8(response.into_bytes().unwrap()).unwrap(),
String::from(HELLO)
);
}
Expand All @@ -228,7 +228,7 @@ mod compression_fairing_tests {
.get("Content-Encoding")
.any(|x| x != "identity"));
assert_eq!(
String::from_utf8(response.body_bytes().unwrap()).unwrap(),
String::from_utf8(response.into_bytes().unwrap()).unwrap(),
String::from(HELLO)
);
}
Expand All @@ -246,7 +246,7 @@ mod compression_fairing_tests {
.get("Content-Encoding")
.any(|x| x != "identity"));
assert_eq!(
String::from_utf8(response.body_bytes().unwrap()).unwrap(),
String::from_utf8(response.into_bytes().unwrap()).unwrap(),
String::from(HELLO)
);
}
Expand All @@ -264,7 +264,7 @@ mod compression_fairing_tests {
.get("Content-Encoding")
.any(|x| x != "identity"));
assert_eq!(
String::from_utf8(response.body_bytes().unwrap()).unwrap(),
String::from_utf8(response.into_bytes().unwrap()).unwrap(),
String::from(HELLO)
);
}
Expand All @@ -283,7 +283,7 @@ mod compression_fairing_tests {
.any(|x| x == "br"));
let mut body_plain = Cursor::new(Vec::<u8>::new());
brotli::BrotliDecompress(
&mut Cursor::new(response.body_bytes().unwrap()),
&mut Cursor::new(response.into_bytes().unwrap()),
&mut body_plain,
)
.expect("decompress response");
Expand Down
22 changes: 11 additions & 11 deletions contrib/lib/tests/helmet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extern crate rocket;
#[cfg(feature = "helmet")]
mod helmet_tests {
use rocket::http::{Status, uri::Uri};
use rocket::local::{Client, LocalResponse};
use rocket::local::blocking::{Client, LocalResponse};

use rocket_contrib::helmet::*;
use time::Duration;
Expand All @@ -34,24 +34,24 @@ mod helmet_tests {
macro_rules! dispatch {
($helmet:expr, $closure:expr) => {{
let rocket = rocket::ignite().mount("/", routes![hello]).attach($helmet);
let client = Client::new(rocket).await.unwrap();
let response = client.get("/").dispatch().await;
let client = Client::new(rocket).unwrap();
let response = client.get("/").dispatch();
assert_eq!(response.status(), Status::Ok);
$closure(response)
}}
}

#[rocket::async_test]
async fn default_headers_test() {
#[test]
fn default_headers_test() {
dispatch!(SpaceHelmet::default(), |response: LocalResponse<'_>| {
assert_header!(response, "X-XSS-Protection", "1");
assert_header!(response, "X-Frame-Options", "SAMEORIGIN");
assert_header!(response, "X-Content-Type-Options", "nosniff");
})
}

#[rocket::async_test]
async fn disable_headers_test() {
#[test]
fn disable_headers_test() {
let helmet = SpaceHelmet::default().disable::<XssFilter>();
dispatch!(helmet, |response: LocalResponse<'_>| {
assert_header!(response, "X-Frame-Options", "SAMEORIGIN");
Expand Down Expand Up @@ -84,8 +84,8 @@ mod helmet_tests {
});
}

#[rocket::async_test]
async fn additional_headers_test() {
#[test]
fn additional_headers_test() {
let helmet = SpaceHelmet::default()
.enable(Hsts::default())
.enable(ExpectCt::default())
Expand All @@ -108,8 +108,8 @@ mod helmet_tests {
})
}

#[rocket::async_test]
async fn uri_test() {
#[test]
fn uri_test() {
let allow_uri = Uri::parse("https://www.google.com").unwrap();
let report_uri = Uri::parse("https://www.google.com").unwrap();
let enforce_uri = Uri::parse("https://www.google.com").unwrap();
Expand Down
Loading