test(coap): fix ci errors
This commit is contained in:
parent
854754eb60
commit
ec183f1d4c
|
@ -97,7 +97,8 @@ t_case_coap_publish(_) ->
|
||||||
end,
|
end,
|
||||||
Case = fun(Channel, Token) ->
|
Case = fun(Channel, Token) ->
|
||||||
Fun(Channel, Token, <<"/publish">>, ?checkMatch({ok, changed, _})),
|
Fun(Channel, Token, <<"/publish">>, ?checkMatch({ok, changed, _})),
|
||||||
Fun(Channel, Token, <<"/badpublish">>, ?checkMatch({error, uauthorized}))
|
Fun(Channel, Token, <<"/badpublish">>, ?checkMatch({error, uauthorized})),
|
||||||
|
true
|
||||||
end,
|
end,
|
||||||
Mod:with_connection(Case).
|
Mod:with_connection(Case).
|
||||||
|
|
||||||
|
@ -113,7 +114,8 @@ t_case_coap_subscribe(_) ->
|
||||||
end,
|
end,
|
||||||
Case = fun(Channel, Token) ->
|
Case = fun(Channel, Token) ->
|
||||||
Fun(Channel, Token, <<"/subscribe">>, ?checkMatch({ok, content, _})),
|
Fun(Channel, Token, <<"/subscribe">>, ?checkMatch({ok, content, _})),
|
||||||
Fun(Channel, Token, <<"/badsubscribe">>, ?checkMatch({error, uauthorized}))
|
Fun(Channel, Token, <<"/badsubscribe">>, ?checkMatch({error, uauthorized})),
|
||||||
|
true
|
||||||
end,
|
end,
|
||||||
Mod:with_connection(Case).
|
Mod:with_connection(Case).
|
||||||
|
|
||||||
|
|
|
@ -410,6 +410,19 @@ is_create_connection_request(Msg = #coap_message{method = Method}) when
|
||||||
is_create_connection_request(_Msg) ->
|
is_create_connection_request(_Msg) ->
|
||||||
false.
|
false.
|
||||||
|
|
||||||
|
is_delete_connection_request(Msg = #coap_message{method = Method}) when
|
||||||
|
is_atom(Method) andalso Method =/= undefined
|
||||||
|
->
|
||||||
|
URIPath = emqx_coap_message:get_option(uri_path, Msg, []),
|
||||||
|
case URIPath of
|
||||||
|
[<<"mqtt">>, <<"connection">>] when Method == delete ->
|
||||||
|
true;
|
||||||
|
_ ->
|
||||||
|
false
|
||||||
|
end;
|
||||||
|
is_delete_connection_request(_Msg) ->
|
||||||
|
false.
|
||||||
|
|
||||||
check_token(
|
check_token(
|
||||||
Msg,
|
Msg,
|
||||||
#channel{
|
#channel{
|
||||||
|
@ -424,10 +437,18 @@ check_token(
|
||||||
<<"token">> := Token
|
<<"token">> := Token
|
||||||
} ->
|
} ->
|
||||||
call_session(handle_request, Msg, Channel);
|
call_session(handle_request, Msg, Channel);
|
||||||
_ ->
|
Any ->
|
||||||
|
%% This channel is create by this DELETE command, so here can safely close this channel
|
||||||
|
case Token =:= undefined andalso is_delete_connection_request(Msg) of
|
||||||
|
true ->
|
||||||
|
Reply = emqx_coap_message:piggyback({ok, deleted}, Msg),
|
||||||
|
{shutdown, normal, Reply, Channel};
|
||||||
|
false ->
|
||||||
|
io:format(">>> C1:~p, T1:~p~nC2:~p~n", [ClientId, Token, Any]),
|
||||||
ErrMsg = <<"Missing token or clientid in connection mode">>,
|
ErrMsg = <<"Missing token or clientid in connection mode">>,
|
||||||
Reply = emqx_coap_message:piggyback({error, bad_request}, ErrMsg, Msg),
|
Reply = emqx_coap_message:piggyback({error, bad_request}, ErrMsg, Msg),
|
||||||
{ok, {outgoing, Reply}, Channel}
|
{ok, {outgoing, Reply}, Channel}
|
||||||
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
run_conn_hooks(
|
run_conn_hooks(
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
-include("emqx_coap.hrl").
|
-include("emqx_coap.hrl").
|
||||||
|
|
||||||
-export([initialize/1, create/3, get_connection_id/4, dispatch/3, close/2]).
|
-export([initialize/1, find_or_create/4, get_connection_id/4, dispatch/3, close/2]).
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Callbacks
|
%% Callbacks
|
||||||
|
@ -28,8 +28,13 @@
|
||||||
initialize(_Opts) ->
|
initialize(_Opts) ->
|
||||||
emqx_coap_frame:initial_parse_state(#{}).
|
emqx_coap_frame:initial_parse_state(#{}).
|
||||||
|
|
||||||
create(Transport, Peer, Opts) ->
|
find_or_create(CId, Transport, Peer, Opts) ->
|
||||||
emqx_gateway_conn:start_link(Transport, Peer, Opts).
|
case emqx_gateway_cm_registry:lookup_channels(coap, CId) of
|
||||||
|
[Pid] ->
|
||||||
|
{ok, Pid};
|
||||||
|
[] ->
|
||||||
|
emqx_gateway_conn:start_link(Transport, Peer, Opts)
|
||||||
|
end.
|
||||||
|
|
||||||
get_connection_id(_Transport, _Peer, State, Data) ->
|
get_connection_id(_Transport, _Peer, State, Data) ->
|
||||||
case parse_incoming(Data, [], State) of
|
case parse_incoming(Data, [], State) of
|
||||||
|
@ -40,7 +45,10 @@ get_connection_id(_Transport, _Peer, State, Data) ->
|
||||||
} ->
|
} ->
|
||||||
{ok, ClientId, Packets, NState};
|
{ok, ClientId, Packets, NState};
|
||||||
_ ->
|
_ ->
|
||||||
invalid
|
ErrMsg = <<"Missing token or clientid in connection mode">>,
|
||||||
|
Reply = emqx_coap_message:piggyback({error, bad_request}, ErrMsg, Msg),
|
||||||
|
Bin = emqx_coap_frame:serialize_pkt(Reply, emqx_coap_frame:serialize_opts()),
|
||||||
|
{error, Bin}
|
||||||
end;
|
end;
|
||||||
_Error ->
|
_Error ->
|
||||||
invalid
|
invalid
|
||||||
|
|
|
@ -165,7 +165,8 @@ t_connection(_) ->
|
||||||
emqx_gateway_cm_registry:lookup_channels(coap, <<"client1">>)
|
emqx_gateway_cm_registry:lookup_channels(coap, <<"client1">>)
|
||||||
)
|
)
|
||||||
end,
|
end,
|
||||||
do(Action).
|
do(Action),
|
||||||
|
ok.
|
||||||
|
|
||||||
t_connection_with_short_param_name(_) ->
|
t_connection_with_short_param_name(_) ->
|
||||||
Action = fun(Channel) ->
|
Action = fun(Channel) ->
|
||||||
|
|
|
@ -207,7 +207,8 @@ test_recv_coap_request(UdpSock) ->
|
||||||
test_send_coap_response(UdpSock, Host, Port, Code, Content, Request) ->
|
test_send_coap_response(UdpSock, Host, Port, Code, Content, Request) ->
|
||||||
is_list(Host) orelse error("Host is not a string"),
|
is_list(Host) orelse error("Host is not a string"),
|
||||||
{ok, IpAddr} = inet:getaddr(Host, inet),
|
{ok, IpAddr} = inet:getaddr(Host, inet),
|
||||||
Response = emqx_coap_message:piggyback(Code, Content, Request),
|
Response0 = emqx_coap_message:piggyback(Code, Content, Request),
|
||||||
|
Response = Response0#coap_message{options = #{uri_query => [<<"clientid=client1">>]}},
|
||||||
?LOGT("test_send_coap_response Response=~p", [Response]),
|
?LOGT("test_send_coap_response Response=~p", [Response]),
|
||||||
Binary = emqx_coap_frame:serialize_pkt(Response, undefined),
|
Binary = emqx_coap_frame:serialize_pkt(Response, undefined),
|
||||||
ok = gen_udp:send(UdpSock, IpAddr, Port, Binary).
|
ok = gen_udp:send(UdpSock, IpAddr, Port, Binary).
|
||||||
|
|
Loading…
Reference in New Issue