mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-09-05 20:26:31 +00:00
Update tests
This commit is contained in:
@ -449,7 +449,7 @@ pub(crate) mod test {
|
|||||||
let dump = DumpReader::open(dump).unwrap();
|
let dump = DumpReader::open(dump).unwrap();
|
||||||
|
|
||||||
// top level infos
|
// top level infos
|
||||||
insta::assert_snapshot!(dump.date().unwrap(), @"2025-07-31 7:28:28.091553 +00:00:00");
|
insta::assert_snapshot!(dump.date().unwrap(), @"2025-07-31 9:21:30.479544 +00:00:00");
|
||||||
insta::assert_debug_snapshot!(dump.instance_uid().unwrap(), @r"
|
insta::assert_debug_snapshot!(dump.instance_uid().unwrap(), @r"
|
||||||
Some(
|
Some(
|
||||||
cb887dcc-34b3-48d1-addd-9815ae721a81,
|
cb887dcc-34b3-48d1-addd-9815ae721a81,
|
||||||
@ -462,23 +462,23 @@ pub(crate) mod test {
|
|||||||
insta::assert_json_snapshot!(webhooks, @r#"
|
insta::assert_json_snapshot!(webhooks, @r#"
|
||||||
{
|
{
|
||||||
"webhooks": {
|
"webhooks": {
|
||||||
"_cli": {
|
"00000000-0000-0000-0000-000000000000": {
|
||||||
"url": "https://defined-in-dump.com/",
|
"url": "https://defined-in-dump.com/",
|
||||||
"headers": {
|
"headers": {
|
||||||
"Authorization": "Bearer defined in dump"
|
"Authorization": "Bearer defined in dump"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"exampleName": {
|
"627ea538-733d-4545-8d2d-03526eb381ce": {
|
||||||
|
"url": "https://example.com/authorization-less",
|
||||||
|
"headers": {}
|
||||||
|
},
|
||||||
|
"771b0a28-ef28-4082-b984-536f82958c65": {
|
||||||
"url": "https://example.com/hook",
|
"url": "https://example.com/hook",
|
||||||
"headers": {
|
"headers": {
|
||||||
"authorization": "TOKEN"
|
"authorization": "TOKEN"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"otherName": {
|
"f3583083-f8a7-4cbf-a5e7-fb3f1e28a7e9": {
|
||||||
"url": "https://example.com/authorization-less",
|
|
||||||
"headers": {}
|
|
||||||
},
|
|
||||||
"third": {
|
|
||||||
"url": "https://third.com",
|
"url": "https://third.com",
|
||||||
"headers": {}
|
"headers": {}
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
@ -13,6 +13,7 @@ use meili_snap::{json_string, snapshot};
|
|||||||
use meilisearch::Opt;
|
use meilisearch::Opt;
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::common::{self, default_settings, Server};
|
use crate::common::{self, default_settings, Server};
|
||||||
use crate::json;
|
use crate::json;
|
||||||
@ -129,16 +130,18 @@ async fn cli_only() {
|
|||||||
|
|
||||||
let (webhooks, code) = server.get_webhooks().await;
|
let (webhooks, code) = server.get_webhooks().await;
|
||||||
snapshot!(code, @"200 OK");
|
snapshot!(code, @"200 OK");
|
||||||
snapshot!(json_string!(webhooks, { ".webhooks._cli.url" => "[ignored]" }), @r#"
|
snapshot!(json_string!(webhooks, { ".results[].url" => "[ignored]" }), @r#"
|
||||||
{
|
{
|
||||||
"webhooks": {
|
"results": [
|
||||||
"_cli": {
|
{
|
||||||
|
"uuid": "00000000-0000-0000-0000-000000000000",
|
||||||
|
"isEditable": false,
|
||||||
"url": "[ignored]",
|
"url": "[ignored]",
|
||||||
"headers": {
|
"headers": {
|
||||||
"Authorization": "Bearer a-secret-token"
|
"Authorization": "Bearer a-secret-token"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
]
|
||||||
}
|
}
|
||||||
"#);
|
"#);
|
||||||
|
|
||||||
@ -163,28 +166,36 @@ async fn cli_with_dumps() {
|
|||||||
snapshot!(code, @"200 OK");
|
snapshot!(code, @"200 OK");
|
||||||
snapshot!(webhooks, @r#"
|
snapshot!(webhooks, @r#"
|
||||||
{
|
{
|
||||||
"webhooks": {
|
"results": [
|
||||||
"_cli": {
|
{
|
||||||
|
"uuid": "00000000-0000-0000-0000-000000000000",
|
||||||
|
"isEditable": false,
|
||||||
"url": "http://defined-in-test-cli.com/",
|
"url": "http://defined-in-test-cli.com/",
|
||||||
"headers": {
|
"headers": {
|
||||||
"Authorization": "Bearer a-secret-token-defined-in-test-cli"
|
"Authorization": "Bearer a-secret-token-defined-in-test-cli"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"exampleName": {
|
{
|
||||||
|
"uuid": "627ea538-733d-4545-8d2d-03526eb381ce",
|
||||||
|
"isEditable": true,
|
||||||
|
"url": "https://example.com/authorization-less",
|
||||||
|
"headers": {}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"uuid": "771b0a28-ef28-4082-b984-536f82958c65",
|
||||||
|
"isEditable": true,
|
||||||
"url": "https://example.com/hook",
|
"url": "https://example.com/hook",
|
||||||
"headers": {
|
"headers": {
|
||||||
"authorization": "TOKEN"
|
"authorization": "TOKEN"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"otherName": {
|
{
|
||||||
"url": "https://example.com/authorization-less",
|
"uuid": "f3583083-f8a7-4cbf-a5e7-fb3f1e28a7e9",
|
||||||
"headers": {}
|
"isEditable": true,
|
||||||
},
|
|
||||||
"third": {
|
|
||||||
"url": "https://third.com",
|
"url": "https://third.com",
|
||||||
"headers": {}
|
"headers": {}
|
||||||
}
|
}
|
||||||
}
|
]
|
||||||
}
|
}
|
||||||
"#);
|
"#);
|
||||||
}
|
}
|
||||||
@ -194,23 +205,23 @@ async fn reserved_names() {
|
|||||||
let server = Server::new().await;
|
let server = Server::new().await;
|
||||||
|
|
||||||
let (value, code) = server
|
let (value, code) = server
|
||||||
.set_webhooks(json!({ "webhooks": { "_cli": { "url": "http://localhost:8080" } } }))
|
.set_webhooks(json!({ "webhooks": { Uuid::nil(): { "url": "http://localhost:8080" } } }))
|
||||||
.await;
|
.await;
|
||||||
snapshot!(code, @"400 Bad Request");
|
snapshot!(code, @"400 Bad Request");
|
||||||
snapshot!(value, @r#"
|
snapshot!(value, @r#"
|
||||||
{
|
{
|
||||||
"message": "Cannot edit webhook `_cli`. Webhooks prefixed with an underscore are reserved and may not be modified using the API.",
|
"message": "Cannot edit webhook `[uuid]`. Webhooks prefixed with an underscore are reserved and may not be modified using the API.",
|
||||||
"code": "reserved_webhook",
|
"code": "reserved_webhook",
|
||||||
"type": "invalid_request",
|
"type": "invalid_request",
|
||||||
"link": "https://docs.meilisearch.com/errors#reserved_webhook"
|
"link": "https://docs.meilisearch.com/errors#reserved_webhook"
|
||||||
}
|
}
|
||||||
"#);
|
"#);
|
||||||
|
|
||||||
let (value, code) = server.set_webhooks(json!({ "webhooks": { "_cli": null } })).await;
|
let (value, code) = server.set_webhooks(json!({ "webhooks": { Uuid::nil(): null } })).await;
|
||||||
snapshot!(code, @"400 Bad Request");
|
snapshot!(code, @"400 Bad Request");
|
||||||
snapshot!(value, @r#"
|
snapshot!(value, @r#"
|
||||||
{
|
{
|
||||||
"message": "Cannot edit webhook `_cli`. Webhooks prefixed with an underscore are reserved and may not be modified using the API.",
|
"message": "Cannot edit webhook `[uuid]`. Webhooks prefixed with an underscore are reserved and may not be modified using the API.",
|
||||||
"code": "reserved_webhook",
|
"code": "reserved_webhook",
|
||||||
"type": "invalid_request",
|
"type": "invalid_request",
|
||||||
"link": "https://docs.meilisearch.com/errors#reserved_webhook"
|
"link": "https://docs.meilisearch.com/errors#reserved_webhook"
|
||||||
@ -223,14 +234,14 @@ async fn over_limits() {
|
|||||||
let server = Server::new().await;
|
let server = Server::new().await;
|
||||||
|
|
||||||
// Too many webhooks
|
// Too many webhooks
|
||||||
for i in 0..20 {
|
for _ in 0..20 {
|
||||||
let (_value, code) = server
|
let (_value, code) = server
|
||||||
.set_webhooks(json!({ "webhooks": { format!("webhook_{i}"): { "url": "http://localhost:8080" } } }))
|
.set_webhooks(json!({ "webhooks": { Uuid::new_v4(): { "url": "http://localhost:8080" } } }))
|
||||||
.await;
|
.await;
|
||||||
snapshot!(code, @"200 OK");
|
snapshot!(code, @"200 OK");
|
||||||
}
|
}
|
||||||
let (value, code) = server
|
let (value, code) = server
|
||||||
.set_webhooks(json!({ "webhooks": { "webhook_21": { "url": "http://localhost:8080" } } }))
|
.set_webhooks(json!({ "webhooks": { Uuid::new_v4(): { "url": "http://localhost:8080" } } }))
|
||||||
.await;
|
.await;
|
||||||
snapshot!(code, @"400 Bad Request");
|
snapshot!(code, @"400 Bad Request");
|
||||||
snapshot!(value, @r#"
|
snapshot!(value, @r#"
|
||||||
@ -252,20 +263,21 @@ async fn over_limits() {
|
|||||||
"#);
|
"#);
|
||||||
|
|
||||||
// Test too many headers
|
// Test too many headers
|
||||||
|
let uuid = Uuid::new_v4();
|
||||||
for i in 0..200 {
|
for i in 0..200 {
|
||||||
let header_name = format!("header_{i}");
|
let header_name = format!("header_{i}");
|
||||||
let (_value, code) = server
|
let (_value, code) = server
|
||||||
.set_webhooks(json!({ "webhooks": { "webhook": { "url": "http://localhost:8080", "headers": { header_name: "value" } } } }))
|
.set_webhooks(json!({ "webhooks": { uuid: { "url": "http://localhost:8080", "headers": { header_name: "value" } } } }))
|
||||||
.await;
|
.await;
|
||||||
snapshot!(code, @"200 OK");
|
snapshot!(code, @"200 OK");
|
||||||
}
|
}
|
||||||
let (value, code) = server
|
let (value, code) = server
|
||||||
.set_webhooks(json!({ "webhooks": { "webhook": { "url": "http://localhost:8080", "headers": { "header_201": "value" } } } }))
|
.set_webhooks(json!({ "webhooks": { uuid: { "url": "http://localhost:8080", "headers": { "header_201": "value" } } } }))
|
||||||
.await;
|
.await;
|
||||||
snapshot!(code, @"400 Bad Request");
|
snapshot!(code, @"400 Bad Request");
|
||||||
snapshot!(value, @r#"
|
snapshot!(value, @r#"
|
||||||
{
|
{
|
||||||
"message": "Too many headers for the webhook `webhook`. Please limit the number of headers to 200.",
|
"message": "Too many headers for the webhook `[uuid]`. Please limit the number of headers to 200.",
|
||||||
"code": "invalid_webhooks_headers",
|
"code": "invalid_webhooks_headers",
|
||||||
"type": "invalid_request",
|
"type": "invalid_request",
|
||||||
"link": "https://docs.meilisearch.com/errors#invalid_webhooks_headers"
|
"link": "https://docs.meilisearch.com/errors#invalid_webhooks_headers"
|
||||||
|
Reference in New Issue
Block a user