Преглед изворни кода

fix(gateway): Add support for query by is_superuser

firest пре 3 година
родитељ
комит
fd0f32418e

+ 8 - 0
apps/emqx_gateway/i18n/emqx_gateway_api_authn_i18n.conf

@@ -90,4 +90,12 @@ emqx_gateway_api_authn {
             zh: """Client ID 模糊搜索"""
         }
     }
+
+    is_superuser {
+        desc {
+            en: """Is superuser"""
+            zh: """是否是超级用户"""
+        }
+    }
+
 }

+ 11 - 1
apps/emqx_gateway/src/emqx_gateway_api_authn.erl

@@ -195,7 +195,8 @@ parse_qstring(Qs) ->
             <<"page">>,
             <<"limit">>,
             <<"like_username">>,
-            <<"like_clientid">>
+            <<"like_clientid">>,
+            <<"is_superuser">>
         ],
         Qs
     ).
@@ -397,6 +398,15 @@ params_fuzzy_in_qs() ->
                     desc => ?DESC(like_clientid),
                     example => <<"clientid">>
                 }
+            )},
+        {is_superuser,
+            mk(
+                boolean(),
+                #{
+                    in => query,
+                    required => false,
+                    desc => ?DESC(is_superuser)
+                }
             )}
     ].
 

+ 47 - 0
apps/emqx_gateway/test/emqx_gateway_api_SUITE.erl

@@ -415,6 +415,53 @@ t_listeners_authn_data_mgmt(_) ->
     ),
     {204, _} = request(delete, "/gateway/stomp").
 
+t_authn_fuzzy_search(_) ->
+    GwConf = #{name => <<"stomp">>},
+    {201, _} = request(post, "/gateway", GwConf),
+    {204, _} = request(get, "/gateway/stomp/authentication"),
+
+    AuthConf = #{
+        mechanism => <<"password_based">>,
+        backend => <<"built_in_database">>,
+        user_id_type => <<"clientid">>
+    },
+    {201, _} = request(post, "/gateway/stomp/authentication", AuthConf),
+    {200, ConfResp} = request(get, "/gateway/stomp/authentication"),
+    assert_confs(AuthConf, ConfResp),
+
+    Checker = fun({User, Fuzzy}) ->
+        {200, #{data := [UserRespd]}} = request(
+            get, "/gateway/stomp/authentication/users", Fuzzy
+        ),
+        assert_confs(UserRespd, User)
+    end,
+
+    Create = fun(User) ->
+        {201, _} = request(post, "/gateway/stomp/authentication/users", User)
+    end,
+
+    UserDatas = [
+        #{
+            user_id => <<"test">>,
+            password => <<"123456">>,
+            is_superuser => false
+        },
+        #{
+            user_id => <<"foo">>,
+            password => <<"123456">>,
+            is_superuser => true
+        }
+    ],
+
+    FuzzyDatas = [[{<<"like_username">>, <<"test">>}], [{<<"is_superuser">>, <<"true">>}]],
+
+    lists:foreach(Create, UserDatas),
+    lists:foreach(Checker, lists:zip(UserDatas, FuzzyDatas)),
+
+    {204, _} = request(delete, "/gateway/stomp/authentication"),
+    {204, _} = request(get, "/gateway/stomp/authentication"),
+    {204, _} = request(delete, "/gateway/stomp").
+
 %%--------------------------------------------------------------------
 %% Asserts