diff --git a/big_tests/dynamic_domains.config b/big_tests/dynamic_domains.config index c9e57df686..1250c781e4 100644 --- a/big_tests/dynamic_domains.config +++ b/big_tests/dynamic_domains.config @@ -84,5 +84,10 @@ {server, <<"example.org">>}, {host, <<"localhost">>}, {password, <<"makota3">>}, - {port, 5232}]} + {port, 5232}]}, + {john, [ + {username, <<"john">>}, + {server, <<"domain.example.com">>}, + {host, <<"localhost">>}, + {password, <<"cosontuma">>}]} ]}. diff --git a/big_tests/dynamic_domains.spec b/big_tests/dynamic_domains.spec index 0de2856af8..f51db454bb 100644 --- a/big_tests/dynamic_domains.spec +++ b/big_tests/dynamic_domains.spec @@ -25,6 +25,8 @@ {suites, "tests", mam_SUITE}. +{suites, "tests", mod_blocking_SUITE}. + {suites, "tests", mod_ping_SUITE}. {suites, "tests", muc_SUITE}. diff --git a/big_tests/test.config b/big_tests/test.config index e690718f9e..b80a83ec38 100644 --- a/big_tests/test.config +++ b/big_tests/test.config @@ -129,6 +129,10 @@ {username, <<"mike">>}, {server, <<"localhost">>}, {password, <<"nicniema">>}]}, + {john, [ + {username, <<"john">>}, + {server, <<"localhost">>}, + {password, <<"cosontuma">>}]}, {geralt, [ {username, <<"geralt">>}, {server, <<"localhost">>}, diff --git a/big_tests/tests/mod_blocking_SUITE.erl b/big_tests/tests/mod_blocking_SUITE.erl index 85ec04d7af..cf0587a912 100644 --- a/big_tests/tests/mod_blocking_SUITE.erl +++ b/big_tests/tests/mod_blocking_SUITE.erl @@ -107,10 +107,10 @@ end_per_suite(Config) -> escalus:end_per_suite(Config). init_per_group(_GroupName, Config) -> - escalus:create_users(Config, escalus:get_users([alice, bob, carol, mike, geralt])). + escalus_fresh:create_users(Config, escalus:get_users([alice, bob, kate, mike, john])). end_per_group(_GroupName, Config) -> - escalus:delete_users(Config, escalus:get_users([alice, bob, carol, mike, geralt])). + Config. init_per_testcase(CaseName, Config) -> escalus:init_per_testcase(CaseName, Config). @@ -176,7 +176,7 @@ add_another_user_to_blocklist(Config) -> add_many_users_to_blocklist(Config) -> escalus:fresh_story( - Config, [{alice, 1}, {bob, 1}, {carol, 1}, {mike, 1}], + Config, [{alice, 1}, {bob, 1}, {kate, 1}, {mike, 1}], fun(User1, User2, User3, User4) -> user_blocks(User1, [User2, User3, User4]), BlockList = get_blocklist(User1), @@ -197,7 +197,7 @@ remove_user_from_blocklist(Config) -> remove_many_user_from_blocklist(Config) -> escalus:fresh_story( - Config, [{alice, 1}, {bob, 1}, {geralt, 1}], + Config, [{alice, 1}, {bob, 1}, {kate, 1}], fun(User1, User2, User3) -> user_blocks(User1, [User2, User3]), user_unblocks(User1, [User2, User3]), @@ -208,7 +208,7 @@ remove_many_user_from_blocklist(Config) -> clear_blocklist(Config) -> escalus:fresh_story( - Config, [{alice, 1}, {bob, 1}, {geralt, 1}], + Config, [{alice, 1}, {bob, 1}, {kate, 1}], fun(User1, User2, User3) -> user_blocks(User1, [User2, User3]), user_unblocks_all(User1), @@ -231,7 +231,8 @@ messages_from_blocked_user_dont_arrive(Config) -> fun(User1, User2) -> user_blocks(User1, [User2]), message(User2, User1, <<"Hi!">>), - client_gets_nothing(User1), + ct:sleep(100), + escalus_assert:has_no_stanzas(User1), privacy_helper:gets_error(User2, <<"cancel">>, <<"service-unavailable">>) end). @@ -255,18 +256,24 @@ messages_from_any_blocked_resource_dont_arrive(Config) -> user_blocks(User2, [User1a]), %% then message_is_not_delivered(User1a, [User2], <<"roar!">>), + privacy_helper:gets_error(User1a, <<"cancel">>, <<"service-unavailable">>), message_is_not_delivered(User1b, [User2], <<"woof!">>), - message_is_not_delivered(User1c, [User2], <<"grrr!">>) + privacy_helper:gets_error(User1b, <<"cancel">>, <<"service-unavailable">>), + message_is_not_delivered(User1c, [User2], <<"grrr!">>), + privacy_helper:gets_error(User1c, <<"cancel">>, <<"service-unavailable">>), + ct:sleep(100), + escalus_assert:has_no_stanzas(User2) end). blocking_doesnt_interfere(Config) -> escalus:fresh_story( - Config, [{alice, 1}, {bob, 1}, {geralt, 1}], + Config, [{alice, 1}, {bob, 1}, {kate, 1}], fun(User1, User2, User3) -> %% given user_blocks(User1, [User2]), %% then message_is_not_delivered(User2, [User1], <<"!@#@$@#$%">>), + privacy_helper:gets_error(User2, <<"cancel">>, <<"service-unavailable">>), message_is_delivered(User3, [User1], <<"Ni hao.">>) end). @@ -285,11 +292,13 @@ blocking_propagates_to_resources(Config) -> client_gets_blocking_error(User1b), % Bob can't send to any of Alice's resources message_is_not_delivered(User2, [User1a], <<"hau!">>), - message_is_not_delivered(User2, [User1b], <<"miau!">>) + privacy_helper:gets_error(User2, <<"cancel">>, <<"service-unavailable">>), + message_is_not_delivered(User2, [User1b], <<"miau!">>), + privacy_helper:gets_error(User2, <<"cancel">>, <<"service-unavailable">>) end). iq_reply_doesnt_crash_user_process(Config) -> - escalus:story(Config, [{alice, 1}, {bob, 1}], fun(Alice, Bob) -> + escalus:fresh_story(Config, [{alice, 1}, {bob, 1}], fun(Alice, Bob) -> QueryWithBlockingNS = escalus_stanza:query_el(?NS_BLOCKING, []), %% Send IQ reply with blocking ns @@ -367,7 +376,7 @@ blocking_and_relogin_many(Config) -> simple_story(Config, Fun) -> escalus:story( - Config, [{alice, 1}, {bob, 1}, {carol, 1}, {mike, 1}, {geralt, 1}], + Config, [{alice, 1}, {bob, 1}, {kate, 1}, {mike, 1}, {john, 1}], Fun ). @@ -630,10 +639,6 @@ user_unblocks_all(User) -> message(From, To, MsgTxt) -> escalus_client:send(From, escalus_stanza:chat_to(To, MsgTxt)). -client_gets_nothing(Client) -> - ct:sleep(500), - escalus_assert:has_no_stanzas(Client). - message_is_delivered(From, [To|_] = Tos, MessageText) -> BareTo = escalus_utils:jid_to_lower(escalus_client:short_jid(To)), escalus:send(From, escalus_stanza:chat_to(BareTo, MessageText)), @@ -647,7 +652,6 @@ message_is_delivered(From, To, MessageText) -> message_is_not_delivered(From, [To|_] = Tos, MessageText) -> BareTo = escalus_utils:jid_to_lower(escalus_client:short_jid(To)), escalus:send(From, escalus_stanza:chat_to(BareTo, MessageText)), - timer:sleep(300), clients_have_no_messages(Tos). clients_have_no_messages(Cs) when is_list (Cs) -> [ client_has_no_messages(C) || C <- Cs ]. diff --git a/big_tests/tests/mod_global_distrib_SUITE.erl b/big_tests/tests/mod_global_distrib_SUITE.erl index e3afbf9ab0..c3fdf17e95 100644 --- a/big_tests/tests/mod_global_distrib_SUITE.erl +++ b/big_tests/tests/mod_global_distrib_SUITE.erl @@ -193,7 +193,7 @@ init_per_group_generic(Config0) -> %% To reduce load when sending many messages VirtHosts = virtual_hosts(), - ModulesToStop = [mod_offline, mod_privacy, mod_roster, mod_last], + ModulesToStop = [mod_offline, mod_blocking, mod_privacy, mod_roster, mod_last], OldMods = save_modules(NodeName, VirtHosts), diff --git a/rel/files/mongooseim.toml b/rel/files/mongooseim.toml index b6b37db3d5..4e8bc701e3 100644 --- a/rel/files/mongooseim.toml +++ b/rel/files/mongooseim.toml @@ -244,8 +244,8 @@ {{{mod_privacy}}} {{/mod_privacy}} {{#mod_blocking}} +[modules.mod_blocking] {{{mod_blocking}}} - {{/mod_blocking}} {{#mod_private}} {{{mod_private}}} diff --git a/rel/mim1.vars-toml.config b/rel/mim1.vars-toml.config index 97c8e2bac2..c90530d3a9 100644 --- a/rel/mim1.vars-toml.config +++ b/rel/mim1.vars-toml.config @@ -9,6 +9,7 @@ {default_server_domain, "\"localhost\""}. {mod_privacy, ""}. +{mod_blocking, ""}. {host_config, "[[host_config]] host = \"anonymous.localhost\" @@ -47,7 +48,11 @@ {{#mod_privacy}} [host_config.modules.mod_privacy] {{{mod_privacy}}} - {{/mod_privacy}}"}. + {{/mod_privacy}} + {{#mod_blocking}} + [host_config.modules.mod_blocking] + {{{mod_blocking}}} + {{/mod_blocking}}"}. {password_format, "password.format = \"scram\" password.hash = [\"sha256\"]"}. {scram_iterations, 64}. diff --git a/rel/vars-toml.config.in b/rel/vars-toml.config.in index bdc12ebeae..c8d84cf926 100644 --- a/rel/vars-toml.config.in +++ b/rel/vars-toml.config.in @@ -25,7 +25,7 @@ {mod_last, ""}. {mod_offline, ""}. {mod_privacy, ""}. -{mod_blocking, "[modules.mod_blocking]"}. +{mod_blocking, ""}. {mod_private, "[modules.mod_private]"}. {mod_roster, ""}. {mod_vcard, "[modules.mod_vcard] diff --git a/src/mod_blocking.erl b/src/mod_blocking.erl index 0955781da8..f555fb4257 100644 --- a/src/mod_blocking.erl +++ b/src/mod_blocking.erl @@ -1,42 +1,49 @@ -%%%------------------------------------------------------------------- -%%% @author bartek -%%% @copyright (C) 2016, -%%% @doc -%%% -%%% @end -%%% Created : 16. May 2016 18:17 -%%%------------------------------------------------------------------- -module(mod_blocking). --xep([{xep, 191}, {version, "1.2"}]). +-xep([{xep, 191}, {version, "1.3"}]). + -behaviour(gen_mod). -behaviour(mongoose_module_metrics). --export([start/2, +-export([start/2]). +-export([stop/1]). +-export([deps/2]). +-export([supported_features/0]). +-export([config_spec/0]). + +-export([ process_iq_get/5, process_iq_set/4, - stop/1, disco_local_features/1 ]). -ignore_xref([disco_local_features/1, process_iq_get/5, process_iq_set/4]). --include("mongoose.hrl"). -include("jlib.hrl"). -include("mod_privacy.hrl"). -type listitem() :: #listitem{}. -start(Host, _Opts) -> - ejabberd_hooks:add(hooks(Host)). +start(HostType, _Opts) -> + ejabberd_hooks:add(hooks(HostType)). + +stop(HostType) -> + ejabberd_hooks:delete(hooks(HostType)). + +deps(_HostType, Opts) -> + [{mod_privacy, Opts, hard}]. -stop(Host) -> - ejabberd_hooks:delete(hooks(Host)). +-spec supported_features() -> [atom()]. +supported_features() -> + [dynamic_domains]. -hooks(Host) -> - [{disco_local_features, Host, ?MODULE, disco_local_features, 99}, - {privacy_iq_get, Host, ?MODULE, process_iq_get, 50}, - {privacy_iq_set, Host, ?MODULE, process_iq_set, 50}]. +config_spec() -> + mod_privacy:config_spec(). + +hooks(HostType) -> + [{disco_local_features, HostType, ?MODULE, disco_local_features, 99}, + {privacy_iq_get, HostType, ?MODULE, process_iq_get, 50}, + {privacy_iq_set, HostType, ?MODULE, process_iq_set, 50}]. -spec disco_local_features(mongoose_disco:feature_acc()) -> mongoose_disco:feature_acc(). disco_local_features(Acc = #{node := <<>>}) -> @@ -211,13 +218,9 @@ make_blocking_list_entry(J) -> broadcast_blocking_command(Acc, LUser, LServer, UserList, _Changed, unblock_all) -> broadcast_blocking_command(Acc, LUser, LServer, UserList, [], unblock); broadcast_blocking_command(Acc, LUser, LServer, UserList, Changed, Type) -> - case jid:make(LUser, LServer, <<>>) of - error -> - Acc; - UserJID -> - Bcast = {blocking, UserList, Type, Changed}, - ejabberd_sm:route(UserJID, UserJID, Acc, {broadcast, Bcast}) - end. + UserJID = jid:make_noprep(LUser, LServer, <<>>), + Bcast = {blocking, UserList, Type, Changed}, + ejabberd_sm:route(UserJID, UserJID, Acc, {broadcast, Bcast}). blocking_query_response(Lst) -> #xmlel{