From 0402b2734b14af4a7b5abeaedf610de7c172fe7c Mon Sep 17 00:00:00 2001 From: Konrad Borowski Date: Mon, 20 Jan 2020 12:18:09 +0100 Subject: [PATCH] Add CORS tests --- src/routes/mod.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/routes/mod.rs b/src/routes/mod.rs index bac9610..a036a1d 100644 --- a/src/routes/mod.rs +++ b/src/routes/mod.rs @@ -399,4 +399,49 @@ mod test { } } } + + #[test] + #[cfg_attr(not(feature = "database_tests"), ignore)] + fn raw_cors() { + assert_eq!( + warp::test::request() + .path("/a.txt") + .method("OPTIONS") + .header("origin", "example.com") + .header("access-control-request-method", "GET") + .reply(&*ROUTES) + .status(), + StatusCode::OK, + ); + } + + #[test] + #[cfg_attr(not(feature = "database_tests"), ignore)] + fn paste_no_cors() { + assert_eq!( + warp::test::request() + .path("/a") + .method("OPTIONS") + .header("origin", "example.com") + .header("access-control-request-method", "GET") + .reply(&*ROUTES) + .status(), + StatusCode::METHOD_NOT_ALLOWED, + ); + } + + #[test] + #[cfg_attr(not(feature = "database_tests"), ignore)] + fn api_v1_cors() { + assert_eq!( + warp::test::request() + .path("/api/v1/languages") + .method("OPTIONS") + .header("origin", "example.com") + .header("access-control-request-method", "GET") + .reply(&*ROUTES) + .status(), + StatusCode::OK, + ); + } }