zhouzb 4 лет назад
Родитель
Сommit
b89973ce7c

+ 4 - 4
apps/emqx/src/emqx_authentication.erl

@@ -264,7 +264,7 @@ do_post_config_update({create_authenticator, ChainName, Config}, _NewConfig, _Ol
 do_post_config_update({delete_authenticator, ChainName, AuthenticatorID}, _NewConfig, OldConfig, _AppEnvs) ->
     case delete_authenticator(ChainName, AuthenticatorID) of
         ok ->
-            [Config] = [Config0 || Config0 <- OldConfig, AuthenticatorID == generate_id(Config0)],
+            [Config] = [Config0 || Config0 <- to_list(OldConfig), AuthenticatorID == generate_id(Config0)],
             CertsDir = certs_dir([to_bin(ChainName), AuthenticatorID]),
             clear_certs(CertsDir, Config),
             ok;
@@ -456,11 +456,11 @@ list_users(ChainName, AuthenticatorID) ->
 
 -spec generate_id(config()) -> authenticator_id().
 generate_id(#{mechanism := Mechanism0, backend := Backend0}) ->
-    Mechanism = atom_to_binary(Mechanism0),
-    Backend = atom_to_binary(Backend0),
+    Mechanism = to_bin(Mechanism0),
+    Backend = to_bin(Backend0),
     <<Mechanism/binary, ":", Backend/binary>>;
 generate_id(#{mechanism := Mechanism}) ->
-    atom_to_binary(Mechanism);
+    to_bin(Mechanism);
 generate_id(#{<<"mechanism">> := Mechanism, <<"backend">> := Backend}) ->
     <<Mechanism/binary, ":", Backend/binary>>;
 generate_id(#{<<"mechanism">> := Mechanism}) ->

+ 8 - 8
apps/emqx/test/emqx_authentication_SUITE.erl

@@ -211,12 +211,12 @@ t_update_config(Config) when is_list(Config) ->
     ok = register_provider(?config("auth1"), ?MODULE),
     ok = register_provider(?config("auth2"), ?MODULE),
     Global = ?config(global),
-    AuthenticatorConfig1 = #{mechanism => 'password-based',
-                             backend => 'built-in-database',
-                             enable => true},
-    AuthenticatorConfig2 = #{mechanism => 'password-based',
-                             backend => mysql,
-                             enable => true},
+    AuthenticatorConfig1 = #{<<"mechanism">> => <<"password-based">>,
+                             <<"backend">> => <<"built-in-database">>,
+                             <<"enable">> => true},
+    AuthenticatorConfig2 = #{<<"mechanism">> => <<"password-based">>,
+                             <<"backend">> => <<"mysql">>,
+                             <<"enable">> => true},
     ID1 = <<"password-based:built-in-database">>,
     ID2 = <<"password-based:mysql">>,
 
@@ -227,7 +227,7 @@ t_update_config(Config) when is_list(Config) ->
     ?assertMatch({ok, _}, update_config([authentication], {create_authenticator, Global, AuthenticatorConfig2})),
     ?assertMatch({ok, #{id := ID2, state := #{mark := 1}}}, ?AUTHN:lookup_authenticator(Global, ID2)),
 
-    ?assertMatch({ok, _}, update_config([authentication], {update_authenticator, Global, ID1, AuthenticatorConfig1#{enable => false}})),
+    ?assertMatch({ok, _}, update_config([authentication], {update_authenticator, Global, ID1, AuthenticatorConfig1#{<<"enable">> => false}})),
     ?assertMatch({ok, #{id := ID1, state := #{mark := 2}}}, ?AUTHN:lookup_authenticator(Global, ID1)),
 
     ?assertMatch({ok, _}, update_config([authentication], {move_authenticator, Global, ID2, top})),
@@ -244,7 +244,7 @@ t_update_config(Config) when is_list(Config) ->
     ?assertMatch({ok, _}, update_config(ConfKeyPath, {create_authenticator, ListenerID, AuthenticatorConfig2})),
     ?assertMatch({ok, #{id := ID2, state := #{mark := 1}}}, ?AUTHN:lookup_authenticator(ListenerID, ID2)),
 
-    ?assertMatch({ok, _}, update_config(ConfKeyPath, {update_authenticator, ListenerID, ID1, AuthenticatorConfig1#{enable => false}})),
+    ?assertMatch({ok, _}, update_config(ConfKeyPath, {update_authenticator, ListenerID, ID1, AuthenticatorConfig1#{<<"enable">> => false}})),
     ?assertMatch({ok, #{id := ID1, state := #{mark := 2}}}, ?AUTHN:lookup_authenticator(ListenerID, ID1)),
 
     ?assertMatch({ok, _}, update_config(ConfKeyPath, {move_authenticator, ListenerID, ID2, top})),