1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2025-04-06 10:09:44 +00:00

update/add tests for new HostGuard implementation

This commit is contained in:
Anton Lazarev 2019-07-18 09:37:32 -07:00
parent c995fbc05d
commit b2098922bd
No known key found for this signature in database
GPG key ID: FBD20243E0CD9104

View file

@ -341,21 +341,64 @@ mod tests {
assert!(!pred.check(req.head()));
}
// #[test]
// fn test_host() {
// let req = TestServiceRequest::default()
// .header(
// header::HOST,
// header::HeaderValue::from_static("www.rust-lang.org"),
// )
// .request();
#[test]
fn test_host() {
let req = TestRequest::default()
.header(
header::HOST,
header::HeaderValue::from_static("www.rust-lang.org"),
)
.to_http_request();
// let pred = Host("www.rust-lang.org");
// assert!(pred.check(&req));
let pred = Host("www.rust-lang.org");
assert!(pred.check(req.head()));
// let pred = Host("localhost");
// assert!(!pred.check(&req));
// }
let pred = Host("www.rust-lang.org").scheme("https");
assert!(pred.check(req.head()));
let pred = Host("blog.rust-lang.org");
assert!(!pred.check(req.head()));
let pred = Host("blog.rust-lang.org").scheme("https");
assert!(!pred.check(req.head()));
let pred = Host("crates.io");
assert!(!pred.check(req.head()));
let pred = Host("localhost");
assert!(!pred.check(req.head()));
}
#[test]
fn test_host_scheme() {
let req = TestRequest::default()
.header(
header::HOST,
header::HeaderValue::from_static("https://www.rust-lang.org"),
)
.to_http_request();
let pred = Host("www.rust-lang.org").scheme("https");
assert!(pred.check(req.head()));
let pred = Host("www.rust-lang.org");
assert!(pred.check(req.head()));
let pred = Host("www.rust-lang.org").scheme("http");
assert!(!pred.check(req.head()));
let pred = Host("blog.rust-lang.org");
assert!(!pred.check(req.head()));
let pred = Host("blog.rust-lang.org").scheme("https");
assert!(!pred.check(req.head()));
let pred = Host("crates.io").scheme("https");
assert!(!pred.check(req.head()));
let pred = Host("localhost");
assert!(!pred.check(req.head()));
}
#[test]
fn test_methods() {