Merge pull request #9599 from lafirest/fix/blacklist_default_exp
fix(banned): ensure the default expiration time of `banned` is large enough
This commit is contained in:
commit
2ff6ef01f1
|
@ -59,6 +59,10 @@
|
||||||
|
|
||||||
-define(BANNED_TAB, ?MODULE).
|
-define(BANNED_TAB, ?MODULE).
|
||||||
|
|
||||||
|
%% The default expiration time should be infinite
|
||||||
|
%% but for compatibility, a large number (1 years) is used here to represent the 'infinite'
|
||||||
|
-define(EXPIRATION_TIME, 31536000).
|
||||||
|
|
||||||
-ifdef(TEST).
|
-ifdef(TEST).
|
||||||
-compile(export_all).
|
-compile(export_all).
|
||||||
-compile(nowarn_export_all).
|
-compile(nowarn_export_all).
|
||||||
|
@ -126,7 +130,7 @@ parse(Params) ->
|
||||||
By = maps:get(<<"by">>, Params, <<"mgmt_api">>),
|
By = maps:get(<<"by">>, Params, <<"mgmt_api">>),
|
||||||
Reason = maps:get(<<"reason">>, Params, <<"">>),
|
Reason = maps:get(<<"reason">>, Params, <<"">>),
|
||||||
At = maps:get(<<"at">>, Params, erlang:system_time(second)),
|
At = maps:get(<<"at">>, Params, erlang:system_time(second)),
|
||||||
Until = maps:get(<<"until">>, Params, At + 5 * 60),
|
Until = maps:get(<<"until">>, Params, At + ?EXPIRATION_TIME),
|
||||||
case Until > erlang:system_time(second) of
|
case Until > erlang:system_time(second) of
|
||||||
true ->
|
true ->
|
||||||
#banned{
|
#banned{
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
|
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
|
|
||||||
|
-define(EXPIRATION_TIME, 31536000).
|
||||||
|
|
||||||
all() ->
|
all() ->
|
||||||
emqx_common_test_helpers:all(?MODULE).
|
emqx_common_test_helpers:all(?MODULE).
|
||||||
|
|
||||||
|
@ -82,6 +84,28 @@ t_create(_Config) ->
|
||||||
{ok, #{<<"data">> := List}} = list_banned(),
|
{ok, #{<<"data">> := List}} = list_banned(),
|
||||||
Bans = lists:sort(lists:map(fun(#{<<"who">> := W, <<"as">> := A}) -> {A, W} end, List)),
|
Bans = lists:sort(lists:map(fun(#{<<"who">> := W, <<"as">> := A}) -> {A, W} end, List)),
|
||||||
?assertEqual([{<<"clientid">>, ClientId}, {<<"peerhost">>, PeerHost}], Bans),
|
?assertEqual([{<<"clientid">>, ClientId}, {<<"peerhost">>, PeerHost}], Bans),
|
||||||
|
|
||||||
|
ClientId2 = <<"TestClient2"/utf8>>,
|
||||||
|
ClientIdBanned2 = #{
|
||||||
|
as => As,
|
||||||
|
who => ClientId2,
|
||||||
|
by => By,
|
||||||
|
reason => Reason,
|
||||||
|
at => At
|
||||||
|
},
|
||||||
|
{ok, ClientIdBannedRes2} = create_banned(ClientIdBanned2),
|
||||||
|
Until2 = emqx_banned:to_rfc3339(Now + ?EXPIRATION_TIME),
|
||||||
|
?assertEqual(
|
||||||
|
#{
|
||||||
|
<<"as">> => As,
|
||||||
|
<<"at">> => At,
|
||||||
|
<<"by">> => By,
|
||||||
|
<<"reason">> => Reason,
|
||||||
|
<<"until">> => Until2,
|
||||||
|
<<"who">> => ClientId2
|
||||||
|
},
|
||||||
|
ClientIdBannedRes2
|
||||||
|
),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
t_create_failed(_Config) ->
|
t_create_failed(_Config) ->
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
|
|
||||||
- Added the option to customize the clientid prefix of egress MQTT bridges. [#9609](https://github.com/emqx/emqx/pull/9609)
|
- Added the option to customize the clientid prefix of egress MQTT bridges. [#9609](https://github.com/emqx/emqx/pull/9609)
|
||||||
|
|
||||||
|
- Ensure the default expiration time of `banned` is large enough [#9599](https://github.com/emqx/emqx/pull/9599/).
|
||||||
|
|
||||||
## Bug fixes
|
## Bug fixes
|
||||||
|
|
||||||
- Trigger `message.dropped` hook when QoS2 message is resend by client with a same packet id, or 'awaiting_rel' queue is full [#9487](https://github.com/emqx/emqx/pull/9487).
|
- Trigger `message.dropped` hook when QoS2 message is resend by client with a same packet id, or 'awaiting_rel' queue is full [#9487](https://github.com/emqx/emqx/pull/9487).
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
|
|
||||||
- 增加了自定义出口MQTT桥的clientid前缀的选项。[#9609](https://github.com/emqx/emqx/pull/9609)
|
- 增加了自定义出口MQTT桥的clientid前缀的选项。[#9609](https://github.com/emqx/emqx/pull/9609)
|
||||||
|
|
||||||
|
- 确保黑名单的默认超期时间足够长 [#9599](https://github.com/emqx/emqx/pull/9599/)。
|
||||||
|
|
||||||
## 修复
|
## 修复
|
||||||
|
|
||||||
- 当 QoS2 消息被重发(使用相同 Packet ID),或当 'awaiting_rel' 队列已满时,触发消息丢弃钩子(`message.dropped`)及计数器 [#9487](https://github.com/emqx/emqx/pull/9487)。
|
- 当 QoS2 消息被重发(使用相同 Packet ID),或当 'awaiting_rel' 队列已满时,触发消息丢弃钩子(`message.dropped`)及计数器 [#9487](https://github.com/emqx/emqx/pull/9487)。
|
||||||
|
|
Loading…
Reference in New Issue