mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-28 01:52:57 +01:00
proper test for CorsBuilder::resource
This commit is contained in:
parent
1686682c19
commit
2881859400
@ -793,7 +793,7 @@ impl<S: 'static> CorsBuilder<S> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use test::TestRequest;
|
use test::{self, TestRequest};
|
||||||
|
|
||||||
impl Started {
|
impl Started {
|
||||||
fn is_done(&self) -> bool {
|
fn is_done(&self) -> bool {
|
||||||
@ -1000,19 +1000,21 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn cors_resource() {
|
fn cors_resource() {
|
||||||
let mut app = App::new()
|
let mut srv = test::TestServer::with_factory(
|
||||||
|
|| App::new()
|
||||||
.configure(
|
.configure(
|
||||||
|app| Cors::for_app(app)
|
|app| Cors::for_app(app)
|
||||||
.allowed_origin("https://www.example.com")
|
.allowed_origin("https://www.example.com")
|
||||||
.resource("/test", |r| r.f(|_| HttpResponse::Ok()))
|
.resource("/test", |r| r.f(|_| HttpResponse::Ok()))
|
||||||
.register())
|
.register()));
|
||||||
.finish();
|
|
||||||
|
|
||||||
let req = TestRequest::with_uri("/test").finish();
|
let request = srv.get().uri(srv.url("/test")).finish().unwrap();
|
||||||
let resp = app.run(req);
|
let response = srv.execute(request.send()).unwrap();
|
||||||
|
assert_eq!(response.status(), StatusCode::BAD_REQUEST);
|
||||||
|
|
||||||
// TODO: proper test
|
let request = srv.get().uri(srv.url("/test"))
|
||||||
//assert_eq!(resp.as_response().unwrap().status(), StatusCode::OK);
|
.header("ORIGIN", "https://www.example.com").finish().unwrap();
|
||||||
assert!(resp.as_response().is_none());
|
let response = srv.execute(request.send()).unwrap();
|
||||||
|
assert_eq!(response.status(), StatusCode::OK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user