Explorar el Código

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

firest hace 2 años
padre
commit
9dee2dc31e

+ 12 - 3
apps/emqx_dashboard_sso/src/emqx_dashboard_sso_manager.erl

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

+ 2 - 2
apps/emqx_dashboard_sso/test/emqx_dashboard_sso_ldap_SUITE.erl

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