fix(admin): inconsistent return type on empty inputs
If an empty username or password are given during the initialization of `emqx_dashboard_admin`, it'll return just the atom `ok`, which breaks the expected `{ok, _}` in `emqx_dashboard_app:start/2`. ``` {'EXIT', {{failed_to_start_app,emqx_dashboard, {emqx_dashboard, {bad_return, {{emqx_dashboard_app,start,[normal,[]]}, {'EXIT', {{badmatch,ok}, [{emqx_dashboard_app,start,2, [{file, "/home/thales/dev/emqx/emqx/apps/emqx_dashboard/src/emqx_dashboard_app.erl"}, {line,32}]}, {application_master,start_it_old,4, [{file,"application_master.erl"},{line,293}]}]}}}}}}}} ```
This commit is contained in:
parent
b8a68d7a9f
commit
0300403fc0
|
@ -211,6 +211,7 @@ hash(Password) ->
|
||||||
sha256(SaltBin, Password) ->
|
sha256(SaltBin, Password) ->
|
||||||
crypto:hash('sha256', <<SaltBin/binary, Password/binary>>).
|
crypto:hash('sha256', <<SaltBin/binary, Password/binary>>).
|
||||||
|
|
||||||
|
-spec(add_default_user() -> {ok, map() | empty | default_user_exists } | {error, any()}).
|
||||||
add_default_user() ->
|
add_default_user() ->
|
||||||
add_default_user(binenv(default_username), binenv(default_password)).
|
add_default_user(binenv(default_username), binenv(default_password)).
|
||||||
|
|
||||||
|
@ -218,7 +219,7 @@ binenv(Key) ->
|
||||||
iolist_to_binary(emqx_conf:get([emqx_dashboard, Key], "")).
|
iolist_to_binary(emqx_conf:get([emqx_dashboard, Key], "")).
|
||||||
|
|
||||||
add_default_user(Username, Password) when ?EMPTY_KEY(Username) orelse ?EMPTY_KEY(Password) ->
|
add_default_user(Username, Password) when ?EMPTY_KEY(Username) orelse ?EMPTY_KEY(Password) ->
|
||||||
ok;
|
{ok, empty};
|
||||||
|
|
||||||
add_default_user(Username, Password) ->
|
add_default_user(Username, Password) ->
|
||||||
case lookup_user(Username) of
|
case lookup_user(Username) of
|
||||||
|
|
Loading…
Reference in New Issue