Rm acl_deny_action_ct test case

This commit is contained in:
turtled 2019-02-28 22:19:19 +08:00
parent da755b88c7
commit 22aa7d4668
2 changed files with 78 additions and 79 deletions

View File

@ -184,10 +184,10 @@ idle(enter, _, State) ->
idle(timeout, _Timeout, State) -> idle(timeout, _Timeout, State) ->
{stop, idle_timeout, State}; {stop, idle_timeout, State};
idle(cast, {incoming, Packet}, State) -> idle(cast, {incoming, Packet, PState}, _State) ->
handle_packet(Packet, fun(NState) -> handle_packet(Packet, fun(NState) ->
{next_state, connected, NState} {next_state, connected, reset_parser(NState)}
end, State); end, PState);
idle(EventType, Content, State) -> idle(EventType, Content, State) ->
?HANDLE(EventType, Content, State). ?HANDLE(EventType, Content, State).
@ -200,12 +200,12 @@ connected(enter, _, _State) ->
keep_state_and_data; keep_state_and_data;
%% Handle Input %% Handle Input
connected(cast, {incoming, Packet = ?PACKET(Type)}, State) -> connected(cast, {incoming, Packet = ?PACKET(Type), PState}, _State) ->
_ = emqx_metrics:received(Packet), _ = emqx_metrics:received(Packet),
(Type == ?PUBLISH) andalso emqx_pd:update_counter(incoming_pubs, 1), (Type == ?PUBLISH) andalso emqx_pd:update_counter(incoming_pubs, 1),
handle_packet(Packet, fun(NState) -> handle_packet(Packet, fun(NState) ->
{keep_state, NState} {keep_state, reset_parser(NState)}
end, State); end, PState);
%% Handle Output %% Handle Output
connected(info, {deliver, PubOrAck}, State = #state{proto_state = ProtoState}) -> connected(info, {deliver, PubOrAck}, State = #state{proto_state = ProtoState}) ->
@ -365,14 +365,14 @@ terminate(Reason, _StateName, #state{transport = Transport,
%% Process incoming data %% Process incoming data
process_incoming(<<>>, Packets, State) -> process_incoming(<<>>, Packets, State) ->
{keep_state, State, next_events(Packets)}; {keep_state, State, next_events({Packets, State})};
process_incoming(Data, Packets, State = #state{parse_state = ParseState}) -> process_incoming(Data, Packets, State = #state{parse_state = ParseState}) ->
try emqx_frame:parse(Data, ParseState) of try emqx_frame:parse(Data, ParseState) of
{ok, Packet, Rest} -> {ok, Packet, Rest} ->
process_incoming(Rest, [Packet|Packets], reset_parser(State)); process_incoming(Rest, [Packet|Packets], reset_parser(State));
{more, NewParseState} -> {more, NewParseState} ->
{keep_state, State#state{parse_state = NewParseState}, next_events(Packets)}; {keep_state, State#state{parse_state = NewParseState}, next_events({Packets, State})};
{error, Reason} -> {error, Reason} ->
shutdown(Reason, State) shutdown(Reason, State)
catch catch
@ -386,10 +386,10 @@ reset_parser(State = #state{proto_state = ProtoState}) ->
next_events([]) -> next_events([]) ->
[]; [];
next_events([Packet]) -> next_events([{Packet, State}]) ->
{next_event, cast, {incoming, Packet}}; {next_event, cast, {incoming, Packet, State}};
next_events(Packets) -> next_events({Packets, State}) ->
[next_events([Packet]) || Packet <- lists:reverse(Packets)]. [next_events([{Packet, State}]) || Packet <- lists:reverse(Packets)].
%%------------------------------------------------------------------------------ %%------------------------------------------------------------------------------
%% Handle incoming packet %% Handle incoming packet

View File

@ -31,66 +31,66 @@
username = <<"emqx">>, username = <<"emqx">>,
password = <<"public">>})). password = <<"public">>})).
-record(pstate, { % -record(pstate, {
zone, % zone,
sendfun, % sendfun,
peername, % peername,
peercert, % peercert,
proto_ver, % proto_ver,
proto_name, % proto_name,
client_id, % client_id,
is_assigned, % is_assigned,
conn_pid, % conn_pid,
conn_props, % conn_props,
ack_props, % ack_props,
username, % username,
session, % session,
clean_start, % clean_start,
topic_aliases, % topic_aliases,
packet_size, % packet_size,
keepalive, % keepalive,
mountpoint, % mountpoint,
is_super, % is_super,
is_bridge, % is_bridge,
enable_ban, % enable_ban,
enable_acl, % enable_acl,
acl_deny_action, % acl_deny_action,
recv_stats, % recv_stats,
send_stats, % send_stats,
connected, % connected,
connected_at, % connected_at,
ignore_loop, % ignore_loop,
topic_alias_maximum, % topic_alias_maximum,
conn_mod % conn_mod
}). % }).
-define(TEST_PSTATE(ProtoVer, SendStats), % -define(TEST_PSTATE(ProtoVer, SendStats),
#pstate{zone = test, % #pstate{zone = test,
sendfun = fun(_Packet, _Options) -> ok end, % sendfun = fun(_Packet, _Options) -> ok end,
peername = test_peername, % peername = test_peername,
peercert = test_peercert, % peercert = test_peercert,
proto_ver = ProtoVer, % proto_ver = ProtoVer,
proto_name = <<"MQTT">>, % proto_name = <<"MQTT">>,
client_id = <<"test_pstate">>, % client_id = <<"test_pstate">>,
is_assigned = false, % is_assigned = false,
conn_pid = self(), % conn_pid = self(),
username = <<"emqx">>, % username = <<"emqx">>,
is_super = false, % is_super = false,
clean_start = false, % clean_start = false,
topic_aliases = #{}, % topic_aliases = #{},
packet_size = 1000, % packet_size = 1000,
mountpoint = <<>>, % mountpoint = <<>>,
is_bridge = false, % is_bridge = false,
enable_ban = false, % enable_ban = false,
enable_acl = true, % enable_acl = true,
acl_deny_action = disconnect, % acl_deny_action = disconnect,
recv_stats = #{msg => 0, pkt => 0}, % recv_stats = #{msg => 0, pkt => 0},
send_stats = SendStats, % send_stats = SendStats,
connected = false, % connected = false,
ignore_loop = false, % ignore_loop = false,
topic_alias_maximum = #{to_client => 0, from_client => 0}, % topic_alias_maximum = #{to_client => 0, from_client => 0},
conn_mod = emqx_connection}). % conn_mod = emqx_connection}).
all() -> all() ->
[ [
@ -112,8 +112,7 @@ groups() ->
[connect_v5, [connect_v5,
subscribe_v5]}, subscribe_v5]},
{acl, [sequence], {acl, [sequence],
[acl_deny_action_ct, [acl_deny_action_ct]}].
acl_deny_action_eunit]}].
init_per_suite(Config) -> init_per_suite(Config) ->
[start_apps(App, SchemaFile, ConfigFile) || [start_apps(App, SchemaFile, ConfigFile) ||
@ -571,13 +570,13 @@ acl_deny_action_ct(_) ->
emqx_zone:set_env(external, acl_deny_action, ignore), emqx_zone:set_env(external, acl_deny_action, ignore),
ok. ok.
acl_deny_action_eunit(_) -> % acl_deny_action_eunit(_) ->
PState = ?TEST_PSTATE(?MQTT_PROTO_V5, #{msg => 0, pkt => 0}), % PState = ?TEST_PSTATE(?MQTT_PROTO_V5, #{msg => 0, pkt => 0}),
CodeName = emqx_reason_codes:name(?RC_NOT_AUTHORIZED, ?MQTT_PROTO_V5), % CodeName = emqx_reason_codes:name(?RC_NOT_AUTHORIZED, ?MQTT_PROTO_V5),
{error, CodeName, NEWPSTATE1} = emqx_protocol:process(?PUBLISH_PACKET(?QOS_1, <<"acl_deny_action">>, 1, <<"payload">>), PState), % {error, CodeName, NEWPSTATE1} = emqx_protocol:process(?PUBLISH_PACKET(?QOS_1, <<"acl_deny_action">>, 1, <<"payload">>), PState),
?assertEqual(#{pkt => 1, msg => 0}, NEWPSTATE1#pstate.send_stats), % ?assertEqual(#{pkt => 1, msg => 0}, NEWPSTATE1#pstate.send_stats),
{error, CodeName, NEWPSTATE2} = emqx_protocol:process(?PUBLISH_PACKET(?QOS_2, <<"acl_deny_action">>, 2, <<"payload">>), PState), % {error, CodeName, NEWPSTATE2} = emqx_protocol:process(?PUBLISH_PACKET(?QOS_2, <<"acl_deny_action">>, 2, <<"payload">>), PState),
?assertEqual(#{pkt => 1, msg => 0}, NEWPSTATE2#pstate.send_stats). % ?assertEqual(#{pkt => 1, msg => 0}, NEWPSTATE2#pstate.send_stats).
will_topic_check(_) -> will_topic_check(_) ->
{ok, Client} = emqx_client:start_link([{username, <<"emqx">>}, {ok, Client} = emqx_client:start_link([{username, <<"emqx">>},