test: refine existed test cases
This commit is contained in:
parent
fed512689a
commit
829887630d
|
@ -310,7 +310,11 @@ reorder_authenticator(_ChainName, []) ->
|
||||||
reorder_authenticator(ChainName, AuthenticatorIDs) ->
|
reorder_authenticator(ChainName, AuthenticatorIDs) ->
|
||||||
call({reorder_authenticator, ChainName, AuthenticatorIDs}).
|
call({reorder_authenticator, ChainName, AuthenticatorIDs}).
|
||||||
|
|
||||||
-spec import_users(chain_name(), authenticator_id(), {binary(), binary()}) ->
|
-spec import_users(
|
||||||
|
chain_name(),
|
||||||
|
authenticator_id(),
|
||||||
|
{plain | hash, prepared_user_list | binary(), binary()}
|
||||||
|
) ->
|
||||||
ok | {error, term()}.
|
ok | {error, term()}.
|
||||||
import_users(ChainName, AuthenticatorID, Filename) ->
|
import_users(ChainName, AuthenticatorID, Filename) ->
|
||||||
call({import_users, ChainName, AuthenticatorID, Filename}).
|
call({import_users, ChainName, AuthenticatorID, Filename}).
|
||||||
|
|
|
@ -53,11 +53,14 @@ when
|
||||||
when
|
when
|
||||||
State :: state().
|
State :: state().
|
||||||
|
|
||||||
-callback import_users({Filename, FileData}, State) ->
|
-callback import_users({PasswordType, Filename, FileData}, State) ->
|
||||||
ok
|
ok
|
||||||
| {error, term()}
|
| {error, term()}
|
||||||
when
|
when
|
||||||
Filename :: binary(), FileData :: binary(), State :: state().
|
PasswordType :: plain | hash,
|
||||||
|
Filename :: prepared_user_list | binary(),
|
||||||
|
FileData :: binary(),
|
||||||
|
State :: state().
|
||||||
|
|
||||||
-callback add_user(UserInfo, State) ->
|
-callback add_user(UserInfo, State) ->
|
||||||
{ok, User}
|
{ok, User}
|
||||||
|
|
|
@ -195,7 +195,9 @@ param_password_type() ->
|
||||||
}
|
}
|
||||||
)}.
|
)}.
|
||||||
|
|
||||||
password_type(_Req = #{query_string := #{<<"type">> := Type}}) ->
|
password_type(_Req = #{query_string := #{<<"type">> := <<"plain">>}}) ->
|
||||||
binary_to_existing_atom(Type);
|
plain;
|
||||||
|
password_type(_Req = #{query_string := #{<<"type">> := <<"hash">>}}) ->
|
||||||
|
hash;
|
||||||
password_type(_) ->
|
password_type(_) ->
|
||||||
hash.
|
hash.
|
||||||
|
|
|
@ -216,7 +216,7 @@ t_import_users(_) ->
|
||||||
?assertMatch(
|
?assertMatch(
|
||||||
{error, {unsupported_file_format, _}},
|
{error, {unsupported_file_format, _}},
|
||||||
emqx_authn_mnesia:import_users(
|
emqx_authn_mnesia:import_users(
|
||||||
{<<"/file/with/unknown.extension">>, <<>>},
|
{hash, <<"/file/with/unknown.extension">>, <<>>},
|
||||||
State
|
State
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
@ -224,7 +224,7 @@ t_import_users(_) ->
|
||||||
?assertEqual(
|
?assertEqual(
|
||||||
{error, unknown_file_format},
|
{error, unknown_file_format},
|
||||||
emqx_authn_mnesia:import_users(
|
emqx_authn_mnesia:import_users(
|
||||||
{<<"/file/with/no/extension">>, <<>>},
|
{hash, <<"/file/with/no/extension">>, <<>>},
|
||||||
State
|
State
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
@ -264,7 +264,7 @@ sample_filename(Name) ->
|
||||||
sample_filename_and_data(Name) ->
|
sample_filename_and_data(Name) ->
|
||||||
Filename = sample_filename(Name),
|
Filename = sample_filename(Name),
|
||||||
{ok, Data} = file:read_file(Filename),
|
{ok, Data} = file:read_file(Filename),
|
||||||
{Filename, Data}.
|
{hash, Filename, Data}.
|
||||||
|
|
||||||
config() ->
|
config() ->
|
||||||
#{
|
#{
|
||||||
|
|
|
@ -81,7 +81,7 @@ import_users(post, #{
|
||||||
[{FileName, FileData}] = maps:to_list(maps:without([type], File)),
|
[{FileName, FileData}] = maps:to_list(maps:without([type], File)),
|
||||||
case
|
case
|
||||||
emqx_authn_chains:import_users(
|
emqx_authn_chains:import_users(
|
||||||
ChainName, AuthId, {FileName, FileData}
|
ChainName, AuthId, {hash, FileName, FileData}
|
||||||
)
|
)
|
||||||
of
|
of
|
||||||
ok -> {204};
|
ok -> {204};
|
||||||
|
@ -105,7 +105,7 @@ import_listener_users(post, #{
|
||||||
[{FileName, FileData}] = maps:to_list(maps:without([type], File)),
|
[{FileName, FileData}] = maps:to_list(maps:without([type], File)),
|
||||||
case
|
case
|
||||||
emqx_authn_chains:import_users(
|
emqx_authn_chains:import_users(
|
||||||
ChainName, AuthId, {FileName, FileData}
|
ChainName, AuthId, {hash, FileName, FileData}
|
||||||
)
|
)
|
||||||
of
|
of
|
||||||
ok -> {204};
|
ok -> {204};
|
||||||
|
|
Loading…
Reference in New Issue