diff --git a/Makefile b/Makefile index a8e753a95..e471d50ed 100644 --- a/Makefile +++ b/Makefile @@ -17,11 +17,11 @@ TEST_ERLC_OPTS += +debug_info TEST_ERLC_OPTS += +'{parse_transform, lager_transform}' EUNIT_OPTS = verbose -EUNIT_ERL_OPTS = -args_file test_data/ct_vm.args -config test_data/ct_sys.config +# EUNIT_ERL_OPTS = CT_SUITES = emqttd emqttd_access emqttd_backend emqttd_lib emqttd_mod emqttd_net \ emqttd_mqueue emqttd_protocol emqttd_topic emqttd_trie -CT_OPTS = -cover test/ct.cover.spec -erl_args -args_file test_data/ct_vm.args -config test_data/ct_sys.config +CT_OPTS = -cover test/ct.cover.spec -erl_args -name emqttd_ct@127.0.0.1 COVER = true diff --git a/src/emqttd_acl_internal.erl b/src/emqttd_acl_internal.erl index ff1efcd16..282fb77a4 100644 --- a/src/emqttd_acl_internal.erl +++ b/src/emqttd_acl_internal.erl @@ -113,6 +113,8 @@ match(Client, Topic, [Rule|Rules]) -> %% @doc Reload ACL -spec(reload_acl(State :: #state{}) -> ok | {error, Reason :: any()}). +reload_acl(#state{config = undefined}) -> + ok; reload_acl(State) -> case catch load_rules_from_file(State) of {'EXIT', Error} -> {error, Error}; diff --git a/test/emqttd_SUITE.erl b/test/emqttd_SUITE.erl index 3c507540d..afd5b28d1 100644 --- a/test/emqttd_SUITE.erl +++ b/test/emqttd_SUITE.erl @@ -82,6 +82,8 @@ groups() -> init_per_suite(Config) -> application:start(lager), + DataDir = proplists:get_value(data_dir, Config), + application:set_env(emqttd, conf, filename:join([DataDir, "emqttd.conf"])), application:ensure_all_started(emqttd), Config. @@ -177,7 +179,7 @@ pubsub_queue(_) -> Self = self(), Q = <<"$queue/abc">>, SubFun = fun() -> emqttd:subscribe(Q), - timer:sleep(1), + timer:sleep(10), {ok, Msgs} = loop_recv(Q, 10), Self ! {recv, self(), Msgs} end, diff --git a/test_data/ct_emqttd.conf b/test/emqttd_SUITE_data/emqttd.conf similarity index 100% rename from test_data/ct_emqttd.conf rename to test/emqttd_SUITE_data/emqttd.conf diff --git a/test/emqttd_access_SUITE.erl b/test/emqttd_access_SUITE.erl index 8a8d05766..074fd15df 100644 --- a/test/emqttd_access_SUITE.erl +++ b/test/emqttd_access_SUITE.erl @@ -38,9 +38,34 @@ groups() -> [compile_rule, match_rule]}]. +init_per_group(access_control, Config) -> + application:load(emqttd), + prepare_config(), + gen_conf:init(emqttd), + Config; + init_per_group(_Group, Config) -> Config. +prepare_config() -> + Rules = [{allow, {ipaddr, "127.0.0.1"}, subscribe, ["$SYS/#", "#"]}, + {allow, {user, "testuser"}, subscribe, ["a/b/c", "d/e/f/#"]}, + {allow, {user, "admin"}, pubsub, ["a/b/c", "d/e/f/#"]}, + {allow, {client, "testClient"}, subscribe, ["testTopics/testClient"]}, + {allow, all, subscribe, ["clients/$c"]}, + {allow, all, pubsub, ["users/$u/#"]}, + {deny, all, subscribe, ["$SYS/#", "#"]}, + {deny, all}], + write_config("access_SUITE_acl.conf", Rules), + Config = [{auth, anonymous, []}, + {acl, internal, [{config, "access_SUITE_acl.conf"}, + {nomatch, allow}]}], + write_config("access_SUITE_emqttd.conf", Config), + application:set_env(emqttd, conf, "access_SUITE_emqttd.conf"). + +write_config(Filename, Terms) -> + file:write_file(Filename, [io_lib:format("~tp.~n", [Term]) || Term <- Terms]). + end_per_group(_Group, Config) -> Config. @@ -48,14 +73,7 @@ init_per_testcase(TestCase, Config) when TestCase =:= reload_acl; TestCase =:= register_mod; TestCase =:= unregister_mod; TestCase =:= check_acl -> - DataDir = proplists:get_value(data_dir, Config), - AclOpts = [ - {auth, [{anonymous, []}]}, - {acl, [{internal, [{file, filename:join([DataDir, "test_acl.config"])}, - {nomatch, allow}]}]} - ], - {ok, _Pid} = ?AC:start_link(AclOpts), - Config; + {ok, _Pid} = ?AC:start_link(), Config; init_per_testcase(_TestCase, Config) -> Config. diff --git a/test/emqttd_access_SUITE_data/test_acl.config b/test/emqttd_access_SUITE_data/test_acl.config deleted file mode 100644 index 4a2c6ea44..000000000 --- a/test/emqttd_access_SUITE_data/test_acl.config +++ /dev/null @@ -1,16 +0,0 @@ -{allow, {ipaddr, "127.0.0.1"}, subscribe, ["$SYS/#", "#"]}. - -{allow, {user, "testuser"}, subscribe, ["a/b/c", "d/e/f/#"]}. - -{allow, {user, "admin"}, pubsub, ["a/b/c", "d/e/f/#"]}. - -{allow, {client, "testClient"}, subscribe, ["testTopics/testClient"]}. - -{allow, all, subscribe, ["clients/$c"]}. - -{allow, all, pubsub, ["users/$u/#"]}. - -{deny, all, subscribe, ["$SYS/#", "#"]}. - -{deny, all}. - diff --git a/test_data/ct_sys.config b/test_data/ct_sys.config deleted file mode 100644 index 67f13b910..000000000 --- a/test_data/ct_sys.config +++ /dev/null @@ -1,6 +0,0 @@ -% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*- -%% ex: ft=erlang ts=4 sw=4 et -[ - {kernel, [{start_timer, true}, {start_pg2, true}]}, - {emqttd, [{conf, "test_data/ct_emqttd.conf"}]} -]. diff --git a/test_data/ct_vm.args b/test_data/ct_vm.args deleted file mode 100644 index e05e373a4..000000000 --- a/test_data/ct_vm.args +++ /dev/null @@ -1,61 +0,0 @@ -##------------------------------------------------------------------------- -## Name of the emqttd node: Name@Host -## -## NOTICE: The Host should be IP address or the fully qualified host name. -## The short hostname cannot work! -##------------------------------------------------------------------------- - --name emqttd_ct@127.0.0.1 -# or -#-name emqttd@localhost. - -## Cookie for distributed erlang --setcookie emqttdsecretcookie - -##------------------------------------------------------------------------- -## Flags -##------------------------------------------------------------------------- - -## Heartbeat management; auto-restarts VM if it dies or becomes unresponsive -## (Disabled by default..use with caution!) -##-heart --smp true - -## Enable kernel poll and a few async threads -+K true - -## 12 threads/core. -+A 24 - -## max process numbers -#+P 8192 - -## Sets the maximum number of simultaneously existing ports for this system -#+Q 8192 - -## max atom number -## +t - -## Set the distribution buffer busy limit (dist_buf_busy_limit) in kilobytes. -## Valid range is 1-2097151. Default is 1024. -## +zdbbl 8192 - -## Set scheduler bind type. -## +sbt db - -##------------------------------------------------------------------------- -## Env -##------------------------------------------------------------------------- - -## Increase number of concurrent ports/sockets, deprecated in R17 -#-env ERL_MAX_PORTS 8192 - -#-env ERTS_MAX_PORTS 8192 - -## Mnesia and SSL will create temporary ets tables. --env ERL_MAX_ETS_TABLES 1024 - -## Tweak GC to run more often --env ERL_FULLSWEEP_AFTER 1000 - --env ERL_CRASH_DUMP log/emqttd_crash.dump