Compare commits

...

2 Commits

Author SHA1 Message Date
JianBo He f3560ed5fa chore: update changes 2024-01-05 16:53:55 +08:00
JianBo He 88ac8631a0 fix: avoid emqx starting crash if bootstrap_file is not existed 2024-01-05 16:41:13 +08:00
3 changed files with 22 additions and 8 deletions

View File

@ -28,13 +28,9 @@
-include("emqx_mgmt.hrl"). -include("emqx_mgmt.hrl").
start(_Type, _Args) -> start(_Type, _Args) ->
case emqx_mgmt_auth:init_bootstrap_file() of _ = emqx_mgmt_auth:init_bootstrap_file(),
ok -> emqx_conf:add_handler([api_key], emqx_mgmt_auth),
emqx_conf:add_handler([api_key], emqx_mgmt_auth), emqx_mgmt_sup:start_link().
emqx_mgmt_sup:start_link();
{error, Reason} ->
{error, Reason}
end.
stop(_State) -> stop(_State) ->
emqx_conf:remove_handler([api_key]), emqx_conf:remove_handler([api_key]),

View File

@ -52,7 +52,12 @@ groups() ->
[ [
{parallel, [parallel], [t_create, t_update, t_delete, t_authorize, t_create_unexpired_app]}, {parallel, [parallel], [t_create, t_update, t_delete, t_authorize, t_create_unexpired_app]},
{parallel, [parallel], ?EE_CASES}, {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) -> init_per_suite(Config) ->
@ -62,6 +67,18 @@ init_per_suite(Config) ->
end_per_suite(_) -> end_per_suite(_) ->
emqx_mgmt_api_test_util:end_suite([emqx_conf, emqx_management]). 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(_) -> t_bootstrap_file(_) ->
TestPath = <<"/api/v5/status">>, TestPath = <<"/api/v5/status">>,
Bin = <<"test-1:secret-1\ntest-2:secret-2">>, Bin = <<"test-1:secret-1\ntest-2:secret-2">>,

View File

@ -0,0 +1 @@
Fixes the issue that caused emqx to fail to start when `api_key.bootstrap_file` was configured as a non-existent file.