test(rocketmq): add an ACL test case
This commit is contained in:
parent
b5f24c4f88
commit
ea9b1e13d5
|
@ -23,6 +23,7 @@ services:
|
||||||
- ./rocketmq/logs:/opt/logs
|
- ./rocketmq/logs:/opt/logs
|
||||||
- ./rocketmq/store:/opt/store
|
- ./rocketmq/store:/opt/store
|
||||||
- ./rocketmq/conf/broker.conf:/etc/rocketmq/broker.conf
|
- ./rocketmq/conf/broker.conf:/etc/rocketmq/broker.conf
|
||||||
|
- ./rocketmq/conf/plain_acl.yml:/home/rocketmq/rocketmq-4.9.4/conf/plain_acl.yml
|
||||||
environment:
|
environment:
|
||||||
NAMESRV_ADDR: "rocketmq_namesrv:9876"
|
NAMESRV_ADDR: "rocketmq_namesrv:9876"
|
||||||
JAVA_OPTS: " -Duser.home=/opt -Drocketmq.broker.diskSpaceWarningLevelRatio=0.99"
|
JAVA_OPTS: " -Duser.home=/opt -Drocketmq.broker.diskSpaceWarningLevelRatio=0.99"
|
||||||
|
|
|
@ -20,3 +20,5 @@ maxMessageSize=65536
|
||||||
brokerRole=ASYNC_MASTER
|
brokerRole=ASYNC_MASTER
|
||||||
|
|
||||||
flushDiskType=ASYNC_FLUSH
|
flushDiskType=ASYNC_FLUSH
|
||||||
|
|
||||||
|
aclEnable=true
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
globalWhiteRemoteAddresses:
|
||||||
|
|
||||||
|
accounts:
|
||||||
|
- accessKey: RocketMQ
|
||||||
|
secretKey: 12345678
|
||||||
|
whiteRemoteAddress:
|
||||||
|
admin: false
|
||||||
|
defaultTopicPerm: DENY
|
||||||
|
defaultGroupPerm: PUB|SUB
|
||||||
|
topicPerms:
|
||||||
|
- TopicTest=PUB|SUB
|
|
@ -13,6 +13,9 @@
|
||||||
|
|
||||||
% Bridge defaults
|
% Bridge defaults
|
||||||
-define(TOPIC, "TopicTest").
|
-define(TOPIC, "TopicTest").
|
||||||
|
-define(DENY_TOPIC, "DENY_TOPIC").
|
||||||
|
-define(ACCESS_KEY, "RocketMQ").
|
||||||
|
-define(SECRET_KEY, "12345678").
|
||||||
-define(BATCH_SIZE, 10).
|
-define(BATCH_SIZE, 10).
|
||||||
-define(PAYLOAD, <<"HELLO">>).
|
-define(PAYLOAD, <<"HELLO">>).
|
||||||
|
|
||||||
|
@ -25,17 +28,19 @@
|
||||||
all() ->
|
all() ->
|
||||||
[
|
[
|
||||||
{group, async},
|
{group, async},
|
||||||
{group, sync}
|
{group, sync},
|
||||||
|
{group, acl}
|
||||||
].
|
].
|
||||||
|
|
||||||
groups() ->
|
groups() ->
|
||||||
TCs = emqx_common_test_helpers:all(?MODULE),
|
TCs = emqx_common_test_helpers:all(?MODULE) -- [t_acl_deny],
|
||||||
BatchingGroups = [{group, with_batch}, {group, without_batch}],
|
BatchingGroups = [{group, with_batch}, {group, without_batch}],
|
||||||
[
|
[
|
||||||
{async, BatchingGroups},
|
{async, BatchingGroups},
|
||||||
{sync, BatchingGroups},
|
{sync, BatchingGroups},
|
||||||
{with_batch, TCs},
|
{with_batch, TCs},
|
||||||
{without_batch, TCs}
|
{without_batch, TCs},
|
||||||
|
{acl, [t_acl_deny]}
|
||||||
].
|
].
|
||||||
|
|
||||||
init_per_group(async, Config) ->
|
init_per_group(async, Config) ->
|
||||||
|
@ -48,6 +53,9 @@ init_per_group(with_batch, Config0) ->
|
||||||
init_per_group(without_batch, Config0) ->
|
init_per_group(without_batch, Config0) ->
|
||||||
Config = [{batch_size, 1} | Config0],
|
Config = [{batch_size, 1} | Config0],
|
||||||
common_init(Config);
|
common_init(Config);
|
||||||
|
init_per_group(acl, Config0) ->
|
||||||
|
Config = [{batch_size, 1}, {query_mode, sync} | Config0],
|
||||||
|
common_init(Config);
|
||||||
init_per_group(_Group, Config) ->
|
init_per_group(_Group, Config) ->
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
|
@ -137,6 +145,8 @@ rocketmq_config(BridgeType, Config) ->
|
||||||
"bridges.~s.~s {\n"
|
"bridges.~s.~s {\n"
|
||||||
" enable = true\n"
|
" enable = true\n"
|
||||||
" servers = ~p\n"
|
" servers = ~p\n"
|
||||||
|
" access_key = ~p\n"
|
||||||
|
" secret_key = ~p\n"
|
||||||
" topic = ~p\n"
|
" topic = ~p\n"
|
||||||
" resource_opts = {\n"
|
" resource_opts = {\n"
|
||||||
" request_timeout = 1500ms\n"
|
" request_timeout = 1500ms\n"
|
||||||
|
@ -148,6 +158,8 @@ rocketmq_config(BridgeType, Config) ->
|
||||||
BridgeType,
|
BridgeType,
|
||||||
Name,
|
Name,
|
||||||
Server,
|
Server,
|
||||||
|
?ACCESS_KEY,
|
||||||
|
?SECRET_KEY,
|
||||||
?TOPIC,
|
?TOPIC,
|
||||||
BatchSize,
|
BatchSize,
|
||||||
QueryMode
|
QueryMode
|
||||||
|
@ -271,3 +283,29 @@ t_simple_query(Config) ->
|
||||||
Result = query_resource(Config, Request),
|
Result = query_resource(Config, Request),
|
||||||
?assertEqual(ok, Result),
|
?assertEqual(ok, Result),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
t_acl_deny(Config0) ->
|
||||||
|
RocketCfg = ?GET_CONFIG(rocketmq_config, Config0),
|
||||||
|
RocketCfg2 = RocketCfg#{<<"topic">> := ?DENY_TOPIC},
|
||||||
|
Config = lists:keyreplace(rocketmq_config, 1, Config0, {rocketmq_config, RocketCfg2}),
|
||||||
|
?assertMatch(
|
||||||
|
{ok, _},
|
||||||
|
create_bridge(Config)
|
||||||
|
),
|
||||||
|
SentData = #{payload => ?PAYLOAD},
|
||||||
|
?check_trace(
|
||||||
|
begin
|
||||||
|
?wait_async_action(
|
||||||
|
?assertMatch({error, #{<<"code">> := 1}}, send_message(Config, SentData)),
|
||||||
|
#{?snk_kind := rocketmq_connector_query_return},
|
||||||
|
10_000
|
||||||
|
),
|
||||||
|
ok
|
||||||
|
end,
|
||||||
|
fun(Trace0) ->
|
||||||
|
Trace = ?of_kind(rocketmq_connector_query_return, Trace0),
|
||||||
|
?assertMatch([#{error := #{<<"code">> := 1}}], Trace),
|
||||||
|
ok
|
||||||
|
end
|
||||||
|
),
|
||||||
|
ok.
|
||||||
|
|
Loading…
Reference in New Issue