Comment 'TEST_DEPS = emqx_ct_helplers'
This commit is contained in:
parent
754f86ce57
commit
b1dadf444f
|
@ -139,18 +139,18 @@ unregister_mod(_) ->
|
||||||
[] = ?AC:lookup_mods(auth).
|
[] = ?AC:lookup_mods(auth).
|
||||||
|
|
||||||
check_acl_1(_) ->
|
check_acl_1(_) ->
|
||||||
SelfUser = #client{id = <<"client1">>, username = <<"testuser">>},
|
SelfUser = #{client_id => <<"client1">>, username => <<"testuser">>},
|
||||||
allow = ?AC:check_acl(SelfUser, subscribe, <<"users/testuser/1">>),
|
allow = ?AC:check_acl(SelfUser, subscribe, <<"users/testuser/1">>),
|
||||||
allow = ?AC:check_acl(SelfUser, subscribe, <<"clients/client1">>),
|
allow = ?AC:check_acl(SelfUser, subscribe, <<"clients/client1">>),
|
||||||
deny = ?AC:check_acl(SelfUser, subscribe, <<"clients/client1/x/y">>),
|
deny = ?AC:check_acl(SelfUser, subscribe, <<"clients/client1/x/y">>),
|
||||||
allow = ?AC:check_acl(SelfUser, publish, <<"users/testuser/1">>),
|
allow = ?AC:check_acl(SelfUser, publish, <<"users/testuser/1">>),
|
||||||
allow = ?AC:check_acl(SelfUser, subscribe, <<"a/b/c">>).
|
allow = ?AC:check_acl(SelfUser, subscribe, <<"a/b/c">>).
|
||||||
check_acl_2(_) ->
|
check_acl_2(_) ->
|
||||||
SelfUser = #client{id = <<"client2">>, username = <<"xyz">>},
|
SelfUser = #{client_id => <<"client2">>, username => <<"xyz">>},
|
||||||
deny = ?AC:check_acl(SelfUser, subscribe, <<"a/b/c">>).
|
deny = ?AC:check_acl(SelfUser, subscribe, <<"a/b/c">>).
|
||||||
|
|
||||||
acl_cache_basic(_) ->
|
acl_cache_basic(_) ->
|
||||||
SelfUser = #client{id = <<"client1">>, username = <<"testuser">>},
|
SelfUser = #{client_id => <<"client1">>, username => <<"testuser">>},
|
||||||
not_found = ?CACHE:get_acl_cache(subscribe, <<"users/testuser/1">>),
|
not_found = ?CACHE:get_acl_cache(subscribe, <<"users/testuser/1">>),
|
||||||
not_found = ?CACHE:get_acl_cache(subscribe, <<"clients/client1">>),
|
not_found = ?CACHE:get_acl_cache(subscribe, <<"clients/client1">>),
|
||||||
|
|
||||||
|
@ -163,8 +163,7 @@ acl_cache_basic(_) ->
|
||||||
|
|
||||||
acl_cache_expiry(_) ->
|
acl_cache_expiry(_) ->
|
||||||
application:set_env(emqx, acl_cache_ttl, 100),
|
application:set_env(emqx, acl_cache_ttl, 100),
|
||||||
|
SelfUser = #{client_id => <<"client1">>, username => <<"testuser">>},
|
||||||
SelfUser = #client{id = <<"client1">>, username = <<"testuser">>},
|
|
||||||
allow = ?AC:check_acl(SelfUser, subscribe, <<"clients/client1">>),
|
allow = ?AC:check_acl(SelfUser, subscribe, <<"clients/client1">>),
|
||||||
allow = ?CACHE:get_acl_cache(subscribe, <<"clients/client1">>),
|
allow = ?CACHE:get_acl_cache(subscribe, <<"clients/client1">>),
|
||||||
ct:sleep(150),
|
ct:sleep(150),
|
||||||
|
@ -174,7 +173,7 @@ acl_cache_expiry(_) ->
|
||||||
acl_cache_full(_) ->
|
acl_cache_full(_) ->
|
||||||
application:set_env(emqx, acl_cache_max_size, 1),
|
application:set_env(emqx, acl_cache_max_size, 1),
|
||||||
|
|
||||||
SelfUser = #client{id = <<"client1">>, username = <<"testuser">>},
|
SelfUser = #{client_id => <<"client1">>, username => <<"testuser">>},
|
||||||
allow = ?AC:check_acl(SelfUser, subscribe, <<"users/testuser/1">>),
|
allow = ?AC:check_acl(SelfUser, subscribe, <<"users/testuser/1">>),
|
||||||
allow = ?AC:check_acl(SelfUser, subscribe, <<"clients/client1">>),
|
allow = ?AC:check_acl(SelfUser, subscribe, <<"clients/client1">>),
|
||||||
|
|
||||||
|
@ -189,7 +188,7 @@ acl_cache_cleanup(_) ->
|
||||||
application:set_env(emqx, acl_cache_ttl, 100),
|
application:set_env(emqx, acl_cache_ttl, 100),
|
||||||
application:set_env(emqx, acl_cache_max_size, 2),
|
application:set_env(emqx, acl_cache_max_size, 2),
|
||||||
|
|
||||||
SelfUser = #client{id = <<"client1">>, username = <<"testuser">>},
|
SelfUser = #{client_id => <<"client1">>, username => <<"testuser">>},
|
||||||
allow = ?AC:check_acl(SelfUser, subscribe, <<"users/testuser/1">>),
|
allow = ?AC:check_acl(SelfUser, subscribe, <<"users/testuser/1">>),
|
||||||
allow = ?AC:check_acl(SelfUser, subscribe, <<"clients/client1">>),
|
allow = ?AC:check_acl(SelfUser, subscribe, <<"clients/client1">>),
|
||||||
|
|
||||||
|
@ -334,7 +333,6 @@ cache_auto_cleanup(_) ->
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
compile_rule(_) ->
|
compile_rule(_) ->
|
||||||
|
|
||||||
{allow, {'and', [{ipaddr, {{127,0,0,1}, {127,0,0,1}, 32}},
|
{allow, {'and', [{ipaddr, {{127,0,0,1}, {127,0,0,1}, 32}},
|
||||||
{user, <<"user">>}]}, subscribe, [ [<<"$SYS">>, '#'], ['#'] ]} =
|
{user, <<"user">>}]}, subscribe, [ [<<"$SYS">>, '#'], ['#'] ]} =
|
||||||
compile({allow, {'and', [{ipaddr, "127.0.0.1"}, {user, <<"user">>}]}, subscribe, ["$SYS/#", "#"]}),
|
compile({allow, {'and', [{ipaddr, "127.0.0.1"}, {user, <<"user">>}]}, subscribe, ["$SYS/#", "#"]}),
|
||||||
|
@ -360,8 +358,8 @@ compile_rule(_) ->
|
||||||
{deny, all} = compile({deny, all}).
|
{deny, all} = compile({deny, all}).
|
||||||
|
|
||||||
match_rule(_) ->
|
match_rule(_) ->
|
||||||
User = #client{peername = {{127,0,0,1}, 2948}, id = <<"testClient">>, username = <<"TestUser">>},
|
User = #{client_id => <<"testClient">>, username => <<"TestUser">>, peername => {{127,0,0,1}, 2948}},
|
||||||
User2 = #client{peername = {{192,168,0,10}, 3028}, id = <<"testClient">>, username = <<"TestUser">>},
|
User2 = #{client_id => <<"testClient">>, username => <<"TestUser">>, peername => {{192,168,0,10}, 3028}},
|
||||||
|
|
||||||
{matched, allow} = match(User, <<"Test/Topic">>, {allow, all}),
|
{matched, allow} = match(User, <<"Test/Topic">>, {allow, all}),
|
||||||
{matched, deny} = match(User, <<"Test/Topic">>, {deny, all}),
|
{matched, deny} = match(User, <<"Test/Topic">>, {deny, all}),
|
||||||
|
@ -371,8 +369,7 @@ match_rule(_) ->
|
||||||
nomatch = match(User, <<"d/e/f/x">>, compile({allow, {user, "admin"}, pubsub, ["d/e/f/#"]})),
|
nomatch = match(User, <<"d/e/f/x">>, compile({allow, {user, "admin"}, pubsub, ["d/e/f/#"]})),
|
||||||
{matched, allow} = match(User, <<"testTopics/testClient">>, compile({allow, {client, "testClient"}, publish, ["testTopics/testClient"]})),
|
{matched, allow} = match(User, <<"testTopics/testClient">>, compile({allow, {client, "testClient"}, publish, ["testTopics/testClient"]})),
|
||||||
{matched, allow} = match(User, <<"clients/testClient">>, compile({allow, all, pubsub, ["clients/%c"]})),
|
{matched, allow} = match(User, <<"clients/testClient">>, compile({allow, all, pubsub, ["clients/%c"]})),
|
||||||
{matched, allow} = match(#client{username = <<"user2">>}, <<"users/user2/abc/def">>,
|
{matched, allow} = match(#{username => <<"user2">>}, <<"users/user2/abc/def">>, compile({allow, all, subscribe, ["users/%u/#"]})),
|
||||||
compile({allow, all, subscribe, ["users/%u/#"]})),
|
|
||||||
{matched, deny} = match(User, <<"d/e/f">>, compile({deny, all, subscribe, ["$SYS/#", "#"]})),
|
{matched, deny} = match(User, <<"d/e/f">>, compile({deny, all, subscribe, ["$SYS/#", "#"]})),
|
||||||
Rule = compile({allow, {'and', [{ipaddr, "127.0.0.1"}, {user, <<"WrongUser">>}]}, publish, <<"Topic">>}),
|
Rule = compile({allow, {'and', [{ipaddr, "127.0.0.1"}, {user, <<"WrongUser">>}]}, publish, <<"Topic">>}),
|
||||||
nomatch = match(User, <<"Topic">>, Rule),
|
nomatch = match(User, <<"Topic">>, Rule),
|
||||||
|
@ -380,3 +377,4 @@ match_rule(_) ->
|
||||||
{matched, allow} = match(User, <<"Topic">>, AndRule),
|
{matched, allow} = match(User, <<"Topic">>, AndRule),
|
||||||
OrRule = compile({allow, {'or', [{ipaddr, "127.0.0.1"}, {user, <<"WrongUser">>}]}, publish, ["Topic"]}),
|
OrRule = compile({allow, {'or', [{ipaddr, "127.0.0.1"}, {user, <<"WrongUser">>}]}, publish, ["Topic"]}),
|
||||||
{matched, allow} = match(User, <<"Topic">>, OrRule).
|
{matched, allow} = match(User, <<"Topic">>, OrRule).
|
||||||
|
|
||||||
|
|
|
@ -36,15 +36,12 @@ stop(CPid) ->
|
||||||
gen_server:call(CPid, stop).
|
gen_server:call(CPid, stop).
|
||||||
|
|
||||||
init([ClientId]) ->
|
init([ClientId]) ->
|
||||||
{ok,
|
{ok, #state{clean_start = true, client_id = ClientId}}.
|
||||||
#state{clean_start = true,
|
|
||||||
client_id = ClientId}
|
|
||||||
}.
|
|
||||||
|
|
||||||
handle_call({start_session, ClientPid, ClientId, Zone}, _From, State) ->
|
handle_call({start_session, ClientPid, ClientId, Zone}, _From, State) ->
|
||||||
Attrs = #{ zone => Zone,
|
Attrs = #{ zone => Zone,
|
||||||
client_id => ClientId,
|
client_id => ClientId,
|
||||||
client_pid => ClientPid,
|
conn_pid => ClientPid,
|
||||||
clean_start => true,
|
clean_start => true,
|
||||||
username => undefined,
|
username => undefined,
|
||||||
conn_props => undefined
|
conn_props => undefined
|
||||||
|
|
|
@ -14,22 +14,23 @@
|
||||||
|
|
||||||
-module(emqx_sm_SUITE).
|
-module(emqx_sm_SUITE).
|
||||||
|
|
||||||
|
-include("emqx.hrl").
|
||||||
|
|
||||||
-compile(export_all).
|
-compile(export_all).
|
||||||
-compile(nowarn_export_all).
|
-compile(nowarn_export_all).
|
||||||
|
|
||||||
-include("emqx.hrl").
|
|
||||||
|
|
||||||
all() -> [t_open_close_session].
|
all() -> [t_open_close_session].
|
||||||
|
|
||||||
t_open_close_session(_) ->
|
t_open_close_session(_) ->
|
||||||
emqx_ct_broker_helpers:run_setup_steps(),
|
emqx_ct_broker_helpers:run_setup_steps(),
|
||||||
{ok, ClientPid} = emqx_mock_client:start_link(<<"client">>),
|
{ok, ClientPid} = emqx_mock_client:start_link(<<"client">>),
|
||||||
Attrs = #{clean_start => true, client_id => <<"client">>, client_pid => ClientPid, zone => internal, username => <<"zhou">>, conn_props => ref},
|
Attrs = #{clean_start => true, client_id => <<"client">>, conn_pid => ClientPid,
|
||||||
|
zone => internal, username => <<"zhou">>, conn_props => #{}},
|
||||||
{ok, _SPid} = emqx_sm:open_session(Attrs),
|
{ok, _SPid} = emqx_sm:open_session(Attrs),
|
||||||
[{<<"client">>, SPid}] = emqx_sm:lookup_session(<<"client">>),
|
[{<<"client">>, SPid}] = emqx_sm:lookup_session(<<"client">>),
|
||||||
SPid = emqx_sm:lookup_session_pid(<<"client">>),
|
SPid = emqx_sm:lookup_session_pid(<<"client">>),
|
||||||
{ok, NewClientPid} = emqx_mock_client:start_link(<<"client">>),
|
{ok, NewConnPid} = emqx_mock_client:start_link(<<"client">>),
|
||||||
{ok, SPid, true} = emqx_sm:open_session(Attrs#{clean_start => false, client_pid => NewClientPid}),
|
{ok, SPid, true} = emqx_sm:open_session(Attrs#{clean_start => false, conn_pid => NewConnPid}),
|
||||||
[{<<"client">>, SPid}] = emqx_sm:lookup_session(<<"client">>),
|
[{<<"client">>, SPid}] = emqx_sm:lookup_session(<<"client">>),
|
||||||
SAttrs = emqx_sm:get_session_attrs({<<"client">>, SPid}),
|
SAttrs = emqx_sm:get_session_attrs({<<"client">>, SPid}),
|
||||||
<<"client">> = proplists:get_value(client_id, SAttrs),
|
<<"client">> = proplists:get_value(client_id, SAttrs),
|
||||||
|
@ -38,3 +39,4 @@ t_open_close_session(_) ->
|
||||||
{open, true} = emqx_sm:get_session_stats(Session),
|
{open, true} = emqx_sm:get_session_stats(Session),
|
||||||
ok = emqx_sm:close_session(SPid),
|
ok = emqx_sm:close_session(SPid),
|
||||||
[] = emqx_sm:lookup_session(<<"client">>).
|
[] = emqx_sm:lookup_session(<<"client">>).
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue