test: dashboard default password

This commit is contained in:
Zhongwen Deng 2023-01-17 11:30:25 +08:00
parent 2bfb37f7f0
commit 3dfdad9cc9
3 changed files with 10 additions and 6 deletions

View File

@ -175,6 +175,7 @@ start_apps(Apps, SpecAppConfig) when is_function(SpecAppConfig) ->
%% Because, minirest, ekka etc.. application will scan these modules %% Because, minirest, ekka etc.. application will scan these modules
lists:foreach(fun load/1, [emqx | Apps]), lists:foreach(fun load/1, [emqx | Apps]),
ok = start_ekka(), ok = start_ekka(),
mnesia:clear_table(emqx_admin),
ok = emqx_ratelimiter_SUITE:load_conf(), ok = emqx_ratelimiter_SUITE:load_conf(),
lists:foreach(fun(App) -> start_app(App, SpecAppConfig) end, [emqx | Apps]). lists:foreach(fun(App) -> start_app(App, SpecAppConfig) end, [emqx | Apps]).

View File

@ -61,6 +61,7 @@ end_suite() ->
end_suite(Apps) -> end_suite(Apps) ->
application:unload(emqx_management), application:unload(emqx_management),
mnesia:clear_table(?ADMIN),
emqx_common_test_helpers:stop_apps(Apps ++ [emqx_dashboard]). emqx_common_test_helpers:stop_apps(Apps ++ [emqx_dashboard]).
init_per_suite(Config) -> init_per_suite(Config) ->
@ -83,8 +84,9 @@ set_special_configs(_) ->
t_overview(_) -> t_overview(_) ->
mnesia:clear_table(?ADMIN), mnesia:clear_table(?ADMIN),
emqx_dashboard_admin:add_user(<<"admin">>, <<"public_www1">>, <<"simple_description">>), emqx_dashboard_admin:add_user(<<"admin">>, <<"public_www1">>, <<"simple_description">>),
Headers = auth_header_(<<"admin">>, <<"public_www1">>),
[ [
{ok, _} = request_dashboard(get, api_path([Overview]), auth_header_()) {ok, _} = request_dashboard(get, api_path([Overview]), Headers)
|| Overview <- ?OVERVIEWS || Overview <- ?OVERVIEWS
]. ].
@ -209,16 +211,16 @@ random_num() ->
erlang:system_time(nanosecond). erlang:system_time(nanosecond).
http_get(Parts) -> http_get(Parts) ->
request_api(get, api_path(Parts), auth_header_()). request_api(get, api_path(Parts), auth_header_(<<"admin">>, <<"public_www1">>)).
http_delete(Parts) -> http_delete(Parts) ->
request_api(delete, api_path(Parts), auth_header_()). request_api(delete, api_path(Parts), auth_header_(<<"admin">>, <<"public_www1">>)).
http_post(Parts, Body) -> http_post(Parts, Body) ->
request_api(post, api_path(Parts), [], auth_header_(), Body). request_api(post, api_path(Parts), [], auth_header_(<<"admin">>, <<"public_www1">>), Body).
http_put(Parts, Body) -> http_put(Parts, Body) ->
request_api(put, api_path(Parts), [], auth_header_(), Body). request_api(put, api_path(Parts), [], auth_header_(<<"admin">>, <<"public_www1">>), Body).
request_dashboard(Method, Url, Auth) -> request_dashboard(Method, Url, Auth) ->
Request = {Url, [Auth]}, Request = {Url, [Auth]},
@ -240,7 +242,7 @@ do_request_dashboard(Method, Request) ->
end. end.
auth_header_() -> auth_header_() ->
auth_header_(<<"admin">>, <<"public_www1">>). auth_header_(<<"admin">>, <<"public">>).
auth_header_(Username, Password) -> auth_header_(Username, Password) ->
{ok, Token} = emqx_dashboard_admin:sign_token(Username, Password), {ok, Token} = emqx_dashboard_admin:sign_token(Username, Password),

View File

@ -33,6 +33,7 @@ all() ->
emqx_common_test_helpers:all(?MODULE). emqx_common_test_helpers:all(?MODULE).
init_per_suite(Config) -> init_per_suite(Config) ->
application:load(emqx_dashboard),
mria:start(), mria:start(),
emqx_common_test_helpers:start_apps([emqx_dashboard], fun set_special_configs/1), emqx_common_test_helpers:start_apps([emqx_dashboard], fun set_special_configs/1),
Config. Config.