Procházet zdrojové kódy

Merge pull request #12433 from HJianBo/fix-content-type

chore: compatible the contet-type sytanx
zhongwencool před 2 roky
rodič
revize
6ee4439249

+ 2 - 2
apps/emqx_auth/src/emqx_authn/emqx_authn_user_import_api.erl

@@ -126,7 +126,7 @@ authenticator_import_users(
     PasswordType = password_type(Req),
     Result =
         case maps:get(<<"content-type">>, Headers, undefined) of
-            <<"application/json">> ->
+            <<"application/json", _/binary>> ->
                 emqx_authn_chains:import_users(
                     ?GLOBAL, AuthenticatorID, {PasswordType, prepared_user_list, Body}
                 );
@@ -172,7 +172,7 @@ listener_authenticator_import_users(
         )
     end,
     case maps:get(<<"content-type">>, Headers, undefined) of
-        <<"application/json">> ->
+        <<"application/json", _/binary>> ->
             DoImport(prepared_user_list, Body);
         _ ->
             case Body of

+ 9 - 0
apps/emqx_auth_mnesia/test/emqx_authn_api_mnesia_SUITE.erl

@@ -342,6 +342,9 @@ test_authenticator_import_users(PathPrefix) ->
     {ok, 204, _} = request(post, ImportUri ++ "?type=hash", emqx_utils_json:decode(JSONData)),
     {ok, JSONData1} = file:read_file(filename:join([Dir, <<"data/user-credentials-plain.json">>])),
     {ok, 204, _} = request(post, ImportUri ++ "?type=plain", emqx_utils_json:decode(JSONData1)),
+
+    %% test application/json; charset=utf-8
+    {ok, 204, _} = request_with_charset(post, ImportUri ++ "?type=plain", JSONData1),
     ok.
 
 %%------------------------------------------------------------------------------
@@ -350,3 +353,9 @@ test_authenticator_import_users(PathPrefix) ->
 
 request(Method, Url) ->
     request(Method, Url, []).
+
+request_with_charset(Method, Url, Body) ->
+    Headers = [emqx_mgmt_api_test_util:auth_header_()],
+    Opts = #{compatible_mode => true, httpc_req_opts => [{body_format, binary}]},
+    Request = {Url, Headers, "application/json; charset=utf-8", Body},
+    emqx_mgmt_api_test_util:do_request_api(Method, Request, Opts).