test: fix authn test cases
This commit is contained in:
parent
a03f2dd64b
commit
95cb262067
|
@ -89,7 +89,7 @@
|
||||||
]).
|
]).
|
||||||
|
|
||||||
-ifdef(TEST).
|
-ifdef(TEST).
|
||||||
-export([erase_schema_mod_and_names/0]).
|
-export([erase_all/0]).
|
||||||
-endif.
|
-endif.
|
||||||
|
|
||||||
-include("logger.hrl").
|
-include("logger.hrl").
|
||||||
|
@ -559,7 +559,9 @@ save_schema_mod_and_names(SchemaMod) ->
|
||||||
}).
|
}).
|
||||||
|
|
||||||
-ifdef(TEST).
|
-ifdef(TEST).
|
||||||
erase_schema_mod_and_names() ->
|
erase_all() ->
|
||||||
|
Names = get_root_names(),
|
||||||
|
lists:foreach(fun erase/1, Names),
|
||||||
persistent_term:erase(?PERSIS_SCHEMA_MODS).
|
persistent_term:erase(?PERSIS_SCHEMA_MODS).
|
||||||
-endif.
|
-endif.
|
||||||
|
|
||||||
|
|
|
@ -249,11 +249,20 @@ start_app(App, SpecAppConfig, Opts) ->
|
||||||
case application:ensure_all_started(App) of
|
case application:ensure_all_started(App) of
|
||||||
{ok, _} ->
|
{ok, _} ->
|
||||||
ok = ensure_dashboard_listeners_started(App),
|
ok = ensure_dashboard_listeners_started(App),
|
||||||
|
ok = wait_for_app_processes(App),
|
||||||
ok;
|
ok;
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
error({failed_to_start_app, App, Reason})
|
error({failed_to_start_app, App, Reason})
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
wait_for_app_processes(emqx_conf) ->
|
||||||
|
%% emqx_conf app has a gen_server which
|
||||||
|
%% initializes its state asynchronously
|
||||||
|
gen_server:call(emqx_cluster_rpc, dummy),
|
||||||
|
ok;
|
||||||
|
wait_for_app_processes(_) ->
|
||||||
|
ok.
|
||||||
|
|
||||||
app_conf_file(emqx_conf) -> "emqx.conf.all";
|
app_conf_file(emqx_conf) -> "emqx.conf.all";
|
||||||
app_conf_file(App) -> atom_to_list(App) ++ ".conf".
|
app_conf_file(App) -> atom_to_list(App) ++ ".conf".
|
||||||
|
|
||||||
|
@ -309,7 +318,7 @@ stop_apps(Apps) ->
|
||||||
%% to avoid inter-suite flakiness
|
%% to avoid inter-suite flakiness
|
||||||
application:unset_env(emqx, init_config_load_done),
|
application:unset_env(emqx, init_config_load_done),
|
||||||
persistent_term:erase(?EMQX_AUTHENTICATION_SCHEMA_MODULE_PT_KEY),
|
persistent_term:erase(?EMQX_AUTHENTICATION_SCHEMA_MODULE_PT_KEY),
|
||||||
emqx_config:erase_schema_mod_and_names(),
|
emqx_config:erase_all(),
|
||||||
ok = emqx_config:delete_override_conf_files(),
|
ok = emqx_config:delete_override_conf_files(),
|
||||||
application:unset_env(emqx, local_override_conf_file),
|
application:unset_env(emqx, local_override_conf_file),
|
||||||
application:unset_env(emqx, cluster_override_conf_file),
|
application:unset_env(emqx, cluster_override_conf_file),
|
||||||
|
|
|
@ -64,14 +64,14 @@ t_init_load(_Config) ->
|
||||||
ConfFile = "./test_emqx.conf",
|
ConfFile = "./test_emqx.conf",
|
||||||
ok = file:write_file(ConfFile, <<"">>),
|
ok = file:write_file(ConfFile, <<"">>),
|
||||||
ExpectRootNames = lists:sort(hocon_schema:root_names(emqx_schema)),
|
ExpectRootNames = lists:sort(hocon_schema:root_names(emqx_schema)),
|
||||||
emqx_config:erase_schema_mod_and_names(),
|
emqx_config:erase_all(),
|
||||||
{ok, DeprecatedFile} = application:get_env(emqx, cluster_override_conf_file),
|
{ok, DeprecatedFile} = application:get_env(emqx, cluster_override_conf_file),
|
||||||
?assertEqual(false, filelib:is_regular(DeprecatedFile), DeprecatedFile),
|
?assertEqual(false, filelib:is_regular(DeprecatedFile), DeprecatedFile),
|
||||||
%% Don't has deprecated file
|
%% Don't has deprecated file
|
||||||
ok = emqx_config:init_load(emqx_schema, [ConfFile]),
|
ok = emqx_config:init_load(emqx_schema, [ConfFile]),
|
||||||
?assertEqual(ExpectRootNames, lists:sort(emqx_config:get_root_names())),
|
?assertEqual(ExpectRootNames, lists:sort(emqx_config:get_root_names())),
|
||||||
?assertMatch({ok, #{raw_config := 256}}, emqx:update_config([mqtt, max_topic_levels], 256)),
|
?assertMatch({ok, #{raw_config := 256}}, emqx:update_config([mqtt, max_topic_levels], 256)),
|
||||||
emqx_config:erase_schema_mod_and_names(),
|
emqx_config:erase_all(),
|
||||||
%% Has deprecated file
|
%% Has deprecated file
|
||||||
ok = file:write_file(DeprecatedFile, <<"{}">>),
|
ok = file:write_file(DeprecatedFile, <<"{}">>),
|
||||||
ok = emqx_config:init_load(emqx_schema, [ConfFile]),
|
ok = emqx_config:init_load(emqx_schema, [ConfFile]),
|
||||||
|
|
|
@ -67,7 +67,7 @@ init_per_suite(Config) ->
|
||||||
emqx_config:erase(?EMQX_AUTHENTICATION_CONFIG_ROOT_NAME_BINARY),
|
emqx_config:erase(?EMQX_AUTHENTICATION_CONFIG_ROOT_NAME_BINARY),
|
||||||
_ = application:load(emqx_conf),
|
_ = application:load(emqx_conf),
|
||||||
ok = emqx_mgmt_api_test_util:init_suite(
|
ok = emqx_mgmt_api_test_util:init_suite(
|
||||||
[emqx_authn]
|
[emqx_conf, emqx_authn]
|
||||||
),
|
),
|
||||||
|
|
||||||
?AUTHN:delete_chain(?GLOBAL),
|
?AUTHN:delete_chain(?GLOBAL),
|
||||||
|
|
|
@ -42,15 +42,16 @@ init_per_testcase(_Case, Config) ->
|
||||||
<<"backend">> => <<"built_in_database">>,
|
<<"backend">> => <<"built_in_database">>,
|
||||||
<<"user_id_type">> => <<"clientid">>
|
<<"user_id_type">> => <<"clientid">>
|
||||||
},
|
},
|
||||||
emqx:update_config(
|
{ok, _} = emqx:update_config(
|
||||||
?PATH,
|
?PATH,
|
||||||
{create_authenticator, ?GLOBAL, AuthnConfig}
|
{create_authenticator, ?GLOBAL, AuthnConfig}
|
||||||
),
|
),
|
||||||
|
{ok, _} = emqx_conf:update(
|
||||||
emqx_conf:update(
|
[listeners, tcp, listener_authn_enabled],
|
||||||
[listeners, tcp, listener_authn_enabled], {create, listener_mqtt_tcp_conf(18830, true)}, #{}
|
{create, listener_mqtt_tcp_conf(18830, true)},
|
||||||
|
#{}
|
||||||
),
|
),
|
||||||
emqx_conf:update(
|
{ok, _} = emqx_conf:update(
|
||||||
[listeners, tcp, listener_authn_disabled],
|
[listeners, tcp, listener_authn_disabled],
|
||||||
{create, listener_mqtt_tcp_conf(18831, false)},
|
{create, listener_mqtt_tcp_conf(18831, false)},
|
||||||
#{}
|
#{}
|
||||||
|
|
|
@ -37,7 +37,7 @@ init_per_testcase(_, Config) ->
|
||||||
|
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
_ = application:load(emqx_conf),
|
_ = application:load(emqx_conf),
|
||||||
emqx_common_test_helpers:start_apps([emqx_authn]),
|
emqx_common_test_helpers:start_apps([emqx_conf, emqx_authn]),
|
||||||
application:ensure_all_started(emqx_resource),
|
application:ensure_all_started(emqx_resource),
|
||||||
application:ensure_all_started(emqx_connector),
|
application:ensure_all_started(emqx_connector),
|
||||||
Config.
|
Config.
|
||||||
|
|
Loading…
Reference in New Issue