From dea93f387e6332aeebd12de7355a6231a895a578 Mon Sep 17 00:00:00 2001 From: Janusz Jakubiec Date: Fri, 29 Dec 2023 09:22:51 +0100 Subject: [PATCH 1/3] Adding chages to mod_mam_pm, now it is discoverable by disco sent to bare jid --- big_tests/tests/mam_SUITE.erl | 12 +++++++++++- src/mam/mod_mam_pm.erl | 9 +++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/big_tests/tests/mam_SUITE.erl b/big_tests/tests/mam_SUITE.erl index 078a8408179..0b5f0cd4cec 100644 --- a/big_tests/tests/mam_SUITE.erl +++ b/big_tests/tests/mam_SUITE.erl @@ -33,6 +33,7 @@ muc_no_elements/1, muc_only_stanzaid/1, mam_service_discovery/1, + mam_service_discovery_to_client_bare_jid/1, muc_service_discovery/1, easy_archive_request/1, easy_archive_request_for_the_receiver/1, @@ -362,7 +363,7 @@ basic_groups() -> [{mam04, [parallel], chat_markers_cases()}]}, {disabled_retraction, [], [{mam06, [parallel], disabled_retract_cases() ++ - [mam_service_discovery]}]}, + [mam_service_discovery, mam_service_discovery_to_client_bare_jid]}]}, {muc_disabled_retraction, [], [{muc06, [parallel], disabled_muc_retract_cases() ++ [muc_service_discovery]}]} @@ -378,6 +379,7 @@ mam_metrics_cases() -> mam_cases() -> [mam_service_discovery, + mam_service_discovery_to_client_bare_jid, easy_archive_request, easy_archive_request_for_the_receiver, message_sent_to_yourself, @@ -2891,6 +2893,14 @@ mam_service_discovery(Config) -> end, escalus_fresh:story(Config, [{alice, 1}], F). +mam_service_discovery_to_client_bare_jid(Config) -> + _P = ?config(props, Config), + F = fun(Alice) -> + Address = inbox_helper:to_bare_lower(Alice), + discover_features(Config, Alice, Address) + end, + escalus_fresh:story(Config, [{alice, 1}], F). + %% Check, that MUC is supported. muc_service_discovery(Config) -> _P = ?config(props, Config), diff --git a/src/mam/mod_mam_pm.erl b/src/mam/mod_mam_pm.erl index 54b9189206d..aa46b8c07f6 100644 --- a/src/mam/mod_mam_pm.erl +++ b/src/mam/mod_mam_pm.erl @@ -44,6 +44,7 @@ %% hook handlers -export([disco_local_features/3, + disco_sm_features/3, user_send_message/3, filter_packet/3, remove_user/3, @@ -165,6 +166,13 @@ disco_local_features(Acc = #{host_type := HostType, node := <<>>}, _, _) -> disco_local_features(Acc, _, _) -> {ok, Acc}. +-spec disco_sm_features(mongoose_disco:feature_acc(), + map(), map()) -> {ok, mongoose_disco:feature_acc()}. +disco_sm_features(Acc = #{host_type := HostType, node := <<>>}, _, _) -> + {ok, mongoose_disco:add_features(mod_mam_utils:features(?MODULE, HostType), Acc)}; +disco_sm_features(Acc, _, _) -> + {ok, Acc}. + %% @doc Handle an outgoing message. %% %% Note: for outgoing messages, the server MUST use the value of the 'to' @@ -667,6 +675,7 @@ is_archivable_message(HostType, Dir, Packet) -> hooks(HostType) -> [ {disco_local_features, HostType, fun ?MODULE:disco_local_features/3, #{}, 99}, + {disco_sm_features, HostType, fun ?MODULE:disco_sm_features/3, #{}, 99}, {user_send_message, HostType, fun ?MODULE:user_send_message/3, #{}, 60}, {filter_local_packet, HostType, fun ?MODULE:filter_packet/3, #{}, 60}, {remove_user, HostType, fun ?MODULE:remove_user/3, #{}, 50}, From b9ca511f48c630b82ddecc61b33d0fddaf4ca58d Mon Sep 17 00:00:00 2001 From: Janusz Jakubiec Date: Wed, 3 Jan 2024 09:38:39 +0100 Subject: [PATCH 2/3] Adding tests checking if sending disco to different jid results in error --- big_tests/tests/mam_SUITE.erl | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/big_tests/tests/mam_SUITE.erl b/big_tests/tests/mam_SUITE.erl index 0b5f0cd4cec..772f401af05 100644 --- a/big_tests/tests/mam_SUITE.erl +++ b/big_tests/tests/mam_SUITE.erl @@ -34,6 +34,7 @@ muc_only_stanzaid/1, mam_service_discovery/1, mam_service_discovery_to_client_bare_jid/1, + mam_service_discovery_to_different_client_bare_jid_results_in_error/1, muc_service_discovery/1, easy_archive_request/1, easy_archive_request_for_the_receiver/1, @@ -363,7 +364,9 @@ basic_groups() -> [{mam04, [parallel], chat_markers_cases()}]}, {disabled_retraction, [], [{mam06, [parallel], disabled_retract_cases() ++ - [mam_service_discovery, mam_service_discovery_to_client_bare_jid]}]}, + [mam_service_discovery, + mam_service_discovery_to_client_bare_jid, + mam_service_discovery_to_different_client_bare_jid_results_in_error]}]}, {muc_disabled_retraction, [], [{muc06, [parallel], disabled_muc_retract_cases() ++ [muc_service_discovery]}]} @@ -380,6 +383,7 @@ mam_metrics_cases() -> mam_cases() -> [mam_service_discovery, mam_service_discovery_to_client_bare_jid, + mam_service_discovery_to_different_client_bare_jid_results_in_error, easy_archive_request, easy_archive_request_for_the_receiver, message_sent_to_yourself, @@ -2901,6 +2905,16 @@ mam_service_discovery_to_client_bare_jid(Config) -> end, escalus_fresh:story(Config, [{alice, 1}], F). +mam_service_discovery_to_different_client_bare_jid_results_in_error(Config) -> + _P = ?config(props, Config), + F = fun(Alice, Bob) -> + Address = inbox_helper:to_bare_lower(Bob), + escalus:send(Alice, escalus_stanza:disco_info(Address)), + Stanza = escalus:wait_for_stanza(Alice), + escalus:assert(is_error, [<<"cancel">>, <<"service-unavailable">>], Stanza) + end, + escalus_fresh:story(Config, [{alice, 1}, {bob, 1}], F). + %% Check, that MUC is supported. muc_service_discovery(Config) -> _P = ?config(props, Config), From c1828ec4ae1136a07f5034467e02cdf3ab382248 Mon Sep 17 00:00:00 2001 From: Janusz Jakubiec Date: Wed, 3 Jan 2024 11:12:06 +0100 Subject: [PATCH 3/3] Applying CR comments --- big_tests/tests/mam_SUITE.erl | 7 ------- 1 file changed, 7 deletions(-) diff --git a/big_tests/tests/mam_SUITE.erl b/big_tests/tests/mam_SUITE.erl index a6aaa3953d0..0b3cfff9713 100644 --- a/big_tests/tests/mam_SUITE.erl +++ b/big_tests/tests/mam_SUITE.erl @@ -2856,7 +2856,6 @@ after_complete_true_after11(Config) -> %% ------------------------------------------------------------------ prefs_set_request(Config) -> - _P = ?config(props, Config), F = fun(Alice) -> %% Send %% @@ -2906,7 +2905,6 @@ query_get_request(Config) -> %% without whitespaces. In the real world it is not true. %% Put "\n" between two jid elements. prefs_set_cdata_request(Config) -> - _P = ?config(props, Config), F = fun(Alice) -> %% Send %% @@ -2936,7 +2934,6 @@ prefs_set_cdata_request(Config) -> escalus_fresh:story(Config, [{alice, 1}], F). mam_service_discovery(Config) -> - _P = ?config(props, Config), F = fun(Alice) -> Server = escalus_client:server(Alice), discover_features(Config, Alice, Server) @@ -2944,7 +2941,6 @@ mam_service_discovery(Config) -> escalus_fresh:story(Config, [{alice, 1}], F). mam_service_discovery_to_client_bare_jid(Config) -> - _P = ?config(props, Config), F = fun(Alice) -> Address = inbox_helper:to_bare_lower(Alice), discover_features(Config, Alice, Address) @@ -2952,7 +2948,6 @@ mam_service_discovery_to_client_bare_jid(Config) -> escalus_fresh:story(Config, [{alice, 1}], F). mam_service_discovery_to_different_client_bare_jid_results_in_error(Config) -> - _P = ?config(props, Config), F = fun(Alice, Bob) -> Address = inbox_helper:to_bare_lower(Bob), escalus:send(Alice, escalus_stanza:disco_info(Address)), @@ -2963,7 +2958,6 @@ mam_service_discovery_to_different_client_bare_jid_results_in_error(Config) -> %% Check, that MUC is supported. muc_service_discovery(Config) -> - _P = ?config(props, Config), F = fun(Alice) -> Domain = domain(), Server = escalus_client:server(Alice), @@ -3069,7 +3063,6 @@ run_prefs_cases(DefaultPolicy, ConfigIn) -> %% The same as prefs_set_request case but for different configurations run_set_and_get_prefs_cases(ConfigIn) -> - _P = ?config(props, ConfigIn), F = fun(Config, Alice, _Bob, _Kate) -> Namespace = mam_ns_binary_v04(), [run_set_and_get_prefs_case(Case, Namespace, Alice, Config) || Case <- prefs_cases2()]