From 375661c6a1c7817f4d178b13c9fcc8b199815d14 Mon Sep 17 00:00:00 2001 From: Kjell Winblad Date: Mon, 5 Jun 2023 17:02:08 +0200 Subject: [PATCH] test: add test case for error when bridge name is too long --- .../test/emqx_bridge_api_SUITE.erl | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/apps/emqx_bridge/test/emqx_bridge_api_SUITE.erl b/apps/emqx_bridge/test/emqx_bridge_api_SUITE.erl index 1ac6750a4..ba65bdd34 100644 --- a/apps/emqx_bridge/test/emqx_bridge_api_SUITE.erl +++ b/apps/emqx_bridge/test/emqx_bridge_api_SUITE.erl @@ -415,6 +415,26 @@ t_http_crud_apis(Config) -> ), %% Test bad updates + %% ================ + + %% Add bridge with a name that is too long + %% We only support bridge names up to 255 characters + LongName = list_to_binary(lists:duplicate(256, $a)), + NameTooLongRequestResult = request_json( + post, + uri(["bridges"]), + ?HTTP_BRIDGE(URL1, LongName), + Config + ), + ?assertMatch( + {ok, 400, _}, + NameTooLongRequestResult + ), + {ok, 400, #{<<"message">> := NameTooLongMessage}} = NameTooLongRequestResult, + %% Use regex to check that the message contains the name + Match = re:run(NameTooLongMessage, LongName), + ?assertMatch({match, _}, Match), + %% Add bridge without the URL field {ok, 400, PutFail1} = request_json( put, uri(["bridges", BridgeID]),