From d1858f98706b4c6d715ab49f878b03db0dedac42 Mon Sep 17 00:00:00 2001 From: Denys Gonchar Date: Fri, 24 Jan 2025 01:28:11 +0100 Subject: [PATCH 1/6] adding support for old exml format for mam_message_eterm decoder --- src/mam/mam_message_compressed_eterm.erl | 2 +- src/mam/mam_message_eterm.erl | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/mam/mam_message_compressed_eterm.erl b/src/mam/mam_message_compressed_eterm.erl index 4b24fd46a97..6ee6bf80105 100644 --- a/src/mam/mam_message_compressed_eterm.erl +++ b/src/mam/mam_message_compressed_eterm.erl @@ -9,4 +9,4 @@ encode(Packet) -> term_to_binary(Packet, [compressed]). decode(Bin) -> - binary_to_term(Bin). + mam_message_eterm:decode(Bin). diff --git a/src/mam/mam_message_eterm.erl b/src/mam/mam_message_eterm.erl index f361a983f4b..ec55282b6c4 100644 --- a/src/mam/mam_message_eterm.erl +++ b/src/mam/mam_message_eterm.erl @@ -5,8 +5,30 @@ -behaviour(mam_message). +-include_lib("exml/include/exml.hrl"). + +-type old_xmlcdata_format() :: {xmlcdata, Content :: binary()}. +-type old_xmlel_format() :: {xmlel, Name :: binary(), Attrs :: [{binary(),binary()}], + Children :: [old_xmlel_format() | old_xmlcdata_format()]}. encode(Packet) -> term_to_binary(Packet). decode(Bin) -> - binary_to_term(Bin). + Term = binary_to_term(Bin), + maybe_convert_old_exml_format(Term). + +-spec maybe_convert_old_exml_format(exml:element() | old_xmlel_format()) -> + exml:element(). +maybe_convert_old_exml_format({xmlel, _, Attrs, _} = XmlEl) when is_list(Attrs) -> + convert_old_exml_format(XmlEl); +maybe_convert_old_exml_format(XmlEl) -> + XmlEl. + +-spec convert_old_exml_format(old_xmlcdata_format()) -> exml:cdata(); + (old_xmlel_format()) -> exml:element(). +convert_old_exml_format({xmlel, Name, Attrs, Children}) -> + NewAttrs = maps:from_list(Attrs), + NewChildren = [convert_old_exml_format(C) || C <- Children], + #xmlel{name = Name, attrs = NewAttrs, children = NewChildren}; +convert_old_exml_format({xmlcdata, Content}) -> + #xmlcdata{content = Content}. From 2299a2bcfd2f26f93d1364562f6842726ad7c7a0 Mon Sep 17 00:00:00 2001 From: Denys Gonchar Date: Fri, 24 Jan 2025 02:06:51 +0100 Subject: [PATCH 2/6] adding a test for decoding the old exml format --- big_tests/tests/mam_SUITE.erl | 51 ++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/big_tests/tests/mam_SUITE.erl b/big_tests/tests/mam_SUITE.erl index 0ca29134804..57ab9bcd000 100644 --- a/big_tests/tests/mam_SUITE.erl +++ b/big_tests/tests/mam_SUITE.erl @@ -309,6 +309,7 @@ mam_cases() -> mam_service_discovery_to_different_client_bare_jid_results_in_error, archive_is_instrumented, easy_archive_request, + easy_archive_request_old_xmlel_format, easy_archive_request_for_the_receiver, message_sent_to_yourself, range_archive_request, @@ -1238,13 +1239,6 @@ message_dropped(Config) -> easy_archive_request(Config) -> P = ?config(props, Config), F = fun(Alice, Bob) -> - %% Alice sends "OH, HAI!" to Bob - %% {xmlel,<<"message">>, - %% [{<<"from">>,<<"alice@localhost/res1">>}, - %% {<<"to">>,<<"bob@localhost/res1">>}, - %% {<<"xml:lang">>,<<"en">>}, - %% {<<"type">>,<<"chat">>}], - %% [{xmlel,<<"body">>,[],[{xmlcdata,<<"OH, HAI!">>}]}]} escalus:send(Alice, escalus_stanza:chat_to(Bob, <<"OH, HAI!">>)), mam_helper:wait_for_archive_size(Alice, 1), escalus:send(Alice, stanza_archive_request(P, <<"q1">>)), @@ -1271,6 +1265,49 @@ easy_archive_request_for_the_receiver(Config) -> end, escalus_fresh:story(Config, [{alice, 1}, {bob, 1}], F). +easy_archive_request_old_xmlel_format(Config) -> + P = ?config(props, Config), + F = fun(Alice, Bob) -> + AArcId = rest_helper:make_arc_id(Alice), + {BobJid, _, _} = BArcId = rest_helper:make_arc_id(Bob), + DateTime = calendar:local_time(), + Msg = mam_helper:generate_msg_for_date_user(AArcId, BArcId, DateTime, <<"OH, HAI!">>), + Packet = erlang:element(5, Msg), + OldFormatPacket = + {xmlel,<<"message">>, + [{<<"to">>, BobJid}, {<<"type">>,<<"chat">>}], + [{xmlel,<<"body">>,[],[{xmlcdata,<<"OH, HAI!">>}]}]}, + + Msg1 = erlang:setelement(5, Msg, OldFormatPacket), + ct:pal("Packet: ~p~n", [Packet]), + ct:pal("OldFormatPacket: ~p~n", [OldFormatPacket]), + mam_helper:put_msg(Msg1), + mam_helper:wait_for_archive_size(Alice, 1), + escalus:send(Alice, stanza_archive_request(P, <<"q1">>)), + Res = wait_archive_respond(Alice), + assert_lookup_event(mod_mam_pm_lookup, escalus_utils:get_jid(Alice)), + assert_respond_size(1, Res), + assert_respond_query_id(P, <<"q1">>, parse_result_iq(Res)), + [RespMessage] = respond_messages(Res), + ct:pal("ResPacket: ~p~n", [RespMessage]), + + ArchivedMsg = exml_query:path(RespMessage, [{element, <<"result">>}, + {element, <<"forwarded">>}, + {element, <<"message">>}]), + ct:pal("ArchivedMsg: ~p~n", [ArchivedMsg]), + assert_msg_match(Packet, ArchivedMsg), + ok + end, + escalus_fresh:story(Config, [{alice, 1}, {bob, 1}], F). + +assert_msg_match(Pattern, Msg) -> + #xmlel{attrs = PatternAttrs, children = PatternChildren} = Pattern, + #xmlel{attrs = MsgAttrs, children = MsgChildren} = Msg, + [?assertEqual(Value, maps:get(Name, MsgAttrs, undefined), + <<"attribute ", Name/binary>>) + || Name := Value <- PatternAttrs], + ?assertEqual(PatternChildren, MsgChildren). + message_sent_to_yourself(Config) -> P = ?config(props, Config), F = fun(Alice) -> From 359d6fe069baf2ae759f6628292b974120bff5fb Mon Sep 17 00:00:00 2001 From: Denys Gonchar Date: Fri, 24 Jan 2025 02:08:07 +0100 Subject: [PATCH 3/6] removing outdated comments --- big_tests/tests/mam_helper.erl | 24 ------------------------ big_tests/tests/muc_SUITE.erl | 24 ------------------------ 2 files changed, 48 deletions(-) diff --git a/big_tests/tests/mam_helper.erl b/big_tests/tests/mam_helper.erl index 489c68aea4c..b98d07d8633 100644 --- a/big_tests/tests/mam_helper.erl +++ b/big_tests/tests/mam_helper.erl @@ -541,30 +541,6 @@ get_received_msgs_ids(Response) -> Parsed#forwarded_message.result_id end, Msgs). -%% @doc Result query iq. -%% -%% [{xmlel,<<"iq">>, -%% [{<<"from">>,<<"alice@localhost">>}, -%% {<<"to">>,<<"alice@localhost/res1">>}, -%% {<<"id">>,<<"387862024ce65379b049e19751e4309e">>}, -%% {<<"type">>,<<"result">>}], -%% []}] -%% -%% -%% [{xmlel,<<"iq">>, -%% [{<<"from">>,<<"alice@localhost">>}, -%% {<<"to">>,<<"alice@localhost/res1">>}, -%% {<<"id">>,<<"c256a18c4b720465e215a81362d41eb7">>}, -%% {<<"type">>,<<"result">>}], -%% [{xmlel,<<"query">>, -%% [{<<"xmlns">>,<<"urn:xmpp:mam:tmp">>}], -%% [{xmlel,<<"set">>, -%% [{<<"xmlns">>,<<"http://jabber.org/protocol/rsm">>}], -%% [{xmlel,<<"first">>, -%% [{<<"index">>,<<"10">>}], -%% [{xmlcdata,<<"103439">>}]}, -%% {xmlel,<<"last">>,[],[{xmlcdata,<<"103447">>}]}, -%% {xmlel,<<"count">>,[],[{xmlcdata,<<"15">>}]}]}]}]}] parse_result_iq(#mam_archive_respond{respond_iq = IQ, respond_fin = undefined}) -> Fin = exml_query:subelement(IQ, <<"fin">>), Set = exml_query:subelement(Fin, <<"set">>), diff --git a/big_tests/tests/muc_SUITE.erl b/big_tests/tests/muc_SUITE.erl index b9dc185cb1d..28a8fcd5c9a 100644 --- a/big_tests/tests/muc_SUITE.erl +++ b/big_tests/tests/muc_SUITE.erl @@ -5374,30 +5374,6 @@ has_muc(#xmlel{children = [ #xmlel{children = Services} ]}) -> %% %% - %% is like this: - %% {xmlel,<<"iq">>, - %% [{<<"from">>,<<"localhost">>}, - %% {<<"to">>,<<"alice@localhost/res1">>}, - %% {<<"id">>,<<"a5eb1dc70826598893b15f1936b18a34">>}, - %% {<<"type">>,<<"result">>}], - %% [{xmlel,<<"query">>, - %% [{<<"xmlns">>, - %% <<"http://jabber.org/protocol/disco#items">>}], - %% [{xmlel,<<"item">>, - %% [{<<"jid">>,<<"vjud.localhost">>}], - %% []}, - %% {xmlel,<<"item">>, - %% [{<<"jid">>,<<"pubsub.localhost">>}], - %% []}, - %% {xmlel,<<"item">>, - %% [{<<"jid">>,<<"muc.localhost">>}], - %% []}, - %% {xmlel,<<"item">>, - %% [{<<"jid">>,<<"irc.localhost">>}], - %% []}]}]} - %% how to obtaing output like the above? simply put this in the test case: - %% S = escalus:wait_for_stanza(Alice), - %% error_logger:info_msg("~p~n", [S]), IsMUC = fun(Item) -> exml_query:attr(Item, <<"jid">>) == muc_host() end, From ae6f449a743c2402f75d477979a155fb96e6deac Mon Sep 17 00:00:00 2001 From: Denys Gonchar Date: Fri, 24 Jan 2025 03:18:37 +0100 Subject: [PATCH 4/6] cleaning up auth_tokens_SUITE --- test/auth_tokens_SUITE.erl | 156 +++++++++++++++---------------------- 1 file changed, 63 insertions(+), 93 deletions(-) diff --git a/test/auth_tokens_SUITE.erl b/test/auth_tokens_SUITE.erl index 328505479d8..236377e4bf7 100644 --- a/test/auth_tokens_SUITE.erl +++ b/test/auth_tokens_SUITE.erl @@ -50,7 +50,7 @@ end_per_suite(Config) -> mongoose_config:erase_opts(). opts() -> - #{{modules, host_type()} => #{?TESTED => config_parser_helper:default_mod_config(?TESTED)}, + #{{modules, host_type()} => #{mod_auth_token => config_parser_helper:default_mod_config(mod_auth_token)}, instrumentation => config_parser_helper:default_config([instrumentation])}. init_per_testcase(Test, Config) @@ -110,21 +110,11 @@ validation_test(Config) -> validation_test(_, ExampleToken) -> %% given - Serialized = ?TESTED:serialize(ExampleToken), + Serialized = mod_auth_token:serialize(ExampleToken), ct:pal("ExampleToken:~n ~p", [ExampleToken]), - %% note that mod_auth_token:deserialize/1 recomputes token_body. - %% therefore the supplied MAC signature (which is part of the serialized data) - %% may become invalid if the vcard xml binary data changes after running - %% exml:parse/1 and exml:to_binary/1 on it. - DeserialisedToken = ?TESTED:deserialize(Serialized), - ct:pal("DeserialisedToken:~n ~p", [DeserialisedToken]), - TokenWithMac = ?TESTED:token_with_mac(host_type(), - DeserialisedToken#token{ - mac_signature = undefined, - token_body = undefined}), - ct:pal("TokenWithMac:~n ~p", [TokenWithMac]), + %% when - Result = ?TESTED:authenticate(host_type(), Serialized), + Result = mod_auth_token:authenticate(host_type(), Serialized), ct:pal("Result: ~p", [Result]), %% then @@ -136,11 +126,11 @@ validation_property(_) -> validity_period_test(_) -> %% given - ok = ?TESTED:start(host_type(), mongoose_config:get_opt([{modules, host_type()}, ?TESTED])), + ok = mod_auth_token:start(host_type(), mongoose_config:get_opt([{modules, host_type()}, mod_auth_token])), UTCSeconds = utc_now_as_seconds(), ExpectedSeconds = UTCSeconds + 3600, %% seconds per hour %% when - ActualDT = ?TESTED:expiry_datetime(host_type(), access, UTCSeconds), + ActualDT = mod_auth_token:expiry_datetime(host_type(), access, UTCSeconds), %% then ?ae(calendar:gregorian_seconds_to_datetime(ExpectedSeconds), ActualDT). @@ -148,9 +138,9 @@ choose_key_by_token_type(_) -> %% given mocked keystore (see init_per_testcase) %% when mod_auth_token asks for key for given token type %% then the correct key is returned - ?ae(<<"access_or_refresh">>, ?TESTED:get_key_for_host_type(host_type(), access)), - ?ae(<<"access_or_refresh">>, ?TESTED:get_key_for_host_type(host_type(), refresh)), - ?ae(<<"provision">>, ?TESTED:get_key_for_host_type(host_type(), provision)). + ?ae(<<"access_or_refresh">>, mod_auth_token:get_key_for_host_type(host_type(), access)), + ?ae(<<"access_or_refresh">>, mod_auth_token:get_key_for_host_type(host_type(), refresh)), + ?ae(<<"provision">>, mod_auth_token:get_key_for_host_type(host_type(), provision)). is_join_and_split_with_base16_and_zeros_reversible(RawToken) -> MAC = binary:encode_hex(crypto:mac(hmac, sha384, <<"unused_key">>, RawToken), lowercase), @@ -165,11 +155,11 @@ is_join_and_split_with_base16_and_zeros_reversible(RawToken) -> end. is_serialization_reversible(Token) -> - Token =:= ?TESTED:deserialize(?TESTED:serialize(Token)). + Token =:= mod_auth_token:deserialize(mod_auth_token:serialize(Token)). is_valid_token_prop(Token) -> - Serialized = ?TESTED:serialize(Token), - R = ?TESTED:authenticate(host_type(), Serialized), + Serialized = mod_auth_token:serialize(Token), + R = mod_auth_token:authenticate(host_type(), Serialized), case is_validation_success(R) of true -> true; _ -> ct:fail(R) @@ -188,12 +178,12 @@ revoked_token_is_not_valid(_) -> RevokedSeqNo = 123455, self() ! {valid_seq_no, ValidSeqNo}, T = #token{type = refresh, - expiry_datetime = ?TESTED:seconds_to_datetime(utc_now_as_seconds() + 10), + expiry_datetime = mod_auth_token:seconds_to_datetime(utc_now_as_seconds() + 10), user_jid = jid:from_binary(<<"alice@localhost">>), sequence_no = RevokedSeqNo}, - Revoked = ?TESTED:serialize(?TESTED:token_with_mac(host_type(), T)), + Revoked = mod_auth_token:serialize(mod_auth_token:token_with_mac(host_type(), T)), %% when - ValidationResult = ?TESTED:authenticate(host_type(), Revoked), + ValidationResult = mod_auth_token:authenticate(host_type(), Revoked), %% then {error, _} = ValidationResult. @@ -245,73 +235,53 @@ mock_tested_backend() -> end). provision_token_example() -> - #token{ - type = provision, - expiry_datetime = {{2055,10,27},{10,54,22}}, - user_jid = jid:make(<<"cee2m1s0i">>,domain(),<<>>), - sequence_no = undefined, - vcard = #xmlel{ - name = <<"vCard">>, - attrs = #{<<"sgzldnl">> => <<"inxdutpu">>, - <<"scmgsrfi">> => <<"nhgybwu">>, - <<"ixrsmzee">> => <<"rysdh">>, - <<"oxwothgyei">> => <<"wderkfgexv">>}, - children = [ - #xmlel{ - name = <<"nqe">>, - attrs = #{<<"i">> => <<"u">>, - <<"gagnixjgml">> => <<"odaorofnra">>, - <<"ijz">> => <<"zvbrqnybi">>}, - children = [ - #xmlcdata{content = <<"uprmzqf">>}, - #xmlel{name = <<"lnnitxm">>, - attrs = #{<<"qytehi">> => <<"axl">>, - <<"xaxforb">> => <<"jrdeydsqhj">>}}, - #xmlcdata{content = <<"pncgsaxl">>}, - #xmlel{name = <<"jfofazuau">>, - attrs = #{<<"si">> => <<"l">>}} - ]}, - #xmlel{name = <<"moy">>, - attrs = #{<<"femjc">> => <<"qqb">>, - <<"tirfmekvpk">> => <<"sa">>}}, - #xmlcdata{content = <<"bgxlyqdeeuo">>} - ]}, - mac_signature = <<96,213,61,178,182,8,167,202,120,67,82,228,108,171,74,98,88,236, - 200,77,44,151,199,213,43,193,109,139,197,14,179,107,72,243,50, - 199,208,14,254,218,47,164,249,1,212,167,90,218>>, - token_body = <<112,114,111,118,105,115,105,111,110,0,99,101,101,50,109,49, - 115,48,105,64,108,111,99,97,108,104,111,115,116,0,54,52,56, - 55,53,52,54,54,52,54,50,0,60,118,67,97,114,100,32,105,120, - 114,115,109,122,101,101,61,39,114,121,115,100,104,39,32,111, - 120,119,111,116,104,103,121,101,105,61,39,119,100,101,114, - 107,102,103,101,120,118,39,32,115,99,109,103,115,114,102,105, - 61,39,110,104,103,121,98,119,117,39,32,115,103,122,108,100, - 110,108,61,39,105,110,120,100,117,116,112,117,39,62,60,110, - 113,101,32,103,97,103,110,105,120,106,103,109,108,61,39,111, - 100,97,111,114,111,102,110,114,97,39,32,105,61,39,117,39,32, - 105,106,122,61,39,122,118,98,114,113,110,121,98,105,39,62, - 117,112,114,109,122,113,102,60,108,110,110,105,116,120,109, - 32,113,121,116,101,104,105,61,39,97,120,108,39,32,120,97,120, - 102,111,114,98,61,39,106,114,100,101,121,100,115,113,104,106, - 39,47,62,112,110,99,103,115,97,120,108,60,106,102,111,102,97, - 122,117,97,117,32,115,105,61,39,108,39,47,62,60,47,110,113, - 101,62,60,109,111,121,32,102,101,109,106,99,61,39,113,113,98, - 39,32,116,105,114,102,109,101,107,118,112,107,61,39,115,97, - 39,47,62,98,103,120,108,121,113,100,101,101,117,111,60,47, - 118,67,97,114,100,62>>}. + Token = + #token{ + type = provision, + expiry_datetime = {{2055,10,27},{10,54,22}}, + user_jid = jid:make(<<"cee2m1s0i">>,domain(),<<>>), + sequence_no = undefined, + vcard = #xmlel{ + name = <<"vCard">>, + attrs = #{<<"sgzldnl">> => <<"inxdutpu">>, + <<"scmgsrfi">> => <<"nhgybwu">>, + <<"ixrsmzee">> => <<"rysdh">>, + <<"oxwothgyei">> => <<"wderkfgexv">>}, + children = [ + #xmlel{ + name = <<"nqe">>, + attrs = #{<<"i">> => <<"u">>, + <<"gagnixjgml">> => <<"odaorofnra">>, + <<"ijz">> => <<"zvbrqnybi">>}, + children = [ + #xmlcdata{content = <<"uprmzqf">>}, + #xmlel{name = <<"lnnitxm">>, + attrs = #{<<"qytehi">> => <<"axl">>, + <<"xaxforb">> => <<"jrdeydsqhj">>}}, + #xmlcdata{content = <<"pncgsaxl">>}, + #xmlel{name = <<"jfofazuau">>, + attrs = #{<<"si">> => <<"l">>}} + ]}, + #xmlel{name = <<"moy">>, + attrs = #{<<"femjc">> => <<"qqb">>, + <<"tirfmekvpk">> => <<"sa">>}}, + #xmlcdata{content = <<"bgxlyqdeeuo">>} + ]}, + mac_signature = undefined, + token_body = undefined}, + mod_auth_token:token_with_mac(host_type(), Token). refresh_token_example() -> - #token{ - type = refresh, - expiry_datetime = {{2055,10,27},{10,54,14}}, - user_jid = jid:make(<<"a">>,domain(),<<>>), - sequence_no = 4, - vcard = undefined, - mac_signature = <<151,225,117,181,0,168,228,208,238,182,157,253,24,200,231,25,189, - 160,176,144,85,193,20,108,31,23,46,35,215,41,250,57,68,201,45,33, - 241,219,197,83,155,118,217,92,172,42,8,118>>, - token_body = <<114,101,102,114,101,115,104,0,97,64,108,111,99,97,108,104,111,115, - 116,0,54,52,56,55,53,52,54,54,52,53,52,0,52>>}. + Token = + #token{ + type = refresh, + expiry_datetime = {{2055,10,27},{10,54,14}}, + user_jid = jid:make(<<"a">>,domain(),<<>>), + sequence_no = 4, + vcard = undefined, + mac_signature = undefined, + token_body = undefined}, + mod_auth_token:token_with_mac(host_type(), Token). %% %% Generators @@ -343,11 +313,11 @@ make_token({Type, Expiry, JID, SeqNo, VCard}) -> user_jid = jid:from_binary(JID)}, case Type of access -> - ?TESTED:token_with_mac(host_type(), T); + mod_auth_token:token_with_mac(host_type(), T); refresh -> - ?TESTED:token_with_mac(host_type(), T#token{sequence_no = SeqNo}); + mod_auth_token:token_with_mac(host_type(), T#token{sequence_no = SeqNo}); provision -> - ?TESTED:token_with_mac(host_type(), T#token{vcard = VCard}) + mod_auth_token:token_with_mac(host_type(), T#token{vcard = VCard}) end. serialized_token(Sep) -> From 6a3f1c4df2a5b88734e93a81efabfb942143fcb8 Mon Sep 17 00:00:00 2001 From: Denys Gonchar Date: Fri, 24 Jan 2025 13:59:28 +0100 Subject: [PATCH 5/6] adding maybe_skip condition for easy_archive_request_old_xmlel_format test case + adding cassandra_eterm configuration for mam suite --- big_tests/tests/mam_SUITE.erl | 44 ++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/big_tests/tests/mam_SUITE.erl b/big_tests/tests/mam_SUITE.erl index 57ab9bcd000..1d244622ebb 100644 --- a/big_tests/tests/mam_SUITE.erl +++ b/big_tests/tests/mam_SUITE.erl @@ -183,7 +183,8 @@ rdbms_configs(_, _) -> []. cassandra_configs(true) -> - [cassandra]; + [cassandra, + cassandra_eterm]; cassandra_configs(_) -> []. @@ -649,6 +650,8 @@ do_init_per_group(C, ConfigIn) -> case C of cassandra -> [{archive_wait, 1500} | Config0]; + cassandra_eterm -> + [{archive_wait, 1500} | Config0]; elasticsearch -> [{archive_wait, 2500} | Config0]; _ -> @@ -658,7 +661,8 @@ do_init_per_group(C, ConfigIn) -> setup_meck(_, elasticsearch) -> ok = rpc(mim(), meck, expect, [mongoose_elasticsearch, insert_document, 4, {error, simulated}]); -setup_meck(_, cassandra) -> +setup_meck(_, Config) when Config =:= cassandra_eterm; + Config =:= cassandra -> ok = rpc(mim(), meck, expect, [mongoose_cassandra, cql_write_async, 5, {error, simulated}]); setup_meck(drop_msg, Config) when Config =:= rdbms_async_pool; @@ -754,21 +758,15 @@ maybe_set_wait(C, Types, Config) when C =:= rdbms_async_pool; maybe_set_wait(_C, _, Config) -> Config. -mam_prefs_backend_module(rdbms, rdbms) -> - mod_mam_rdbms_prefs; -mam_prefs_backend_module(cassandra, cassandra) -> - mod_mam_cassandra_prefs; -mam_prefs_backend_module(_, mnesia) -> - mod_mam_mnesia_prefs; -mam_prefs_backend_module(_, _) -> - {error, wrong_db}. - mam_opts_for_conf(elasticsearch) -> #{backend => elasticsearch, user_prefs_store => mnesia}; mam_opts_for_conf(cassandra) -> #{backend => cassandra, user_prefs_store => cassandra}; +mam_opts_for_conf(cassandra_eterm) -> + Opts = mam_opts_for_conf(cassandra), + Opts#{db_message_format => mam_message_eterm}; mam_opts_for_conf(rdbms_easy) -> EasyOpts = #{db_jid_format => mam_jid_rfc, db_message_format => mam_message_xml}, @@ -882,24 +880,37 @@ maybe_skip(C, Config) when C =:= muc_light_failed_to_decode_message_in_database; "elasticsearch does not support encodings"); maybe_skip(C, Config) when C =:= muc_light_sql_query_failed; C =:= pm_sql_query_failed -> - skip_if(?config(configuration, Config) =:= elasticsearch orelse - ?config(configuration, Config) =:= cassandra, + Configuration = ?config(configuration, Config), + skip_if(lists:member(Configuration, [elasticsearch, cassandra, cassandra_eterm]), "Not an SQL database"); maybe_skip(C, Config) when C =:= muc_light_include_groupchat_filter; C =:= muc_light_no_pm_stored_include_groupchat_filter; C =:= muc_light_include_groupchat_messages_by_default -> - skip_if(?config(configuration, Config) =:= cassandra, + Configuration = ?config(configuration, Config), + skip_if(lists:member(Configuration, [cassandra, cassandra_eterm]), "include_groupchat field is not supported for cassandra backend"); maybe_skip(C, Config) when C =:= easy_text_search_request; C =:= long_text_search_request; C =:= save_unicode_messages; C =:= muc_text_search_request -> - skip_if(?config(configuration, Config) =:= cassandra, + Configuration = ?config(configuration, Config), + skip_if(lists:member(Configuration, [cassandra, cassandra_eterm]), "full text search is not implemented for cassandra backend"); maybe_skip(C, Config) when C =:= muc_light_async_pools_batch_flush; C =:= async_pools_batch_flush -> skip_if(?config(configuration, Config) =/= rdbms_async_pool, "only for async pool"); +maybe_skip(C, Config) when C =:= easy_archive_request_old_xmlel_format -> + MamOpts = ?config(mam_meta_opts, Config), + MamBackend = maps:get(backend, MamOpts, rdbms), + DefaultFormat = case MamBackend of + rdbms -> mam_message_compressed_eterm; + _ -> mam_message_xml + end, + MessageFormat = maps:get(db_message_format, MamOpts, DefaultFormat), + PmMamOpts = maps:get(pm, MamOpts, #{}), + PmMessageFormat = maps:get(db_message_format, PmMamOpts, MessageFormat), + skip_if(PmMessageFormat =:= mam_message_xml, "run only for eterm PM message format"); maybe_skip(_C, _Config) -> ok. @@ -4143,7 +4154,8 @@ message_retraction_is_enabled(Config) -> BasicGroup = ?config(basic_group, Config), BasicGroup =/= disabled_retraction andalso BasicGroup =/= muc_disabled_retraction. -check_include_groupchat_features(Stanza, cassandra, _BasicGroup) -> +check_include_groupchat_features(Stanza, Config, _BasicGroup) when Config =:= cassandra_eterm; + Config =:= cassandra -> ?assertNot(escalus_pred:has_feature(groupchat_field_ns(), Stanza)), ?assertNot(escalus_pred:has_feature(groupchat_available_ns(), Stanza)); check_include_groupchat_features(Stanza, _Configuration, muc_light) -> From 9b219493fb385aadefa365d07ed5a256f187aafe Mon Sep 17 00:00:00 2001 From: Denys Gonchar Date: Tue, 28 Jan 2025 14:14:23 +0100 Subject: [PATCH 6/6] addressing code review comments --- big_tests/tests/mam_SUITE.erl | 10 +++++----- test/auth_tokens_SUITE.erl | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/big_tests/tests/mam_SUITE.erl b/big_tests/tests/mam_SUITE.erl index 1d244622ebb..0a1941d219f 100644 --- a/big_tests/tests/mam_SUITE.erl +++ b/big_tests/tests/mam_SUITE.erl @@ -639,7 +639,7 @@ init_per_group(Group, ConfigIn) -> C = configuration(Group), B = basic_group(Group), {ModulesToStart, Config0} = required_modules_for_group(C, B, ConfigIn), - ct:pal("Init per group ~p; configuration ~p; basic group ~p", [Group, C, B]), + ct:log("Init per group ~p; configuration ~p; basic group ~p", [Group, C, B]), Config01 = dynamic_modules:save_modules(host_type(), Config0), dynamic_modules:ensure_modules(host_type(), ModulesToStart), Config1 = do_init_per_group(C, Config01), @@ -1290,8 +1290,8 @@ easy_archive_request_old_xmlel_format(Config) -> [{xmlel,<<"body">>,[],[{xmlcdata,<<"OH, HAI!">>}]}]}, Msg1 = erlang:setelement(5, Msg, OldFormatPacket), - ct:pal("Packet: ~p~n", [Packet]), - ct:pal("OldFormatPacket: ~p~n", [OldFormatPacket]), + ct:log("Packet: ~p~n", [Packet]), + ct:log("OldFormatPacket: ~p~n", [OldFormatPacket]), mam_helper:put_msg(Msg1), mam_helper:wait_for_archive_size(Alice, 1), escalus:send(Alice, stanza_archive_request(P, <<"q1">>)), @@ -1300,12 +1300,12 @@ easy_archive_request_old_xmlel_format(Config) -> assert_respond_size(1, Res), assert_respond_query_id(P, <<"q1">>, parse_result_iq(Res)), [RespMessage] = respond_messages(Res), - ct:pal("ResPacket: ~p~n", [RespMessage]), + ct:log("ResPacket: ~p~n", [RespMessage]), ArchivedMsg = exml_query:path(RespMessage, [{element, <<"result">>}, {element, <<"forwarded">>}, {element, <<"message">>}]), - ct:pal("ArchivedMsg: ~p~n", [ArchivedMsg]), + ct:log("ArchivedMsg: ~p~n", [ArchivedMsg]), assert_msg_match(Packet, ArchivedMsg), ok end, diff --git a/test/auth_tokens_SUITE.erl b/test/auth_tokens_SUITE.erl index 236377e4bf7..3c774f136f5 100644 --- a/test/auth_tokens_SUITE.erl +++ b/test/auth_tokens_SUITE.erl @@ -111,11 +111,11 @@ validation_test(Config) -> validation_test(_, ExampleToken) -> %% given Serialized = mod_auth_token:serialize(ExampleToken), - ct:pal("ExampleToken:~n ~p", [ExampleToken]), + ct:log("ExampleToken:~n ~p", [ExampleToken]), %% when Result = mod_auth_token:authenticate(host_type(), Serialized), - ct:pal("Result: ~p", [Result]), + ct:log("Result: ~p", [Result]), %% then ?ae(true, is_validation_success(Result)).