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