mirror of
https://github.com/ntex-rs/ntex-extras.git
synced 2025-04-04 13:27:41 +03:00
Update tests
This commit is contained in:
parent
17108a6294
commit
1270f0c8a6
3 changed files with 14 additions and 14 deletions
|
@ -787,7 +787,7 @@ where
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use ntex::service::{fn_service, Container, Middleware};
|
use ntex::service::{fn_service, Middleware, Pipeline};
|
||||||
use ntex::web::{self, test, test::TestRequest};
|
use ntex::web::{self, test, test::TestRequest};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -821,7 +821,7 @@ mod tests {
|
||||||
|
|
||||||
#[ntex::test]
|
#[ntex::test]
|
||||||
async fn test_preflight() {
|
async fn test_preflight() {
|
||||||
let mut cors: Container<_> = Cors::new()
|
let mut cors: Pipeline<_> = Cors::new()
|
||||||
.send_wildcard()
|
.send_wildcard()
|
||||||
.max_age(3600)
|
.max_age(3600)
|
||||||
.allowed_methods(vec![Method::GET, Method::OPTIONS, Method::POST])
|
.allowed_methods(vec![Method::GET, Method::OPTIONS, Method::POST])
|
||||||
|
@ -836,8 +836,8 @@ mod tests {
|
||||||
.header(header::ACCESS_CONTROL_REQUEST_HEADERS, "X-Not-Allowed")
|
.header(header::ACCESS_CONTROL_REQUEST_HEADERS, "X-Not-Allowed")
|
||||||
.to_srv_request();
|
.to_srv_request();
|
||||||
|
|
||||||
assert!(cors.inner.validate_allowed_method(req.head()).is_err());
|
assert!(cors.get_ref().inner.validate_allowed_method(req.head()).is_err());
|
||||||
assert!(cors.inner.validate_allowed_headers(req.head()).is_err());
|
assert!(cors.get_ref().inner.validate_allowed_headers(req.head()).is_err());
|
||||||
let resp = test::call_service(&cors, req).await;
|
let resp = test::call_service(&cors, req).await;
|
||||||
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
|
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
|
||||||
|
|
||||||
|
@ -846,8 +846,8 @@ mod tests {
|
||||||
.method(Method::OPTIONS)
|
.method(Method::OPTIONS)
|
||||||
.to_srv_request();
|
.to_srv_request();
|
||||||
|
|
||||||
assert!(cors.inner.validate_allowed_method(req.head()).is_err());
|
assert!(cors.get_ref().inner.validate_allowed_method(req.head()).is_err());
|
||||||
assert!(cors.inner.validate_allowed_headers(req.head()).is_ok());
|
assert!(cors.get_ref().inner.validate_allowed_headers(req.head()).is_ok());
|
||||||
|
|
||||||
let req = TestRequest::with_header("Origin", "https://www.example.com")
|
let req = TestRequest::with_header("Origin", "https://www.example.com")
|
||||||
.header(header::ACCESS_CONTROL_REQUEST_METHOD, "POST")
|
.header(header::ACCESS_CONTROL_REQUEST_METHOD, "POST")
|
||||||
|
@ -905,7 +905,7 @@ mod tests {
|
||||||
#[ntex::test]
|
#[ntex::test]
|
||||||
#[should_panic(expected = "OriginNotAllowed")]
|
#[should_panic(expected = "OriginNotAllowed")]
|
||||||
async fn test_validate_not_allowed_origin() {
|
async fn test_validate_not_allowed_origin() {
|
||||||
let cors: Container<_> = Cors::new()
|
let cors: Pipeline<_> = Cors::new()
|
||||||
.allowed_origin("https://www.example.com")
|
.allowed_origin("https://www.example.com")
|
||||||
.finish()
|
.finish()
|
||||||
.create(test::ok_service::<web::DefaultError>())
|
.create(test::ok_service::<web::DefaultError>())
|
||||||
|
@ -914,9 +914,9 @@ mod tests {
|
||||||
let req = TestRequest::with_header("Origin", "https://www.unknown.com")
|
let req = TestRequest::with_header("Origin", "https://www.unknown.com")
|
||||||
.method(Method::GET)
|
.method(Method::GET)
|
||||||
.to_srv_request();
|
.to_srv_request();
|
||||||
cors.inner.validate_origin(req.head()).unwrap();
|
cors.get_ref().inner.validate_origin(req.head()).unwrap();
|
||||||
cors.inner.validate_allowed_method(req.head()).unwrap();
|
cors.get_ref().inner.validate_allowed_method(req.head()).unwrap();
|
||||||
cors.inner.validate_allowed_headers(req.head()).unwrap();
|
cors.get_ref().inner.validate_allowed_headers(req.head()).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[ntex::test]
|
#[ntex::test]
|
||||||
|
|
|
@ -1182,7 +1182,7 @@ mod tests {
|
||||||
.default_handler(|req: WebRequest<DefaultError>| {
|
.default_handler(|req: WebRequest<DefaultError>| {
|
||||||
ok(req.into_response(HttpResponse::Ok().body("default content")))
|
ok(req.into_response(HttpResponse::Ok().body("default content")))
|
||||||
})
|
})
|
||||||
.container(())
|
.pipeline(())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let req = TestRequest::with_uri("/missing").to_srv_request();
|
let req = TestRequest::with_uri("/missing").to_srv_request();
|
||||||
|
|
|
@ -583,7 +583,7 @@ mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use ntex::web::test::{self, TestRequest};
|
use ntex::web::test::{self, TestRequest};
|
||||||
use ntex::web::{self, error, App, Error, HttpResponse};
|
use ntex::web::{self, error, App, Error, HttpResponse};
|
||||||
use ntex::{http::StatusCode, service::into_service, service::Container, time};
|
use ntex::{http::StatusCode, service::into_service, service::Pipeline, time};
|
||||||
|
|
||||||
const COOKIE_KEY_MASTER: [u8; 32] = [0; 32];
|
const COOKIE_KEY_MASTER: [u8; 32] = [0; 32];
|
||||||
const COOKIE_NAME: &str = "ntex_auth";
|
const COOKIE_NAME: &str = "ntex_auth";
|
||||||
|
@ -700,7 +700,7 @@ mod tests {
|
||||||
F: Fn(CookieIdentityPolicy) -> CookieIdentityPolicy + Sync + Send + Clone + 'static,
|
F: Fn(CookieIdentityPolicy) -> CookieIdentityPolicy + Sync + Send + Clone + 'static,
|
||||||
>(
|
>(
|
||||||
f: F,
|
f: F,
|
||||||
) -> Container<
|
) -> Pipeline<
|
||||||
impl ntex::service::Service<ntex::http::Request, Response = WebResponse, Error = Error>,
|
impl ntex::service::Service<ntex::http::Request, Response = WebResponse, Error = Error>,
|
||||||
> {
|
> {
|
||||||
test::init_service(
|
test::init_service(
|
||||||
|
@ -1007,7 +1007,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let srv: Container<_> = IdentityServiceMiddleware {
|
let srv: Pipeline<_> = IdentityServiceMiddleware {
|
||||||
backend: Rc::new(Ident),
|
backend: Rc::new(Ident),
|
||||||
service: into_service(|_: WebRequest<DefaultError>| async move {
|
service: into_service(|_: WebRequest<DefaultError>| async move {
|
||||||
time::sleep(time::Seconds(100)).await;
|
time::sleep(time::Seconds(100)).await;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue