diff --git a/meilisearch-http/tests/common.rs b/meilisearch-http/tests/common.rs index 0e02b6707..3b9ac8c2e 100644 --- a/meilisearch-http/tests/common.rs +++ b/meilisearch-http/tests/common.rs @@ -7,6 +7,7 @@ use actix_web::{http::StatusCode, test}; use meilisearch_core::DatabaseOptions; use meilisearch_http::data::Data; use meilisearch_http::option::Opt; +use meilisearch_http::helpers::NormalizeSlashes; use tempdir::TempDir; use tokio::time::delay_for; @@ -126,7 +127,7 @@ impl Server { pub async fn get_request(&mut self, url: &str) -> (Value, StatusCode) { eprintln!("get_request: {}", url); - let mut app = test::init_service(meilisearch_http::create_app(&self.data)).await; + let mut app = test::init_service(meilisearch_http::create_app(&self.data).wrap(NormalizeSlashes)).await; let req = test::TestRequest::get().uri(url).to_request(); let res = test::call_service(&mut app, req).await; @@ -140,7 +141,7 @@ impl Server { pub async fn post_request(&mut self, url: &str, body: Value) -> (Value, StatusCode) { eprintln!("post_request: {}", url); - let mut app = test::init_service(meilisearch_http::create_app(&self.data)).await; + let mut app = test::init_service(meilisearch_http::create_app(&self.data).wrap(NormalizeSlashes)).await; let req = test::TestRequest::post() .uri(url) @@ -169,7 +170,7 @@ impl Server { pub async fn put_request(&mut self, url: &str, body: Value) -> (Value, StatusCode) { eprintln!("put_request: {}", url); - let mut app = test::init_service(meilisearch_http::create_app(&self.data)).await; + let mut app = test::init_service(meilisearch_http::create_app(&self.data).wrap(NormalizeSlashes)).await; let req = test::TestRequest::put() .uri(url) @@ -197,7 +198,7 @@ impl Server { pub async fn delete_request(&mut self, url: &str) -> (Value, StatusCode) { eprintln!("delete_request: {}", url); - let mut app = test::init_service(meilisearch_http::create_app(&self.data)).await; + let mut app = test::init_service(meilisearch_http::create_app(&self.data).wrap(NormalizeSlashes)).await; let req = test::TestRequest::delete().uri(url).to_request(); let res = test::call_service(&mut app, req).await; diff --git a/meilisearch-http/tests/url_normalizer.rs b/meilisearch-http/tests/url_normalizer.rs new file mode 100644 index 000000000..c2c9187ee --- /dev/null +++ b/meilisearch-http/tests/url_normalizer.rs @@ -0,0 +1,18 @@ +mod common; + +#[actix_rt::test] +async fn url_normalizer() { + let mut server = common::Server::with_uid("movies"); + + let (_response, status_code) = server.get_request("/version").await; + assert_eq!(status_code, 200); + + let (_response, status_code) = server.get_request("//version").await; + assert_eq!(status_code, 200); + + let (_response, status_code) = server.get_request("/version/").await; + assert_eq!(status_code, 200); + + let (_response, status_code) = server.get_request("//version/").await; + assert_eq!(status_code, 200); +}