test: cover password_type and new data format
This commit is contained in:
parent
829887630d
commit
8fc8106819
|
@ -0,0 +1,3 @@
|
||||||
|
user_id,password,is_superuser
|
||||||
|
myuser3,password3,true
|
||||||
|
myuser4,password4,false
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"user_id":"myuser1",
|
||||||
|
"password":"password1",
|
||||||
|
"is_superuser": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"user_id":"myuser2",
|
||||||
|
"password":"password2",
|
||||||
|
"is_superuser": false
|
||||||
|
}
|
||||||
|
]
|
|
@ -336,7 +336,13 @@ test_authenticator_import_users(PathPrefix) ->
|
||||||
{ok, CSVData} = file:read_file(CSVFileName),
|
{ok, CSVData} = file:read_file(CSVFileName),
|
||||||
{ok, 204, _} = multipart_formdata_request(ImportUri, [], [
|
{ok, 204, _} = multipart_formdata_request(ImportUri, [], [
|
||||||
{filename, "user-credentials.csv", CSVData}
|
{filename, "user-credentials.csv", CSVData}
|
||||||
]).
|
]),
|
||||||
|
|
||||||
|
%% test application/json
|
||||||
|
{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)),
|
||||||
|
ok.
|
||||||
|
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
%% Helpers
|
%% Helpers
|
||||||
|
|
|
@ -253,6 +253,69 @@ t_import_users(_) ->
|
||||||
)
|
)
|
||||||
).
|
).
|
||||||
|
|
||||||
|
t_import_users_plain(_) ->
|
||||||
|
Config0 = config(),
|
||||||
|
Config = Config0#{password_hash_algorithm => #{name => sha256, salt_position => suffix}},
|
||||||
|
{ok, State} = emqx_authn_mnesia:create(?AUTHN_ID, Config),
|
||||||
|
|
||||||
|
?assertEqual(
|
||||||
|
ok,
|
||||||
|
emqx_authn_mnesia:import_users(
|
||||||
|
sample_filename_and_data(plain, <<"user-credentials-plain.json">>),
|
||||||
|
State
|
||||||
|
)
|
||||||
|
),
|
||||||
|
|
||||||
|
?assertEqual(
|
||||||
|
ok,
|
||||||
|
emqx_authn_mnesia:import_users(
|
||||||
|
sample_filename_and_data(plain, <<"user-credentials-plain.csv">>),
|
||||||
|
State
|
||||||
|
)
|
||||||
|
).
|
||||||
|
|
||||||
|
t_import_users_prepared_list(_) ->
|
||||||
|
Config0 = config(),
|
||||||
|
Config = Config0#{password_hash_algorithm => #{name => sha256, salt_position => suffix}},
|
||||||
|
{ok, State} = emqx_authn_mnesia:create(?AUTHN_ID, Config),
|
||||||
|
|
||||||
|
Users1 = [
|
||||||
|
#{<<"user_id">> => <<"u1">>, <<"password">> => <<"p1">>, <<"is_superuser">> => true},
|
||||||
|
#{<<"user_id">> => <<"u2">>, <<"password">> => <<"p2">>, <<"is_superuser">> => true}
|
||||||
|
],
|
||||||
|
Users2 = [
|
||||||
|
#{
|
||||||
|
<<"user_id">> => <<"u3">>,
|
||||||
|
<<"password_hash">> =>
|
||||||
|
<<"c5e46903df45e5dc096dc74657610dbee8deaacae656df88a1788f1847390242">>,
|
||||||
|
<<"salt">> => <<"e378187547bf2d6f0545a3f441aa4d8a">>,
|
||||||
|
<<"is_superuser">> => true
|
||||||
|
},
|
||||||
|
#{
|
||||||
|
<<"user_id">> => <<"u4">>,
|
||||||
|
<<"password_hash">> =>
|
||||||
|
<<"f4d17f300b11e522fd33f497c11b126ef1ea5149c74d2220f9a16dc876d4567b">>,
|
||||||
|
<<"salt">> => <<"6d3f9bd5b54d94b98adbcfe10b6d181f">>,
|
||||||
|
<<"is_superuser">> => true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
|
||||||
|
?assertEqual(
|
||||||
|
ok,
|
||||||
|
emqx_authn_mnesia:import_users(
|
||||||
|
{plain, prepared_user_list, Users1},
|
||||||
|
State
|
||||||
|
)
|
||||||
|
),
|
||||||
|
|
||||||
|
?assertEqual(
|
||||||
|
ok,
|
||||||
|
emqx_authn_mnesia:import_users(
|
||||||
|
{hash, prepared_user_list, Users2},
|
||||||
|
State
|
||||||
|
)
|
||||||
|
).
|
||||||
|
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
%% Helpers
|
%% Helpers
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
|
@ -262,9 +325,12 @@ sample_filename(Name) ->
|
||||||
filename:join([Dir, <<"data">>, Name]).
|
filename:join([Dir, <<"data">>, Name]).
|
||||||
|
|
||||||
sample_filename_and_data(Name) ->
|
sample_filename_and_data(Name) ->
|
||||||
|
sample_filename_and_data(hash, Name).
|
||||||
|
|
||||||
|
sample_filename_and_data(Type, Name) ->
|
||||||
Filename = sample_filename(Name),
|
Filename = sample_filename(Name),
|
||||||
{ok, Data} = file:read_file(Filename),
|
{ok, Data} = file:read_file(Filename),
|
||||||
{hash, Filename, Data}.
|
{Type, Filename, Data}.
|
||||||
|
|
||||||
config() ->
|
config() ->
|
||||||
#{
|
#{
|
||||||
|
|
Loading…
Reference in New Issue