fix(gateway): Add support for query by is_superuser

This commit is contained in:
firest 2022-04-27 15:41:14 +08:00
parent 09b6648567
commit fd0f32418e
3 changed files with 66 additions and 1 deletions

View File

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

View File

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

View File

@ -415,6 +415,53 @@ t_listeners_authn_data_mgmt(_) ->
), ),
{204, _} = request(delete, "/gateway/stomp"). {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 %% Asserts