From 2d8231c6383089e74b7fb485a7c2faedb89b546f Mon Sep 17 00:00:00 2001 From: JianBo He Date: Fri, 1 Jul 2022 21:08:58 +0800 Subject: [PATCH] chore: fix gateway authz cases --- apps/emqx_gateway/test/emqx_gateway_auth_ct.erl | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/apps/emqx_gateway/test/emqx_gateway_auth_ct.erl b/apps/emqx_gateway/test/emqx_gateway_auth_ct.erl index 7fec71ae3..daf389945 100644 --- a/apps/emqx_gateway/test/emqx_gateway_auth_ct.erl +++ b/apps/emqx_gateway/test/emqx_gateway_auth_ct.erl @@ -65,6 +65,15 @@ -record(state, {}). +-define(AUTHZ_HTTP_RESP(Result, Req), + cowboy_req:reply( + 200, + #{<<"content-type">> => <<"application/json">>}, + "{\"result\": \"" ++ atom_to_list(Result) ++ "\"}", + Req + ) +). + %%------------------------------------------------------------------------------ %% API %%------------------------------------------------------------------------------ @@ -169,12 +178,12 @@ on_start_auth(authz_http) -> Handler = fun(Req0, State) -> case cowboy_req:match_qs([topic, action, username], Req0) of #{topic := <<"/publish">>, action := <<"publish">>} -> - Req = cowboy_req:reply(200, Req0); + Req = ?AUTHZ_HTTP_RESP(allow, Req0); #{topic := <<"/subscribe">>, action := <<"subscribe">>} -> - Req = cowboy_req:reply(200, Req0); + Req = ?AUTHZ_HTTP_RESP(allow, Req0); %% for lwm2m #{username := <<"lwm2m">>} -> - Req = cowboy_req:reply(200, Req0); + Req = ?AUTHZ_HTTP_RESP(allow, Req0); _ -> Req = cowboy_req:reply(400, Req0) end,