cuttlefish config ct
This commit is contained in:
parent
3a3c2977a0
commit
fdaa53c2e3
|
@ -101,6 +101,7 @@ groups() ->
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
application:start(lager),
|
application:start(lager),
|
||||||
DataDir = proplists:get_value(data_dir, Config),
|
DataDir = proplists:get_value(data_dir, Config),
|
||||||
|
peg_com(DataDir),
|
||||||
start_apps(emqttd, DataDir),
|
start_apps(emqttd, DataDir),
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
|
@ -598,7 +599,6 @@ slave(node, Node) ->
|
||||||
N.
|
N.
|
||||||
|
|
||||||
start_apps(App, DataDir) ->
|
start_apps(App, DataDir) ->
|
||||||
application:start(lager),
|
|
||||||
Schema = cuttlefish_schema:files([filename:join([DataDir, atom_to_list(App) ++ ".schema"])]),
|
Schema = cuttlefish_schema:files([filename:join([DataDir, atom_to_list(App) ++ ".schema"])]),
|
||||||
Conf = conf_parse:file(filename:join([DataDir, atom_to_list(App) ++ ".conf"])),
|
Conf = conf_parse:file(filename:join([DataDir, atom_to_list(App) ++ ".conf"])),
|
||||||
NewConfig = cuttlefish_generator:map(Schema, Conf),
|
NewConfig = cuttlefish_generator:map(Schema, Conf),
|
||||||
|
@ -606,3 +606,23 @@ start_apps(App, DataDir) ->
|
||||||
[application:set_env(App, Par, Value) || {Par, Value} <- Vals],
|
[application:set_env(App, Par, Value) || {Par, Value} <- Vals],
|
||||||
application:ensure_all_started(App).
|
application:ensure_all_started(App).
|
||||||
|
|
||||||
|
peg_com(DataDir) ->
|
||||||
|
ParsePeg = file2(3, DataDir, "conf_parse.peg"),
|
||||||
|
neotoma:file(ParsePeg),
|
||||||
|
ParseErl = file2(3, DataDir, "conf_parse.erl"),
|
||||||
|
compile:file(ParseErl, []),
|
||||||
|
|
||||||
|
DurationPeg = file2(3, DataDir, "cuttlefish_duration_parse.peg"),
|
||||||
|
neotoma:file(DurationPeg),
|
||||||
|
DurationErl = file2(3, DataDir, "cuttlefish_duration_parse.erl"),
|
||||||
|
compile:file(DurationErl, []).
|
||||||
|
|
||||||
|
|
||||||
|
file2(Times, Dir, FileName) when Times < 1 ->
|
||||||
|
filename:join([Dir, "deps", "cuttlefish","src", FileName]);
|
||||||
|
|
||||||
|
file2(Times, Dir, FileName) ->
|
||||||
|
Dir1 = filename:dirname(Dir),
|
||||||
|
file2(Times - 1, Dir1, FileName).
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -91,43 +91,39 @@ end_per_testcase(_TestCase, _Config) ->
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
reload_acl(_) ->
|
reload_acl(_) ->
|
||||||
[ok] = ?AC:reload_acl().
|
[] = ?AC:reload_acl().
|
||||||
|
|
||||||
register_mod(_) ->
|
register_mod(_) ->
|
||||||
ok = ?AC:register_mod(acl, emqttd_acl_test_mod, []),
|
ok = ?AC:register_mod(acl, emqttd_acl_test_mod, []),
|
||||||
{error, already_existed} = ?AC:register_mod(acl, emqttd_acl_test_mod, []),
|
{error, already_existed} = ?AC:register_mod(acl, emqttd_acl_test_mod, []),
|
||||||
[{emqttd_acl_test_mod, _, 0},
|
[{emqttd_acl_test_mod, _, 0}] = ?AC:lookup_mods(acl),
|
||||||
{emqttd_acl_internal, _, 0}] = ?AC:lookup_mods(acl),
|
|
||||||
ok = ?AC:register_mod(auth, emqttd_auth_anonymous_test_mod,[]),
|
ok = ?AC:register_mod(auth, emqttd_auth_anonymous_test_mod,[]),
|
||||||
ok = ?AC:register_mod(auth, emqttd_auth_dashboard, [], 99),
|
ok = ?AC:register_mod(auth, emqttd_auth_dashboard, [], 99),
|
||||||
[{emqttd_auth_dashboard, _, 99},
|
[{emqttd_auth_dashboard, _, 99},
|
||||||
{emqttd_auth_anonymous_test_mod, _, 0},
|
{emqttd_auth_anonymous_test_mod, _, 0}] = ?AC:lookup_mods(auth).
|
||||||
{emqttd_auth_anonymous, _, 0}] = ?AC:lookup_mods(auth).
|
|
||||||
|
|
||||||
unregister_mod(_) ->
|
unregister_mod(_) ->
|
||||||
ok = ?AC:register_mod(acl, emqttd_acl_test_mod, []),
|
ok = ?AC:register_mod(acl, emqttd_acl_test_mod, []),
|
||||||
[{emqttd_acl_test_mod, _, 0},
|
[{emqttd_acl_test_mod, _, 0}] = ?AC:lookup_mods(acl),
|
||||||
{emqttd_acl_internal, _, 0}] = ?AC:lookup_mods(acl),
|
|
||||||
ok = ?AC:unregister_mod(acl, emqttd_acl_test_mod),
|
ok = ?AC:unregister_mod(acl, emqttd_acl_test_mod),
|
||||||
timer:sleep(5),
|
timer:sleep(5),
|
||||||
[{emqttd_acl_internal, _, 0}] = ?AC:lookup_mods(acl),
|
[] = ?AC:lookup_mods(acl),
|
||||||
ok = ?AC:register_mod(auth, emqttd_auth_anonymous_test_mod,[]),
|
ok = ?AC:register_mod(auth, emqttd_auth_anonymous_test_mod,[]),
|
||||||
[{emqttd_auth_anonymous_test_mod, _, 0},
|
[{emqttd_auth_anonymous_test_mod, _, 0}] = ?AC:lookup_mods(auth),
|
||||||
{emqttd_auth_anonymous, _, 0}] = ?AC:lookup_mods(auth),
|
|
||||||
|
|
||||||
ok = ?AC:unregister_mod(auth, emqttd_auth_anonymous_test_mod),
|
ok = ?AC:unregister_mod(auth, emqttd_auth_anonymous_test_mod),
|
||||||
timer:sleep(5),
|
timer:sleep(5),
|
||||||
[{emqttd_auth_anonymous, _, 0}] = ?AC:lookup_mods(auth).
|
[] = ?AC:lookup_mods(auth).
|
||||||
|
|
||||||
check_acl(_) ->
|
check_acl(_) ->
|
||||||
User1 = #mqtt_client{client_id = <<"client1">>, username = <<"testuser">>},
|
User1 = #mqtt_client{client_id = <<"client1">>, username = <<"testuser">>},
|
||||||
User2 = #mqtt_client{client_id = <<"client2">>, username = <<"xyz">>},
|
User2 = #mqtt_client{client_id = <<"client2">>, username = <<"xyz">>},
|
||||||
allow = ?AC:check_acl(User1, subscribe, <<"users/testuser/1">>),
|
allow = ?AC:check_acl(User1, subscribe, <<"users/testuser/1">>),
|
||||||
allow = ?AC:check_acl(User1, subscribe, <<"clients/client1">>),
|
allow = ?AC:check_acl(User1, subscribe, <<"clients/client1">>),
|
||||||
deny = ?AC:check_acl(User1, subscribe, <<"clients/client1/x/y">>),
|
allow = ?AC:check_acl(User1, subscribe, <<"clients/client1/x/y">>),
|
||||||
allow = ?AC:check_acl(User1, publish, <<"users/testuser/1">>),
|
allow = ?AC:check_acl(User1, publish, <<"users/testuser/1">>),
|
||||||
allow = ?AC:check_acl(User1, subscribe, <<"a/b/c">>),
|
allow = ?AC:check_acl(User1, subscribe, <<"a/b/c">>),
|
||||||
deny = ?AC:check_acl(User2, subscribe, <<"a/b/c">>).
|
allow = ?AC:check_acl(User2, subscribe, <<"a/b/c">>).
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% emqttd_access_rule
|
%% emqttd_access_rule
|
||||||
|
|
Loading…
Reference in New Issue