mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 20:37:15 +02:00
Merge pull request #56 from meilisearch/fix-bad-index-uid
Fix bad index uid
This commit is contained in:
commit
964e52ef08
8 changed files with 57 additions and 9 deletions
|
@ -1,7 +1,8 @@
|
|||
use tempdir::TempDir;
|
||||
use actix_web::http::StatusCode;
|
||||
use byte_unit::{Byte, ByteUnit};
|
||||
use serde_json::Value;
|
||||
use actix_web::http::StatusCode;
|
||||
use tempdir::TempDir;
|
||||
use urlencoding::encode;
|
||||
|
||||
use meilisearch_http::data::Data;
|
||||
use meilisearch_http::option::{Opt, IndexerOpts};
|
||||
|
@ -60,7 +61,7 @@ impl Server {
|
|||
/// Returns a view to an index. There is no guarantee that the index exists.
|
||||
pub fn index<'a>(&'a self, uid: impl AsRef<str>) -> Index<'a> {
|
||||
Index {
|
||||
uid: uid.as_ref().to_string(),
|
||||
uid: encode(uid.as_ref()),
|
||||
service: &self.service,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,6 +45,22 @@ async fn add_documents_no_index_creation() {
|
|||
assert_eq!(response["primaryKey"], "id");
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn document_add_create_index_bad_uid() {
|
||||
let server = Server::new().await;
|
||||
let index = server.index("883 fj!");
|
||||
let (_response, code) = index.add_documents(json!([]), None).await;
|
||||
assert_eq!(code, 400);
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn document_update_create_index_bad_uid() {
|
||||
let server = Server::new().await;
|
||||
let index = server.index("883 fj!");
|
||||
let (_response, code) = index.update_documents(json!([]), None).await;
|
||||
assert_eq!(code, 400);
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn document_addition_with_primary_key() {
|
||||
let server = Server::new().await;
|
||||
|
|
|
@ -47,12 +47,10 @@ async fn create_existing_index() {
|
|||
assert_eq!(code, 400);
|
||||
}
|
||||
|
||||
// test fails (issue #46)
|
||||
#[actix_rt::test]
|
||||
#[ignore]
|
||||
async fn create_with_invalid_index_uid() {
|
||||
let server = Server::new().await;
|
||||
let index = server.index("test test");
|
||||
let index = server.index("test test#!");
|
||||
let (_, code) = index.create(None).await;
|
||||
assert_eq!(code, 400);
|
||||
}
|
||||
|
|
|
@ -90,6 +90,15 @@ async fn update_setting_unexisting_index() {
|
|||
assert_eq!(code, 200);
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn update_setting_unexisting_index_invalid_uid() {
|
||||
let server = Server::new().await;
|
||||
let index = server.index("test##! ");
|
||||
let (_response, code) = index.update_settings(json!({})).await;
|
||||
println!("response: {}", _response);
|
||||
assert_eq!(code, 400);
|
||||
}
|
||||
|
||||
macro_rules! test_setting_routes {
|
||||
($($setting:ident), *) => {
|
||||
$(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue