From c03979a48a99df539da9d8d3c539f91661235693 Mon Sep 17 00:00:00 2001 From: Thales Macedo Garitezi Date: Wed, 1 Nov 2023 09:51:26 -0300 Subject: [PATCH] fix(bridge_v1): return 400 if trying to delete shared bridge via http api v1 --- apps/emqx_bridge/src/emqx_bridge_api.erl | 2 +- ...qx_bridge_v1_compatibility_layer_SUITE.erl | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/apps/emqx_bridge/src/emqx_bridge_api.erl b/apps/emqx_bridge/src/emqx_bridge_api.erl index eb0efcb14..f2cc7163f 100644 --- a/apps/emqx_bridge/src/emqx_bridge_api.erl +++ b/apps/emqx_bridge/src/emqx_bridge_api.erl @@ -530,7 +530,7 @@ schema("/bridges_probe") -> {error, not_found} -> ?BRIDGE_NOT_FOUND(BridgeType, BridgeName); {error, not_bridge_v1_compatible} -> - ?BAD_REQUEST('ALREADY_EXISTS', non_compat_bridge_msg()) + ?BAD_REQUEST(non_compat_bridge_msg()) end ). diff --git a/apps/emqx_bridge/test/emqx_bridge_v1_compatibility_layer_SUITE.erl b/apps/emqx_bridge/test/emqx_bridge_v1_compatibility_layer_SUITE.erl index bfc3eedc5..b33254afa 100644 --- a/apps/emqx_bridge/test/emqx_bridge_v1_compatibility_layer_SUITE.erl +++ b/apps/emqx_bridge/test/emqx_bridge_v1_compatibility_layer_SUITE.erl @@ -616,6 +616,28 @@ t_scenario_1(_Config) -> %% ?assertMatch({ok, {{_, 204, _}, _, _}}, bridge_node_operation_http_api_v2(NameA, restart)), %% ?assertMatch({ok, {{_, 204, _}, _, _}}, bridge_node_operation_http_api_v2(NameB, restart)), + %% =================================================================================== + %% Try to delete the original bridge using V1. It should fail and its connector + %% should be preserved. + %% =================================================================================== + ?assertMatch( + {error, {{_, 400, _}, _, _}}, + delete_bridge_http_api_v1(#{name => NameA}) + ), + ?assertMatch({ok, {{_, 200, _}, _, []}}, list_bridges_http_api_v1()), + ?assertMatch( + {ok, {{_, 200, _}, _, [#{<<"name">> := _}, #{<<"name">> := _}]}}, list_bridges_http_api_v2() + ), + ?assertMatch({ok, {{_, 200, _}, _, [#{}, #{}]}}, list_connectors_http()), + ?assertMatch({error, {{_, 404, _}, _, #{}}}, get_bridge_http_api_v1(NameA)), + ?assertMatch({error, {{_, 404, _}, _, #{}}}, get_bridge_http_api_v1(NameB)), + ?assertMatch({ok, {{_, 200, _}, _, #{<<"name">> := NameA}}}, get_bridge_http_api_v2(NameA)), + ?assertMatch({ok, {{_, 200, _}, _, #{<<"name">> := NameB}}}, get_bridge_http_api_v2(NameB)), + ?assertMatch( + {ok, {{_, 200, _}, _, #{<<"name">> := GeneratedConnName}}}, + get_connector_http(GeneratedConnName) + ), + %% =================================================================================== %% Delete the 2nd new bridge so it appears again in the V1 API. %% ===================================================================================