Quellcode durchsuchen

fix(test): ifdb test SUITE & version compatibility

DDDHuang vor 4 Jahren
Ursprung
Commit
29790a0c1e

+ 9 - 9
apps/emqx_management/src/emqx_mgmt_api_clients.erl

@@ -179,7 +179,7 @@ schema("/clients/:clientid") ->
         delete => #{
             description => <<"Kick out client by client ID">>,
             parameters => [
-                {clientid, hoconsc:mk(boolean(), #{in => path})}],
+                {clientid, hoconsc:mk(binary(), #{in => path})}],
             responses => #{
                 204 => <<"Kick out client successfully">>,
                 404 => emqx_dashboard_swagger:error_codes(
@@ -258,9 +258,10 @@ schema("/clients/:clientid/unsubscribe") ->
 schema("/clients/:clientid/keepalive") ->
     #{
         'operationId' => set_keepalive,
-        post => #{
+        put => #{
             description => <<"Set the online client keepalive by seconds">>,
             parameters => [{clientid, hoconsc:mk(binary(), #{in => path})}],
+            'requestBody' => hoconsc:mk(hoconsc:ref(?MODULE, keepalive)),
             responses => #{
                 200 => hoconsc:mk(hoconsc:ref(?MODULE, client), #{}),
                 404 => emqx_dashboard_swagger:error_codes(
@@ -363,7 +364,7 @@ fields(authz_cache) ->
 
 fields(keepalive) ->
     [
-        {keepalive, hoconsc:mk(integer(), #{desc => <<"keepalive time, with the unit of second">>})}
+        {interval, hoconsc:mk(integer(), #{desc => <<"Keepalive time, with the unit of second">>})}
     ];
 
 fields(subscribe) ->
@@ -435,13 +436,12 @@ subscriptions(get, #{bindings := #{clientid := ClientID}}) ->
         {200, lists:map(Formatter, Subs)}
     end.
 
-set_keepalive(put, #{bindings := #{clientid := ClientID}, query_string := Query}) ->
-    case maps:find(<<"interval">>, Query) of
-        error -> {404, "Interval Not Found"};
-        {ok, Interval0} ->
-            Interval = binary_to_integer(Interval0),
+set_keepalive(put, #{bindings := #{clientid := ClientID}, body := Body}) ->
+    case maps:find(<<"interval">>, Body) of
+        error -> {400, 'BAD_REQUEST',"Interval Not Found"};
+        {ok, Interval} ->
             case emqx_mgmt:set_keepalive(emqx_mgmt_util:urldecode(ClientID), Interval) of
-                ok -> {200};
+                ok -> lookup(#{clientid => ClientID});
                 {error, not_found} ->{404, ?CLIENT_ID_NOT_FOUND};
                 {error, Reason} -> {400, #{code => 'PARAMS_ERROR', message => Reason}}
             end

+ 7 - 6
apps/emqx_management/test/emqx_mgmt_api_clients_SUITE.erl

@@ -96,8 +96,9 @@ t_clients(_) ->
     %% post /clients/:clientid/unsubscribe
     UnSubscribePath = emqx_mgmt_api_test_util:api_path(["clients",
         binary_to_list(ClientId1), "unsubscribe"]),
+    UnSubscribeBody = #{topic => Topic},
     {ok, _} =  emqx_mgmt_api_test_util:request_api(post, UnSubscribePath,
-        "", AuthHeader, SubscribeBody),
+        "", AuthHeader, UnSubscribeBody),
     timer:sleep(100),
     ?assertEqual([], emqx_mgmt:lookup_subscriptions(Client1)),
 
@@ -165,15 +166,15 @@ t_query_clients_with_time(_) ->
 t_keepalive(_Config) ->
     Username = "user_keepalive",
     ClientId = "client_keepalive",
-    AuthHeader      = emqx_mgmt_api_test_util:auth_header_(),
+    AuthHeader = emqx_mgmt_api_test_util:auth_header_(),
     Path = emqx_mgmt_api_test_util:api_path(["clients", ClientId, "keepalive"]),
-    Query = "interval=11",
+    Body = #{interval => 11},
     {error,{"HTTP/1.1",404,"Not Found"}} =
-        emqx_mgmt_api_test_util:request_api(put, Path, Query, AuthHeader, <<"">>),
+        emqx_mgmt_api_test_util:request_api(put, Path, <<"">>, AuthHeader, Body),
     {ok, C1} = emqtt:start_link(#{username => Username, clientid => ClientId}),
     {ok, _} = emqtt:connect(C1),
-    {ok, Ok} = emqx_mgmt_api_test_util:request_api(put, Path, Query, AuthHeader, <<"">>),
-    ?assertEqual("", Ok),
+    {ok, NewClient} = emqx_mgmt_api_test_util:request_api(put, Path, <<"">>, AuthHeader, Body),
+    #{<<"keepalive">> := 11} = emqx_json:decode(NewClient, [return_maps]),
     [Pid] = emqx_cm:lookup_channels(list_to_binary(ClientId)),
     #{conninfo := #{keepalive := Keepalive}} = emqx_connection:info(Pid),
     ?assertEqual(11, Keepalive),