mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-09-06 12:46:31 +00:00
Add test for reserved webhooks
This commit is contained in:
@ -129,7 +129,7 @@ enum WebhooksError {
|
|||||||
TooManyWebhooks,
|
TooManyWebhooks,
|
||||||
#[error("Too many headers for the webhook `{0}`. Please limit the number of headers to 200.")]
|
#[error("Too many headers for the webhook `{0}`. Please limit the number of headers to 200.")]
|
||||||
TooManyHeaders(String),
|
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),
|
ReservedWebhook(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ use actix_http::body::MessageBody;
|
|||||||
use actix_web::dev::{ServiceFactory, ServiceResponse};
|
use actix_web::dev::{ServiceFactory, ServiceResponse};
|
||||||
use actix_web::web::{Bytes, Data};
|
use actix_web::web::{Bytes, Data};
|
||||||
use actix_web::{post, App, HttpRequest, HttpResponse, HttpServer};
|
use actix_web::{post, App, HttpRequest, HttpResponse, HttpServer};
|
||||||
use meili_snap::snapshot;
|
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;
|
||||||
@ -128,11 +128,11 @@ async fn test_cli_webhook() {
|
|||||||
|
|
||||||
let (webhooks, code) = server.get_webhooks().await;
|
let (webhooks, code) = server.get_webhooks().await;
|
||||||
snapshot!(code, @"200 OK");
|
snapshot!(code, @"200 OK");
|
||||||
snapshot!(webhooks, @r#"
|
snapshot!(json_string!(webhooks, { ".webhooks._cli.url" => "[ignored]" }), @r#"
|
||||||
{
|
{
|
||||||
"webhooks": {
|
"webhooks": {
|
||||||
"_cli": {
|
"_cli": {
|
||||||
"url": "http://127.0.0.1:51503/",
|
"url": "[ignored]",
|
||||||
"headers": {
|
"headers": {
|
||||||
"Authorization": "Bearer a-secret-token"
|
"Authorization": "Bearer a-secret-token"
|
||||||
}
|
}
|
||||||
@ -143,3 +143,32 @@ async fn test_cli_webhook() {
|
|||||||
|
|
||||||
server_handle.abort();
|
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"
|
||||||
|
}
|
||||||
|
"#);
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user