fix(sso): clear last error first before update && fix the `running`

This commit is contained in:
firest 2023-09-28 08:56:16 +08:00
parent afdda107af
commit 9dee2dc31e
2 changed files with 14 additions and 5 deletions

View File

@ -63,14 +63,22 @@ start_link() ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []). gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
running() -> running() ->
SSO = emqx:get_config(?MOD_KEY_PATH, #{}),
lists:filtermap( lists:filtermap(
fun fun
(#?MOD_TAB{backend = Backend, last_error = ?NO_ERROR}) -> (#{backend := Backend, enable := true}) ->
{true, Backend}; case lookup(Backend) of
undefined ->
false;
#?MOD_TAB{last_error = ?NO_ERROR} ->
{true, Backend};
_ ->
false
end;
(_) -> (_) ->
false false
end, end,
ets:tab2list(?MOD_TAB) maps:values(SSO)
). ).
get_backend_status(Backend, false) -> get_backend_status(Backend, false) ->
@ -258,6 +266,7 @@ on_config_update({update, Backend, _RawConfig}, Config) ->
end end
); );
Data -> Data ->
update_last_error(Backend, ?NO_ERROR),
on_backend_updated( on_backend_updated(
Backend, Backend,
emqx_dashboard_sso:update(Provider, Config, Data#?MOD_TAB.state), emqx_dashboard_sso:update(Provider, Config, Data#?MOD_TAB.state),

View File

@ -64,7 +64,7 @@ end_per_testcase(Case, _) ->
t_bad_create(_) -> t_bad_create(_) ->
Path = uri(["sso", "ldap"]), Path = uri(["sso", "ldap"]),
?assertMatch( ?assertMatch(
{ok, 200, _}, {ok, 400, _},
request( request(
put, put,
Path, Path,
@ -168,7 +168,7 @@ t_next_login(_) ->
t_bad_update(_) -> t_bad_update(_) ->
Path = uri(["sso", "ldap"]), Path = uri(["sso", "ldap"]),
?assertMatch( ?assertMatch(
{ok, 200, _}, {ok, 400, _},
request( request(
put, put,
Path, Path,