test(authz): fix test suite based on release-5.0-beta.3
This commit is contained in:
parent
9a115b99a4
commit
552165db26
|
@ -1,5 +1,5 @@
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Copyright (c) 2020-2021 EMQ Technologies Co., Ltd. All Rights Reserved.
|
%% Copyright (c) 2020-2022 EMQ Technologies Co., Ltd. All Rights Reserved.
|
||||||
%%
|
%%
|
||||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
%% you may not use this file except in compliance with the License.
|
%% you may not use this file except in compliance with the License.
|
||||||
|
@ -64,9 +64,7 @@ set_special_configs(_App) ->
|
||||||
|
|
||||||
-define(SOURCE1, #{<<"type">> => <<"http">>,
|
-define(SOURCE1, #{<<"type">> => <<"http">>,
|
||||||
<<"enable">> => true,
|
<<"enable">> => true,
|
||||||
<<"base_url">> => <<"https://example.com:443/">>,
|
<<"url">> => <<"https://example.com:443/a/b?c=d">>,
|
||||||
<<"path">> => <<"a/b">>,
|
|
||||||
<<"query">> => <<"c=d">>,
|
|
||||||
<<"headers">> => #{},
|
<<"headers">> => #{},
|
||||||
<<"method">> => <<"get">>,
|
<<"method">> => <<"get">>,
|
||||||
<<"request_timeout">> => 5000
|
<<"request_timeout">> => 5000
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Copyright (c) 2020-2021 EMQ Technologies Co., Ltd. All Rights Reserved.
|
%% Copyright (c) 2020-2022 EMQ Technologies Co., Ltd. All Rights Reserved.
|
||||||
%%
|
%%
|
||||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
%% you may not use this file except in compliance with the License.
|
%% you may not use this file except in compliance with the License.
|
||||||
|
@ -156,9 +156,10 @@ t_query_params(_Config) ->
|
||||||
Req = cowboy_req:reply(200, Req0),
|
Req = cowboy_req:reply(200, Req0),
|
||||||
{ok, Req, State}
|
{ok, Req, State}
|
||||||
end,
|
end,
|
||||||
#{<<"query">> => <<"username=${username}&"
|
#{<<"url">> => <<"http://127.0.0.1:33333/authz/users/?"
|
||||||
|
"username=${username}&"
|
||||||
"clientid=${clientid}&"
|
"clientid=${clientid}&"
|
||||||
"peerhost=${peerhost}&"
|
"peerhost=${host}&"
|
||||||
"proto_name=${proto_name}&"
|
"proto_name=${proto_name}&"
|
||||||
"mountpoint=${mountpoint}&"
|
"mountpoint=${mountpoint}&"
|
||||||
"topic=${topic}&"
|
"topic=${topic}&"
|
||||||
|
@ -178,63 +179,20 @@ t_query_params(_Config) ->
|
||||||
allow,
|
allow,
|
||||||
emqx_access_control:authorize(ClientInfo, publish, <<"t">>)).
|
emqx_access_control:authorize(ClientInfo, publish, <<"t">>)).
|
||||||
|
|
||||||
t_path_params(_Config) ->
|
|
||||||
ok = setup_handler_and_config(
|
|
||||||
fun(Req0, State) ->
|
|
||||||
<<"/authz/"
|
|
||||||
"username/user%20name/"
|
|
||||||
"clientid/client%20id/"
|
|
||||||
"peerhost/127.0.0.1/"
|
|
||||||
"proto_name/MQTT/"
|
|
||||||
"mountpoint/MOUNTPOINT/"
|
|
||||||
"topic/t/"
|
|
||||||
"action/publish">> = cowboy_req:path(Req0),
|
|
||||||
Req = cowboy_req:reply(200, Req0),
|
|
||||||
{ok, Req, State}
|
|
||||||
end,
|
|
||||||
#{<<"path">> => <<"username/${username}/"
|
|
||||||
"clientid/${clientid}/"
|
|
||||||
"peerhost/${peerhost}/"
|
|
||||||
"proto_name/${proto_name}/"
|
|
||||||
"mountpoint/${mountpoint}/"
|
|
||||||
"topic/${topic}/"
|
|
||||||
"action/${action}">>
|
|
||||||
}),
|
|
||||||
|
|
||||||
ClientInfo = #{clientid => <<"client id">>,
|
|
||||||
username => <<"user name">>,
|
|
||||||
peerhost => {127,0,0,1},
|
|
||||||
protocol => <<"MQTT">>,
|
|
||||||
mountpoint => <<"MOUNTPOINT">>,
|
|
||||||
zone => default,
|
|
||||||
listener => {tcp, default}
|
|
||||||
},
|
|
||||||
|
|
||||||
?assertEqual(
|
|
||||||
allow,
|
|
||||||
emqx_access_control:authorize(ClientInfo, publish, <<"t">>)).
|
|
||||||
|
|
||||||
t_json_body(_Config) ->
|
t_json_body(_Config) ->
|
||||||
ok = setup_handler_and_config(
|
ok = setup_handler_and_config(
|
||||||
fun(Req0, State) ->
|
fun(Req0, State) ->
|
||||||
?assertEqual(
|
?assertEqual(
|
||||||
<<"/authz/"
|
<<"/authz/users/">>,
|
||||||
"username/user%20name/"
|
|
||||||
"clientid/client%20id/"
|
|
||||||
"peerhost/127.0.0.1/"
|
|
||||||
"proto_name/MQTT/"
|
|
||||||
"mountpoint/MOUNTPOINT/"
|
|
||||||
"topic/t/"
|
|
||||||
"action/publish">>,
|
|
||||||
cowboy_req:path(Req0)),
|
cowboy_req:path(Req0)),
|
||||||
|
|
||||||
{ok, RawBody, Req1} = cowboy_req:read_body(Req0),
|
{ok, RawBody, Req1} = cowboy_req:read_body(Req0),
|
||||||
|
|
||||||
?assertMatch(
|
?assertMatch(
|
||||||
#{<<"username">> := <<"user name">>,
|
#{<<"username">> := <<"user name">>,
|
||||||
<<"CLIENT_client id">> := <<"client id">>,
|
<<"CLIENT">> := <<"client id">>,
|
||||||
<<"peerhost">> := [<<"127.0.0.1">>, 1],
|
<<"peerhost">> := <<"127.0.0.1">>,
|
||||||
<<"proto_name">> := #{<<"proto">> := <<"MQTT">>},
|
<<"proto_name">> := <<"MQTT">>,
|
||||||
<<"mountpoint">> := <<"MOUNTPOINT">>,
|
<<"mountpoint">> := <<"MOUNTPOINT">>,
|
||||||
<<"topic">> := <<"t">>,
|
<<"topic">> := <<"t">>,
|
||||||
<<"action">> := <<"publish">>},
|
<<"action">> := <<"publish">>},
|
||||||
|
@ -244,17 +202,10 @@ t_json_body(_Config) ->
|
||||||
{ok, Req, State}
|
{ok, Req, State}
|
||||||
end,
|
end,
|
||||||
#{<<"method">> => <<"post">>,
|
#{<<"method">> => <<"post">>,
|
||||||
<<"path">> => <<"username/${username}/"
|
|
||||||
"clientid/${clientid}/"
|
|
||||||
"peerhost/${peerhost}/"
|
|
||||||
"proto_name/${proto_name}/"
|
|
||||||
"mountpoint/${mountpoint}/"
|
|
||||||
"topic/${topic}/"
|
|
||||||
"action/${action}">>,
|
|
||||||
<<"body">> => #{<<"username">> => <<"${username}">>,
|
<<"body">> => #{<<"username">> => <<"${username}">>,
|
||||||
<<"CLIENT_${clientid}">> => <<"${clientid}">>,
|
<<"CLIENT">> => <<"${clientid}">>,
|
||||||
<<"peerhost">> => [<<"${peerhost}">>, 1],
|
<<"peerhost">> => <<"${host}">>,
|
||||||
<<"proto_name">> => #{<<"proto">> => <<"${proto_name}">>},
|
<<"proto_name">> => <<"${proto_name}">>,
|
||||||
<<"mountpoint">> => <<"${mountpoint}">>,
|
<<"mountpoint">> => <<"${mountpoint}">>,
|
||||||
<<"topic">> => <<"${topic}">>,
|
<<"topic">> => <<"${topic}">>,
|
||||||
<<"action">> => <<"${action}">>}
|
<<"action">> => <<"${action}">>}
|
||||||
|
@ -278,17 +229,10 @@ t_form_body(_Config) ->
|
||||||
ok = setup_handler_and_config(
|
ok = setup_handler_and_config(
|
||||||
fun(Req0, State) ->
|
fun(Req0, State) ->
|
||||||
?assertEqual(
|
?assertEqual(
|
||||||
<<"/authz/"
|
<<"/authz/users/">>,
|
||||||
"username/user%20name/"
|
|
||||||
"clientid/client%20id/"
|
|
||||||
"peerhost/127.0.0.1/"
|
|
||||||
"proto_name/MQTT/"
|
|
||||||
"mountpoint/MOUNTPOINT/"
|
|
||||||
"topic/t/"
|
|
||||||
"action/publish">>,
|
|
||||||
cowboy_req:path(Req0)),
|
cowboy_req:path(Req0)),
|
||||||
|
|
||||||
{ok, PostVars, Req1} = cowboy_req:read_urlencoded_body(Req0),
|
{ok, [{PostVars, true}], Req1} = cowboy_req:read_urlencoded_body(Req0),
|
||||||
|
|
||||||
?assertMatch(
|
?assertMatch(
|
||||||
#{<<"username">> := <<"user name">>,
|
#{<<"username">> := <<"user name">>,
|
||||||
|
@ -298,22 +242,15 @@ t_form_body(_Config) ->
|
||||||
<<"mountpoint">> := <<"MOUNTPOINT">>,
|
<<"mountpoint">> := <<"MOUNTPOINT">>,
|
||||||
<<"topic">> := <<"t">>,
|
<<"topic">> := <<"t">>,
|
||||||
<<"action">> := <<"publish">>},
|
<<"action">> := <<"publish">>},
|
||||||
maps:from_list(PostVars)),
|
jiffy:decode(PostVars, [return_maps])),
|
||||||
|
|
||||||
Req = cowboy_req:reply(200, Req1),
|
Req = cowboy_req:reply(200, Req1),
|
||||||
{ok, Req, State}
|
{ok, Req, State}
|
||||||
end,
|
end,
|
||||||
#{<<"method">> => <<"post">>,
|
#{<<"method">> => <<"post">>,
|
||||||
<<"path">> => <<"username/${username}/"
|
|
||||||
"clientid/${clientid}/"
|
|
||||||
"peerhost/${peerhost}/"
|
|
||||||
"proto_name/${proto_name}/"
|
|
||||||
"mountpoint/${mountpoint}/"
|
|
||||||
"topic/${topic}/"
|
|
||||||
"action/${action}">>,
|
|
||||||
<<"body">> => #{<<"username">> => <<"${username}">>,
|
<<"body">> => #{<<"username">> => <<"${username}">>,
|
||||||
<<"clientid">> => <<"${clientid}">>,
|
<<"clientid">> => <<"${clientid}">>,
|
||||||
<<"peerhost">> => <<"${peerhost}">>,
|
<<"peerhost">> => <<"${host}">>,
|
||||||
<<"proto_name">> => <<"${proto_name}">>,
|
<<"proto_name">> => <<"${proto_name}">>,
|
||||||
<<"mountpoint">> => <<"${mountpoint}">>,
|
<<"mountpoint">> => <<"${mountpoint}">>,
|
||||||
<<"topic">> => <<"${topic}">>,
|
<<"topic">> => <<"${topic}">>,
|
||||||
|
@ -349,7 +286,8 @@ t_create_replace(_Config) ->
|
||||||
Req = cowboy_req:reply(200, Req0),
|
Req = cowboy_req:reply(200, Req0),
|
||||||
{ok, Req, State}
|
{ok, Req, State}
|
||||||
end,
|
end,
|
||||||
#{<<"base_url">> => <<"http://127.0.0.1:33333/authz">>}),
|
#{<<"url">> =>
|
||||||
|
<<"http://127.0.0.1:33333/authz/users/?topic=${topic}&action=${action}">>}),
|
||||||
|
|
||||||
?assertEqual(
|
?assertEqual(
|
||||||
allow,
|
allow,
|
||||||
|
@ -358,7 +296,8 @@ t_create_replace(_Config) ->
|
||||||
%% Changing to other bad config does not work
|
%% Changing to other bad config does not work
|
||||||
BadConfig = maps:merge(
|
BadConfig = maps:merge(
|
||||||
raw_http_authz_config(),
|
raw_http_authz_config(),
|
||||||
#{<<"base_url">> => <<"http://127.0.0.1:33332/authz">>}),
|
#{<<"url">> =>
|
||||||
|
<<"http://127.0.0.1:33332/authz/users/?topic=${topic}&action=${action}">>}),
|
||||||
|
|
||||||
?assertMatch(
|
?assertMatch(
|
||||||
{error, _},
|
{error, _},
|
||||||
|
@ -371,7 +310,8 @@ t_create_replace(_Config) ->
|
||||||
%% Changing to valid config
|
%% Changing to valid config
|
||||||
OkConfig = maps:merge(
|
OkConfig = maps:merge(
|
||||||
raw_http_authz_config(),
|
raw_http_authz_config(),
|
||||||
#{<<"base_url">> => <<"http://127.0.0.1:33333/authz">>}),
|
#{<<"url">> =>
|
||||||
|
<<"http://127.0.0.1:33333/authz/users/?topic=${topic}&action=${action}">>}),
|
||||||
|
|
||||||
?assertMatch(
|
?assertMatch(
|
||||||
{ok, _},
|
{ok, _},
|
||||||
|
@ -388,12 +328,9 @@ t_create_replace(_Config) ->
|
||||||
raw_http_authz_config() ->
|
raw_http_authz_config() ->
|
||||||
#{
|
#{
|
||||||
<<"enable">> => <<"true">>,
|
<<"enable">> => <<"true">>,
|
||||||
|
|
||||||
<<"type">> => <<"http">>,
|
<<"type">> => <<"http">>,
|
||||||
<<"method">> => <<"get">>,
|
<<"method">> => <<"get">>,
|
||||||
<<"base_url">> => <<"http://127.0.0.1:33333/authz">>,
|
<<"url">> => <<"http://127.0.0.1:33333/authz/users/?topic=${topic}&action=${action}">>,
|
||||||
<<"path">> => <<"users/${username}/">>,
|
|
||||||
<<"query">> => <<"topic=${topic}&action=${action}">>,
|
|
||||||
<<"headers">> => #{<<"X-Test-Header">> => <<"Test Value">>}
|
<<"headers">> => #{<<"X-Test-Header">> => <<"Test Value">>}
|
||||||
}.
|
}.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue