2021-04-22 17:13:13 +00:00
|
|
|
use actix_files::Files;
|
|
|
|
use actix_web::{
|
|
|
|
guard::Host,
|
|
|
|
http::StatusCode,
|
|
|
|
test::{self, TestRequest},
|
|
|
|
App,
|
|
|
|
};
|
|
|
|
use bytes::Bytes;
|
|
|
|
|
2021-10-19 16:30:32 +00:00
|
|
|
#[actix_web::test]
|
2021-04-22 17:13:13 +00:00
|
|
|
async fn test_guard_filter() {
|
|
|
|
let srv = test::init_service(
|
|
|
|
App::new()
|
|
|
|
.service(Files::new("/", "./tests/fixtures/guards/first").guard(Host("first.com")))
|
2023-07-17 01:38:12 +00:00
|
|
|
.service(Files::new("/", "./tests/fixtures/guards/second").guard(Host("second.com"))),
|
2021-04-22 17:13:13 +00:00
|
|
|
)
|
|
|
|
.await;
|
|
|
|
|
|
|
|
let req = TestRequest::with_uri("/index.txt")
|
|
|
|
.append_header(("Host", "first.com"))
|
|
|
|
.to_request();
|
|
|
|
let res = test::call_service(&srv, req).await;
|
|
|
|
|
|
|
|
assert_eq!(res.status(), StatusCode::OK);
|
|
|
|
assert_eq!(test::read_body(res).await, Bytes::from("first"));
|
|
|
|
|
|
|
|
let req = TestRequest::with_uri("/index.txt")
|
|
|
|
.append_header(("Host", "second.com"))
|
|
|
|
.to_request();
|
|
|
|
let res = test::call_service(&srv, req).await;
|
|
|
|
|
|
|
|
assert_eq!(res.status(), StatusCode::OK);
|
|
|
|
assert_eq!(test::read_body(res).await, Bytes::from("second"));
|
|
|
|
}
|