access test
This commit is contained in:
parent
e674d00330
commit
bd0c49329b
|
@ -43,7 +43,10 @@ register_mod_test() ->
|
|||
fun() ->
|
||||
emqttd_access_control:register_mod(acl, emqttd_acl_test_mod, []),
|
||||
?assertMatch([{emqttd_acl_test_mod, _}, {emqttd_acl_internal, _}],
|
||||
emqttd_access_control:lookup_mods(acl))
|
||||
emqttd_access_control:lookup_mods(acl)),
|
||||
emqttd_access_control:register_mod(auth, emqttd_auth_anonymous_test_mod,[]),
|
||||
?assertMatch([{emqttd_auth_anonymous_test_mod, _}, {emqttd_auth_anonymous, _}],
|
||||
emqttd_access_control:lookup_mods(auth))
|
||||
end).
|
||||
|
||||
unregister_mod_test() ->
|
||||
|
@ -54,7 +57,15 @@ unregister_mod_test() ->
|
|||
emqttd_access_control:lookup_mods(acl)),
|
||||
emqttd_access_control:unregister_mod(acl, emqttd_acl_test_mod),
|
||||
timer:sleep(5),
|
||||
?assertMatch([{emqttd_acl_internal, _}], emqttd_access_control:lookup_mods(acl))
|
||||
?assertMatch([{emqttd_acl_internal, _}], emqttd_access_control:lookup_mods(acl)),
|
||||
|
||||
emqttd_access_control:register_mod(auth, emqttd_auth_anonymous_test_mod,[]),
|
||||
?assertMatch([{emqttd_auth_anonymous_test_mod, _}, {emqttd_auth_anonymous, _}],
|
||||
emqttd_access_control:lookup_mods(auth)),
|
||||
|
||||
emqttd_access_control:unregister_mod(auth, emqttd_auth_anonymous_test_mod),
|
||||
timer:sleep(5),
|
||||
?assertMatch([{emqttd_auth_anonymous, _}], emqttd_access_control:lookup_mods(auth))
|
||||
end).
|
||||
|
||||
check_acl_test() ->
|
||||
|
@ -64,7 +75,7 @@ check_acl_test() ->
|
|||
User2 = #mqtt_client{clientid = <<"client2">>, username = <<"xyz">>},
|
||||
?assertEqual(allow, emqttd_access_control:check_acl(User1, subscribe, <<"users/testuser/1">>)),
|
||||
?assertEqual(allow, emqttd_access_control:check_acl(User1, subscribe, <<"clients/client1">>)),
|
||||
%?assertEqual(deny, emqttd_access_control:check_acl(User1, subscribe, <<"clients/client1/x/y">>)),
|
||||
?assertEqual(deny, emqttd_access_control:check_acl(User1, subscribe, <<"clients/client1/x/y">>)),
|
||||
?assertEqual(allow, emqttd_access_control:check_acl(User1, publish, <<"users/testuser/1">>)),
|
||||
?assertEqual(allow, emqttd_access_control:check_acl(User1, subscribe, <<"a/b/c">>)),
|
||||
?assertEqual(deny, emqttd_access_control:check_acl(User2, subscribe, <<"a/b/c">>))
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
%%%-----------------------------------------------------------------------------
|
||||
%%% @Copyright (C) 2012-2015, Feng Lee <feng@emqtt.io>
|
||||
%%%
|
||||
%%% Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
%%% of this software and associated documentation files (the "Software"), to deal
|
||||
%%% in the Software without restriction, including without limitation the rights
|
||||
%%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
%%% copies of the Software, and to permit persons to whom the Software is
|
||||
%%% furnished to do so, subject to the following conditions:
|
||||
%%%
|
||||
%%% The above copyright notice and this permission notice shall be included in all
|
||||
%%% copies or substantial portions of the Software.
|
||||
%%%
|
||||
%%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
%%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
%%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
%%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
%%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
%%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
%%% SOFTWARE.
|
||||
%%%-----------------------------------------------------------------------------
|
||||
%%% @doc
|
||||
%%% Test ACL Module.
|
||||
%%%
|
||||
%%% @end
|
||||
%%%-----------------------------------------------------------------------------
|
||||
-module(emqttd_auth_anonymous_test_mod).
|
||||
|
||||
%% ACL callbacks
|
||||
-export([init/1, check/3, description/0]).
|
||||
|
||||
init(AclOpts) ->
|
||||
{ok, AclOpts}.
|
||||
|
||||
check(_Client, _Password, _Opts) ->
|
||||
allow.
|
||||
|
||||
description() ->
|
||||
"Test emqttd_auth_anonymous Mod".
|
Loading…
Reference in New Issue