fix(dashboard): add test case & update change
This commit is contained in:
parent
c37097a150
commit
13df7fa46e
|
@ -149,12 +149,13 @@ remove_sensitive_data(Conf0) ->
|
||||||
post_config_update(_, {change_i18n_lang, _}, _NewConf, _OldConf, _AppEnvs) ->
|
post_config_update(_, {change_i18n_lang, _}, _NewConf, _OldConf, _AppEnvs) ->
|
||||||
delay_job(regenerate);
|
delay_job(regenerate);
|
||||||
post_config_update(_, _Req, NewConf, OldConf, _AppEnvs) ->
|
post_config_update(_, _Req, NewConf, OldConf, _AppEnvs) ->
|
||||||
|
SwaggerSupport = diff_swagger_support(NewConf, OldConf),
|
||||||
OldHttp = get_listener(http, OldConf),
|
OldHttp = get_listener(http, OldConf),
|
||||||
OldHttps = get_listener(https, OldConf),
|
OldHttps = get_listener(https, OldConf),
|
||||||
NewHttp = get_listener(http, NewConf),
|
NewHttp = get_listener(http, NewConf),
|
||||||
NewHttps = get_listener(https, NewConf),
|
NewHttps = get_listener(https, NewConf),
|
||||||
{StopHttp, StartHttp} = diff_listeners(http, OldHttp, NewHttp),
|
{StopHttp, StartHttp} = diff_listeners(http, OldHttp, NewHttp, SwaggerSupport),
|
||||||
{StopHttps, StartHttps} = diff_listeners(https, OldHttps, NewHttps),
|
{StopHttps, StartHttps} = diff_listeners(https, OldHttps, NewHttps, SwaggerSupport),
|
||||||
Stop = maps:merge(StopHttp, StopHttps),
|
Stop = maps:merge(StopHttp, StopHttps),
|
||||||
Start = maps:merge(StartHttp, StartHttps),
|
Start = maps:merge(StartHttp, StartHttps),
|
||||||
delay_job({update_listeners, Stop, Start}).
|
delay_job({update_listeners, Stop, Start}).
|
||||||
|
@ -168,10 +169,16 @@ delay_job(Msg) ->
|
||||||
get_listener(Type, Conf) ->
|
get_listener(Type, Conf) ->
|
||||||
emqx_utils_maps:deep_get([listeners, Type], Conf, undefined).
|
emqx_utils_maps:deep_get([listeners, Type], Conf, undefined).
|
||||||
|
|
||||||
diff_listeners(_, Listener, Listener) -> {#{}, #{}};
|
diff_swagger_support(NewConf, OldConf) ->
|
||||||
diff_listeners(Type, undefined, Start) -> {#{}, #{Type => Start}};
|
maps:get(swagger_support, NewConf, true) =:=
|
||||||
diff_listeners(Type, Stop, undefined) -> {#{Type => Stop}, #{}};
|
maps:get(swagger_support, OldConf, true).
|
||||||
diff_listeners(Type, Stop, Start) -> {#{Type => Stop}, #{Type => Start}}.
|
|
||||||
|
diff_listeners(_, undefined, undefined, _) -> {#{}, #{}};
|
||||||
|
diff_listeners(_, Listener, Listener, true) -> {#{}, #{}};
|
||||||
|
diff_listeners(Type, undefined, Start, _) -> {#{}, #{Type => Start}};
|
||||||
|
diff_listeners(Type, Stop, undefined, _) -> {#{Type => Stop}, #{}};
|
||||||
|
diff_listeners(Type, Listener, Listener, false) -> {#{Type => Listener}, #{Type => Listener}};
|
||||||
|
diff_listeners(Type, Stop, Start, _) -> {#{Type => Stop}, #{Type => Start}}.
|
||||||
|
|
||||||
-define(DIR, <<"dashboard">>).
|
-define(DIR, <<"dashboard">>).
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
-include_lib("common_test/include/ct.hrl").
|
-include_lib("common_test/include/ct.hrl").
|
||||||
-include_lib("emqx/include/emqx.hrl").
|
-include_lib("emqx/include/emqx.hrl").
|
||||||
|
-include_lib("snabbkaffe/include/snabbkaffe.hrl").
|
||||||
-include("emqx_dashboard.hrl").
|
-include("emqx_dashboard.hrl").
|
||||||
|
|
||||||
-define(CONTENT_TYPE, "application/x-www-form-urlencoded").
|
-define(CONTENT_TYPE, "application/x-www-form-urlencoded").
|
||||||
|
@ -188,6 +189,38 @@ t_swagger_json(_Config) ->
|
||||||
),
|
),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
t_disable_swagger_json(_Config) ->
|
||||||
|
Url = ?HOST ++ "/api-docs/index.html",
|
||||||
|
|
||||||
|
?assertMatch(
|
||||||
|
{ok, {{"HTTP/1.1", 200, "OK"}, __, _}},
|
||||||
|
httpc:request(get, {Url, []}, [], [{body_format, binary}])
|
||||||
|
),
|
||||||
|
|
||||||
|
DashboardCfg = emqx:get_raw_config([dashboard]),
|
||||||
|
DashboardCfg2 = DashboardCfg#{<<"swagger_support">> => false},
|
||||||
|
emqx:update_config([dashboard], DashboardCfg2),
|
||||||
|
?retry(
|
||||||
|
_Sleep = 1000,
|
||||||
|
_Attempts = 5,
|
||||||
|
?assertMatch(
|
||||||
|
{ok, {{"HTTP/1.1", 404, "Not Found"}, _, _}},
|
||||||
|
httpc:request(get, {Url, []}, [], [{body_format, binary}])
|
||||||
|
)
|
||||||
|
),
|
||||||
|
|
||||||
|
DashboardCfg3 = DashboardCfg#{<<"swagger_support">> => true},
|
||||||
|
emqx:update_config([dashboard], DashboardCfg3),
|
||||||
|
?retry(
|
||||||
|
_Sleep0 = 1000,
|
||||||
|
_Attempts0 = 5,
|
||||||
|
?assertMatch(
|
||||||
|
{ok, {{"HTTP/1.1", 200, "OK"}, __, _}},
|
||||||
|
httpc:request(get, {Url, []}, [], [{body_format, binary}])
|
||||||
|
)
|
||||||
|
),
|
||||||
|
ok.
|
||||||
|
|
||||||
t_cli(_Config) ->
|
t_cli(_Config) ->
|
||||||
[mria:dirty_delete(?ADMIN, Admin) || Admin <- mnesia:dirty_all_keys(?ADMIN)],
|
[mria:dirty_delete(?ADMIN, Admin) || Admin <- mnesia:dirty_all_keys(?ADMIN)],
|
||||||
emqx_dashboard_cli:admins(["add", "username", "password_ww2"]),
|
emqx_dashboard_cli:admins(["add", "username", "password_ww2"]),
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Exposed the `swagger_support` option in configuration for Dashboard to disable the swagger API document.
|
Loading…
Reference in New Issue