Merge pull request #12923 from zhongwencool/authn-mnesia

chore: provided more specific error for wrong import method
This commit is contained in:
zhongwencool 2024-04-25 10:28:09 +08:00 committed by GitHub
commit 2cbf4dc789
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 22 additions and 1 deletions

View File

@ -1,7 +1,7 @@
%% -*- mode: erlang -*- %% -*- mode: erlang -*-
{application, emqx_auth_mnesia, [ {application, emqx_auth_mnesia, [
{description, "EMQX Buitl-in Database Authentication and Authorization"}, {description, "EMQX Buitl-in Database Authentication and Authorization"},
{vsn, "0.1.4"}, {vsn, "0.1.5"},
{registered, []}, {registered, []},
{mod, {emqx_auth_mnesia_app, []}}, {mod, {emqx_auth_mnesia_app, []}},
{applications, [ {applications, [

View File

@ -527,6 +527,10 @@ find_password_hash(hash, User = #{<<"password_hash">> := PasswordHash}, _) ->
{PasswordHash, maps:get(<<"salt">>, User, <<>>)}; {PasswordHash, maps:get(<<"salt">>, User, <<>>)};
find_password_hash(plain, #{<<"password">> := Password}, Algorithm) -> find_password_hash(plain, #{<<"password">> := Password}, Algorithm) ->
emqx_authn_password_hashing:hash(Algorithm, Password); emqx_authn_password_hashing:hash(Algorithm, Password);
find_password_hash(hash, _User, _) ->
error("hash_import_requires_password_hash_field");
find_password_hash(plain, _User, _Algorithm) ->
error("plain_import_requires_password_field");
find_password_hash(_, _, _) -> find_password_hash(_, _, _) ->
error(bad_format). error(bad_format).

View File

@ -228,6 +228,14 @@ t_import_users(_) ->
State State
) )
), ),
%% import plain.json with hash method
?assertEqual(
{error, "hash_import_requires_password_hash_field"},
emqx_authn_mnesia:import_users(
sample_filename_and_data(hash, <<"user-credentials-plain.json">>),
State
)
),
?assertEqual( ?assertEqual(
{error, bad_format}, {error, bad_format},
@ -289,6 +297,14 @@ t_import_users_plain(_) ->
State State
) )
), ),
%% import hash.json with plain method
?assertEqual(
{error, "plain_import_requires_password_field"},
emqx_authn_mnesia:import_users(
sample_filename_and_data(plain, <<"user-credentials.json">>),
State
)
),
?assertEqual( ?assertEqual(
ok, ok,

View File

@ -0,0 +1 @@
Provided more specific error when importing wrong format into builtin authenticate database.