Add test for reserved webhooks

This commit is contained in:
Mubelotix
2025-07-30 15:52:24 +02:00
parent e88480c7c4
commit c70ae91d34
2 changed files with 33 additions and 4 deletions

View File

@ -129,7 +129,7 @@ enum WebhooksError {
TooManyWebhooks,
#[error("Too many headers for the webhook `{0}`. Please limit the number of headers to 200.")]
TooManyHeaders(String),
#[error("Cannot edit webhook `{0}`. Webhooks prefixed with an underscore are special and may not be modified using the API.")]
#[error("Cannot edit webhook `{0}`. Webhooks prefixed with an underscore are reserved and may not be modified using the API.")]
ReservedWebhook(String),
}

View File

@ -8,7 +8,7 @@ use actix_http::body::MessageBody;
use actix_web::dev::{ServiceFactory, ServiceResponse};
use actix_web::web::{Bytes, Data};
use actix_web::{post, App, HttpRequest, HttpResponse, HttpServer};
use meili_snap::snapshot;
use meili_snap::{json_string, snapshot};
use meilisearch::Opt;
use tokio::sync::mpsc;
use url::Url;
@ -128,11 +128,11 @@ async fn test_cli_webhook() {
let (webhooks, code) = server.get_webhooks().await;
snapshot!(code, @"200 OK");
snapshot!(webhooks, @r#"
snapshot!(json_string!(webhooks, { ".webhooks._cli.url" => "[ignored]" }), @r#"
{
"webhooks": {
"_cli": {
"url": "http://127.0.0.1:51503/",
"url": "[ignored]",
"headers": {
"Authorization": "Bearer a-secret-token"
}
@ -143,3 +143,32 @@ async fn test_cli_webhook() {
server_handle.abort();
}
#[actix_web::test]
async fn reserved_names() {
let server = Server::new().await;
let (value, code) = server
.set_webhooks(json!({ "webhooks": { "_cli": { "url": "http://localhost:8080" } } }))
.await;
snapshot!(code, @"400 Bad Request");
snapshot!(value, @r#"
{
"message": "Cannot edit webhook `_cli`. Webhooks prefixed with an underscore are reserved and may not be modified using the API.",
"code": "reserved_webhook",
"type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#reserved_webhook"
}
"#);
let (value, code) = server.set_webhooks(json!({ "webhooks": { "_cli": null } })).await;
snapshot!(code, @"400 Bad Request");
snapshot!(value, @r#"
{
"message": "Cannot edit webhook `_cli`. Webhooks prefixed with an underscore are reserved and may not be modified using the API.",
"code": "reserved_webhook",
"type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#reserved_webhook"
}
"#);
}