mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-28 01:32: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(
|
||||||
.configure(
|
|| App::new()
|
||||||
|app| Cors::for_app(app)
|
.configure(
|
||||||
.allowed_origin("https://www.example.com")
|
|app| Cors::for_app(app)
|
||||||
.resource("/test", |r| r.f(|_| HttpResponse::Ok()))
|
.allowed_origin("https://www.example.com")
|
||||||
.register())
|
.resource("/test", |r| r.f(|_| HttpResponse::Ok()))
|
||||||
.finish();
|
.register()));
|
||||||
|
|
||||||
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