fix: avoid emqx starting crash if bootstrap_file is not existed
This commit is contained in:
parent
da3937b80e
commit
88ac8631a0
|
@ -28,13 +28,9 @@
|
|||
-include("emqx_mgmt.hrl").
|
||||
|
||||
start(_Type, _Args) ->
|
||||
case emqx_mgmt_auth:init_bootstrap_file() of
|
||||
ok ->
|
||||
emqx_conf:add_handler([api_key], emqx_mgmt_auth),
|
||||
emqx_mgmt_sup:start_link();
|
||||
{error, Reason} ->
|
||||
{error, Reason}
|
||||
end.
|
||||
_ = emqx_mgmt_auth:init_bootstrap_file(),
|
||||
emqx_conf:add_handler([api_key], emqx_mgmt_auth),
|
||||
emqx_mgmt_sup:start_link().
|
||||
|
||||
stop(_State) ->
|
||||
emqx_conf:remove_handler([api_key]),
|
||||
|
|
|
@ -52,7 +52,12 @@ groups() ->
|
|||
[
|
||||
{parallel, [parallel], [t_create, t_update, t_delete, t_authorize, t_create_unexpired_app]},
|
||||
{parallel, [parallel], ?EE_CASES},
|
||||
{sequence, [], [t_bootstrap_file, t_bootstrap_file_with_role, t_create_failed]}
|
||||
{sequence, [], [
|
||||
t_application_start_with_non_exist_file,
|
||||
t_bootstrap_file,
|
||||
t_bootstrap_file_with_role,
|
||||
t_create_failed
|
||||
]}
|
||||
].
|
||||
|
||||
init_per_suite(Config) ->
|
||||
|
@ -62,6 +67,18 @@ init_per_suite(Config) ->
|
|||
end_per_suite(_) ->
|
||||
emqx_mgmt_api_test_util:end_suite([emqx_conf, emqx_management]).
|
||||
|
||||
t_application_start_with_non_exist_file(_) ->
|
||||
application:stop(emqx_management),
|
||||
|
||||
Original = emqx_config:get_raw([api_key, bootstrap_file]),
|
||||
update_file(<<"non-exist-file">>),
|
||||
|
||||
%% assert: start the application succeed with a non-exist bootstrap_file
|
||||
ok = application:start(emqx_management),
|
||||
|
||||
update_file(Original),
|
||||
ok.
|
||||
|
||||
t_bootstrap_file(_) ->
|
||||
TestPath = <<"/api/v5/status">>,
|
||||
Bin = <<"test-1:secret-1\ntest-2:secret-2">>,
|
||||
|
|
Loading…
Reference in New Issue