Browse Source

Merge pull request #11860 from thalesmg/fix-delete-shared-bridgev2-r53-20231101

fix(bridge_v1): return 400 if trying to delete shared bridge via http api v1
Zaiming (Stone) Shi 2 years atrás
parent
commit
f5818a86e3

+ 1 - 1
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
     ).
 

+ 22 - 0
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.
     %% ===================================================================================