From b787f28d2745b2008ae4946a5ba16244ed26c64e Mon Sep 17 00:00:00 2001 From: JianBo He Date: Wed, 31 Jan 2024 17:49:46 +0800 Subject: [PATCH] chore: compatible the contet-type sytanx --- .../src/emqx_authn/emqx_authn_user_import_api.erl | 4 ++-- .../test/emqx_authn_api_mnesia_SUITE.erl | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/apps/emqx_auth/src/emqx_authn/emqx_authn_user_import_api.erl b/apps/emqx_auth/src/emqx_authn/emqx_authn_user_import_api.erl index 2b2ccecac..db6bbccda 100644 --- a/apps/emqx_auth/src/emqx_authn/emqx_authn_user_import_api.erl +++ b/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 diff --git a/apps/emqx_auth_mnesia/test/emqx_authn_api_mnesia_SUITE.erl b/apps/emqx_auth_mnesia/test/emqx_authn_api_mnesia_SUITE.erl index 71da75c1b..660c8c1cc 100644 --- a/apps/emqx_auth_mnesia/test/emqx_authn_api_mnesia_SUITE.erl +++ b/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).