Add more test cases for emqx_mod_acl_internal
This commit is contained in:
parent
cc9ad392af
commit
0dd45aeb3c
|
@ -19,28 +19,53 @@
|
||||||
-compile(export_all).
|
-compile(export_all).
|
||||||
-compile(nowarn_export_all).
|
-compile(nowarn_export_all).
|
||||||
|
|
||||||
|
-include("emqx_mqtt.hrl").
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
|
|
||||||
all() -> emqx_ct:all(?MODULE).
|
all() -> emqx_ct:all(?MODULE).
|
||||||
|
|
||||||
init_per_testcase(_TestCase, Config) ->
|
init_per_suite(Config) ->
|
||||||
|
emqx_ct_helpers:boot_modules(all),
|
||||||
|
emqx_ct_helpers:start_apps([emqx]),
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
end_per_testcase(_TestCase, Config) ->
|
end_per_suite(_Config) ->
|
||||||
Config.
|
emqx_ct_helpers:stop_apps([emqx]).
|
||||||
|
|
||||||
% t_load(_) ->
|
t_load_unload(_) ->
|
||||||
% error('TODO').
|
?assertEqual({error,already_exists}, emqx_mod_acl_internal:load([])),
|
||||||
|
?assertEqual(ok, emqx_mod_acl_internal:unload([])),
|
||||||
|
?assertEqual(ok, emqx_mod_acl_internal:load([])).
|
||||||
|
|
||||||
% t_unload(_) ->
|
t_all_rules(_) ->
|
||||||
% error('TODO').
|
application:set_env(emqx, acl_file, ""),
|
||||||
|
?assertMatch(#{}, emqx_mod_acl_internal:all_rules()),
|
||||||
|
|
||||||
% t_all_rules(_) ->
|
application:set_env(emqx, acl_file, emqx_ct_helpers:deps_path(emqx, "etc/acl.conf")),
|
||||||
% error('TODO').
|
?assertMatch(#{publish := _, subscribe := _}, emqx_mod_acl_internal:all_rules()).
|
||||||
|
|
||||||
% t_check_acl(_) ->
|
t_check_acl(_) ->
|
||||||
% error('TODO').
|
Rules=#{publish => [{allow,all}], subscribe => [{deny, all}]},
|
||||||
|
?assertEqual({ok, allow}, emqx_mod_acl_internal:check_acl(clientinfo(), publish, <<"t">>, [], Rules)),
|
||||||
|
?assertEqual({ok, deny}, emqx_mod_acl_internal:check_acl(clientinfo(), subscribe, <<"t">>, [], Rules)),
|
||||||
|
?assertEqual(ok, emqx_mod_acl_internal:check_acl(clientinfo(), connect, <<"t">>, [], Rules)).
|
||||||
|
|
||||||
% t_reload_acl(_) ->
|
t_reload_acl(_) ->
|
||||||
% error('TODO').
|
?assertEqual(ok, emqx_mod_acl_internal:reload_acl()).
|
||||||
|
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
%% Helper functions
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
|
clientinfo() -> clientinfo(#{}).
|
||||||
|
clientinfo(InitProps) ->
|
||||||
|
maps:merge(#{zone => zone,
|
||||||
|
protocol => mqtt,
|
||||||
|
peerhost => {127,0,0,1},
|
||||||
|
clientid => <<"clientid">>,
|
||||||
|
username => <<"username">>,
|
||||||
|
password => <<"passwd">>,
|
||||||
|
is_superuser => false,
|
||||||
|
peercert => undefined,
|
||||||
|
mountpoint => undefined
|
||||||
|
}, InitProps).
|
||||||
|
|
Loading…
Reference in New Issue