|
|
@@ -26,13 +26,13 @@
|
|
|
-include_lib("emqx_auth_mnesia/include/emqx_auth_mnesia.hrl").
|
|
|
|
|
|
-ifdef(EMQX_ENTERPRISE).
|
|
|
--define(VERSIONS, ["e4.1", "e4.2"]).
|
|
|
+-define(VERSIONS, ["e4.1.1", "e4.2.9"]).
|
|
|
-else.
|
|
|
--define(VERSIONS, ["v4.1", "v4.2"]).
|
|
|
+-define(VERSIONS, ["v4.1.5", "v4.2.9"]).
|
|
|
-endif.
|
|
|
|
|
|
all() ->
|
|
|
- [{group, Id} || {Id, _, _} <- groups()].
|
|
|
+ [{group, Id} || {Id, _, _} <- groups()] ++ [t_import_4_0].
|
|
|
|
|
|
groups() ->
|
|
|
[{username, [], cases()}, {clientid, [], cases()}].
|
|
|
@@ -53,7 +53,9 @@ end_per_suite(_Config) ->
|
|
|
init_per_group(username, Config) ->
|
|
|
[{cred_type, username} | Config];
|
|
|
init_per_group(clientid, Config) ->
|
|
|
- [{cred_type, clientid} | Config].
|
|
|
+ [{cred_type, clientid} | Config];
|
|
|
+init_per_group(_, Config) ->
|
|
|
+ Config.
|
|
|
|
|
|
end_per_group(_, Config) ->
|
|
|
Config.
|
|
|
@@ -71,9 +73,20 @@ t_import(Config) ->
|
|
|
|
|
|
test_import(Config, [V | Versions]) ->
|
|
|
do_import(Config, V),
|
|
|
+ test_clientid_import(),
|
|
|
test_import(Config, Versions);
|
|
|
test_import(_Config, []) -> ok.
|
|
|
|
|
|
+%% This version is special, since it doesn't have mnesia ACL plugin
|
|
|
+t_import_4_0(Config) ->
|
|
|
+ mnesia:clear_table(emqx_acl),
|
|
|
+ mnesia:clear_table(emqx_user),
|
|
|
+ Filename = filename:join(proplists:get_value(data_dir, Config), "v4.0.7.json"),
|
|
|
+ Overrides = emqx_json:encode(#{<<"auth.mnesia.as">> => atom_to_binary(clientid)}),
|
|
|
+ ?assertMatch(ok, emqx_mgmt_data_backup:import(Filename, Overrides)),
|
|
|
+ timer:sleep(100),
|
|
|
+ test_clientid_import().
|
|
|
+
|
|
|
do_import(Config, V) ->
|
|
|
File = V ++ ".json",
|
|
|
Type = proplists:get_value(cred_type, Config),
|
|
|
@@ -95,12 +108,20 @@ do_import(Config, V) ->
|
|
|
access = allow
|
|
|
}],
|
|
|
lists:sort(Records)),
|
|
|
- ?assertMatch([#emqx_user{
|
|
|
- login = {Type, <<"emqx_c">>}
|
|
|
- }], ets:tab2list(emqx_user)),
|
|
|
+ ?assertMatch([_, _], ets:tab2list(emqx_user)),
|
|
|
+ ?assertMatch([_], ets:lookup(emqx_user, {Type, <<"emqx_c">>})),
|
|
|
Req = #{clientid => <<"blah">>}
|
|
|
#{Type => <<"emqx_c">>,
|
|
|
password => "emqx_p"
|
|
|
},
|
|
|
?assertMatch({stop, #{auth_result := success}},
|
|
|
emqx_auth_mnesia:check(Req, #{}, #{hash_type => sha256})).
|
|
|
+
|
|
|
+test_clientid_import() ->
|
|
|
+ [#emqx_user{password = _Pass}] = ets:lookup(emqx_user, {clientid, <<"emqx_clientid">>}),
|
|
|
+ Req = #{clientid => <<"emqx_clientid">>,
|
|
|
+ password => <<"emqx_p">>
|
|
|
+ },
|
|
|
+ catch %% TODO currently broken on some releases.
|
|
|
+ ?assertMatch({stop, #{auth_result := success}},
|
|
|
+ emqx_auth_mnesia:check(Req, #{}, #{hash_type => sha256})).
|