Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Carbons upgrade to 0.13.2 #3125

Merged
merged 13 commits into from
May 21, 2021
149 changes: 70 additions & 79 deletions big_tests/tests/carboncopy_SUITE.erl
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
-module(carboncopy_SUITE).


-compile([export_all]).
-include_lib("common_test/include/ct.hrl").
-include_lib("proper/include/proper.hrl").
-include_lib("eunit/include/eunit.hrl").

-define(AE(Expected, Actual), ?assertEqual(Expected, Actual)).
-define(BODY, <<"And pious action">>).

all() -> [{group, all}].
-import(mongoose_helper, [enable_carbons/1, disable_carbons/1]).

all() ->
[{group, all}].

groups() ->
G = [{all, [parallel, shuffle],
G = [{all, [parallel],
[discovering_support,
enabling_carbons,
disabling_carbons,
Expand All @@ -28,76 +30,84 @@ groups() ->
]}],
ct_helper:repeat_all_until_all_ok(G).

init_per_suite(C) -> escalus:init_per_suite(C).
end_per_suite(C) -> escalus_fresh:clean(), escalus:end_per_suite(C).
init_per_testcase(Name, C) -> escalus:init_per_testcase(Name, C).
end_per_testcase(Name, C) -> escalus:end_per_testcase(Name, C).
run_prop(PropName, Property) ->
?AE(true, proper:quickcheck(proper:conjunction([{PropName, Property}]),
[verbose, long_result, {numtests, 3}])).
%%%===================================================================
%%% Overall setup/teardown
%%%===================================================================
init_per_suite(C) ->
escalus:init_per_suite(C).

end_per_suite(C) ->
escalus_fresh:clean(),
escalus:end_per_suite(C).

%%%===================================================================
%%% Testcase specific setup/teardown
%%%===================================================================
init_per_testcase(Name, C) ->
escalus:init_per_testcase(Name, C).

end_per_testcase(Name, C) ->
escalus:end_per_testcase(Name, C).

%%%===================================================================
%%% Individual Test Cases (from groups() definition)
%%%===================================================================
discovering_support(Config) ->
escalus:fresh_story(
Config, [{alice, 1}],
fun(Alice) ->
IqGet = escalus_stanza:disco_info(ct:get_config({hosts,
mim, domain})),
IqGet = escalus_stanza:disco_info(ct:get_config({hosts, mim, domain})),
escalus_client:send(Alice, IqGet),
Result = escalus_client:wait_for_stanza(Alice),
escalus:assert(is_iq_result, [IqGet], Result),
escalus:assert(has_feature, [<<"urn:xmpp:carbons:2">>], Result)
end).

enabling_carbons(Config) ->
escalus:fresh_story(Config, [{alice, 1}], fun carbons_get_enabled/1).
escalus:fresh_story(Config, [{alice, 1}], fun mongoose_helper:enable_carbons/1).

disabling_carbons(Config) ->
escalus:fresh_story(Config, [{alice, 1}],
fun(Alice) -> carbons_get_enabled(Alice),
carbons_get_disabled(Alice) end).
fun(Alice) -> enable_carbons(Alice),
disable_carbons(Alice) end).

avoiding_carbons(Config) ->
escalus:fresh_story(
Config, [{alice, 2}, {bob, 1}],
fun(Alice1, Alice2, Bob) ->
carbons_get_enabled([Alice1, Alice2]),
Msg = escalus_stanza:chat_without_carbon_to(Bob,
<<"And pious action">>),
enable_carbons([Alice1, Alice2]),
Msg = escalus_stanza:chat_without_carbon_to(Bob, ?BODY),
escalus_client:send(Alice1, Msg),
escalus:assert(
is_chat_message, [<<"And pious action">>],
escalus_client:wait_for_stanza(Bob)),
escalus_client:wait_for_stanzas(Alice2, 1),
[] = escalus_client:peek_stanzas(Alice2)
BobReceived = escalus_client:wait_for_stanza(Bob),
escalus:assert(is_chat_message, [?BODY], BobReceived),
?assertEqual([], escalus_client:wait_for_stanzas(Alice2, 1, 500)),
?assertEqual([], escalus_client:peek_stanzas(Alice2))
end).

non_enabled_clients_dont_get_sent_carbons(Config) ->
escalus:fresh_story(
Config, [{alice, 2}, {bob, 1}],
fun(Alice1, Alice2, Bob) ->
Msg = escalus_stanza:chat_to(Bob, <<"And pious action">>),
Msg = escalus_stanza:chat_to(Bob, ?BODY),
escalus_client:send(Alice1, Msg),
escalus:assert(
is_chat_message, [<<"And pious action">>],
escalus_client:wait_for_stanza(Bob)),
escalus_client:wait_for_stanzas(Alice2, 1),
[] = escalus_client:peek_stanzas(Alice2)
BobReceived = escalus_client:wait_for_stanza(Bob),
escalus:assert(is_chat_message, [?BODY], BobReceived),
?assertEqual([], escalus_client:wait_for_stanzas(Alice2, 1, 500)),
?assertEqual([], escalus_client:peek_stanzas(Alice2))
end).

non_enabled_clients_dont_get_received_carbons(Config) ->
escalus:fresh_story(
Config, [{alice, 2}, {bob, 1}],
fun(Alice1, Alice2, Bob) ->
Msg = escalus_stanza:chat_to(Alice1, <<"And pious action">>),
Msg = escalus_stanza:chat_to(Alice1, ?BODY),
escalus_client:send(Bob, Msg),
escalus:assert(
is_chat_message, [<<"And pious action">>],
escalus_client:wait_for_stanza(Alice1)),
escalus_client:wait_for_stanzas(Alice2, 1),
[] = escalus_client:peek_stanzas(Alice2)
AliceReceived = escalus_client:wait_for_stanza(Alice1),
escalus:assert(is_chat_message, [?BODY], AliceReceived),
?assertEqual([], escalus_client:wait_for_stanzas(Alice2, 1, 500)),
?assertEqual([], escalus_client:peek_stanzas(Alice2))
end).


enabled_single_resource_doesnt_get_carbons(Config) ->
BobsMessages = [
<<"There's such a thing as dwelling">>,
Expand All @@ -108,7 +118,7 @@ enabled_single_resource_doesnt_get_carbons(Config) ->
escalus:fresh_story(
Config, [{alice, 1}, {bob, 1}],
fun(Alice, Bob) ->
carbons_get_enabled(Alice),
enable_carbons(Alice),
[ escalus_client:send(Bob, escalus_stanza:chat_to(Alice, M))
|| M <- BobsMessages ],
[ escalus:assert(is_chat_message, [M], escalus_client:wait_for_stanza(Alice))
Expand All @@ -119,38 +129,33 @@ unavailable_resources_dont_get_carbons(Config) ->
escalus:fresh_story(
Config, [{alice, 2}, {bob, 1}],
fun(Alice1, Alice2, Bob) ->
carbons_get_enabled(Alice1),
carbons_get_enabled(Alice2),
enable_carbons([Alice1, Alice2]),
client_unsets_presence(Alice1),
escalus:assert(is_presence_with_type, [<<"unavailable">>],
escalus_client:wait_for_stanza(Alice2)),

escalus_client:send(Bob, escalus_stanza:chat_to(Alice2, <<"one">>)),
escalus_client:send(Bob, escalus_stanza:chat_to(Alice2, ?BODY)),

client_sets_presence(Alice1),
%% no carbons for Alice1, only presences
escalus_new_assert:mix_match([is_presence, is_presence],
escalus:wait_for_stanzas(Alice1, 2))
escalus:wait_for_stanzas(Alice1, 2)),
AliceReceived = escalus_client:wait_for_stanza(Alice2),
escalus:assert(is_chat_message, [?BODY], AliceReceived)
end).

client_unsets_presence(Client) ->
escalus_client:send(Client, escalus_stanza:presence(<<"unavailable">>)).

client_sets_presence(Client) ->
escalus_client:send(Client, escalus_stanza:presence(<<"available">>)).

dropped_client_doesnt_create_duplicate_carbons(Config) ->
escalus:fresh_story(
Config, [{alice, 2}, {bob, 1}],
fun(Alice1, Alice2, Bob) ->
Msg = escalus_stanza:chat_to(Bob, <<"And pious action">>),
enable_carbons([Alice1, Alice2]),
Msg = escalus_stanza:chat_to(Bob, ?BODY),
escalus_client:stop(Config, Alice2),
escalus:assert(is_presence_with_type, [<<"unavailable">>],
escalus_client:wait_for_stanza(Alice1)),
escalus_client:wait_for_stanza(Alice1)),
escalus_client:send(Alice1, Msg),
escalus:assert(
is_chat_message, [<<"And pious action">>],
escalus_client:wait_for_stanza(Bob)),
escalus:assert(is_chat_message, [?BODY],
escalus_client:wait_for_stanza(Bob)),
[] = escalus_client:peek_stanzas(Alice1)
end).

Expand Down Expand Up @@ -188,15 +193,14 @@ prop_normal_routing_to_bare_jid(Config) ->
end))).



%%
%% Test scenarios w/assertions
%%

all_bobs_resources_get_message_to_bare_jid([Alice, Bob1 | Bobs], Msg) ->
%% All connected resources receive messages sent
%% to the user's bare JID without carbon wrappers.
carbons_get_enabled([Bob1|Bobs]),
enable_carbons([Bob1|Bobs]),
escalus_client:send(
Alice, escalus_stanza:chat_to(escalus_client:short_jid(Bob1), Msg)),
GotMsg = fun(BobsResource) ->
Expand All @@ -209,8 +213,9 @@ all_bobs_resources_get_message_to_bare_jid([Alice, Bob1 | Bobs], Msg) ->
lists:foreach(GotMsg, [Bob1|Bobs]).

all_bobs_other_resources_get_received_carbons([Alice, Bob1 | Bobs], Msg) ->
carbons_get_enabled([Bob1|Bobs]),
enable_carbons([Bob1|Bobs]),
escalus_client:send(Alice, escalus_stanza:chat_to(Bob1, Msg)),
escalus_client:wait_for_stanza(Bob1),
GotForward = fun(BobsResource) ->
escalus:assert(
is_forwarded_received_message,
Expand All @@ -222,7 +227,7 @@ all_bobs_other_resources_get_received_carbons([Alice, Bob1 | Bobs], Msg) ->
lists:foreach(GotForward, Bobs).

all_bobs_other_resources_get_sent_carbons([Alice, Bob1 | Bobs], Msg) ->
carbons_get_enabled([Bob1|Bobs]),
enable_carbons([Bob1|Bobs]),
escalus_client:send(Bob1, escalus_stanza:chat_to(Alice, Msg)),
escalus:assert(is_chat_message, [Msg], escalus_client:wait_for_stanza(Alice)),
GotCarbon = fun(BobsResource) ->
Expand All @@ -235,26 +240,19 @@ all_bobs_other_resources_get_sent_carbons([Alice, Bob1 | Bobs], Msg) ->
escalus_assert:has_no_stanzas(BobsResource) end,
lists:foreach(GotCarbon, Bobs).

carbons_get_disabled(ClientOrClients) ->
disable_carbons(ClientOrClients).

carbons_get_enabled(ClientOrClients) ->
enable_carbons(ClientOrClients).


%%
%% Internal helpers
%%

%% Wrapper around escalus:story. Returns PropEr result.
true_story(Config, UserSpecs, TestFun) ->
try escalus_fresh:story_with_client_list(Config, UserSpecs, TestFun), true
try escalus_fresh:story_with_client_list(Config, UserSpecs, TestFun), true
catch E ->
{error, E}
end.

%% Number of resources per users
no_of_resources() -> rand:uniform(4).
no_of_resources() -> 1 + rand:uniform(4).
chrzaszcz marked this conversation as resolved.
Show resolved Hide resolved

%% A sample chat message
utterance() ->
Expand All @@ -267,19 +265,12 @@ utterance() ->
<<"Long withering out a young man revenue.">>]).


enable_carbons(Clients) when is_list(Clients) ->
lists:foreach(fun enable_carbons/1, Clients);
enable_carbons(Client) ->
IqSet = escalus_stanza:carbons_enable(),
escalus_client:send(Client, IqSet),
Result = escalus_client:wait_for_stanza(Client),
escalus:assert(is_iq, [<<"result">>], Result).
client_unsets_presence(Client) ->
escalus_client:send(Client, escalus_stanza:presence(<<"unavailable">>)).

client_sets_presence(Client) ->
escalus_client:send(Client, escalus_stanza:presence(<<"available">>)).

disable_carbons(Clients) when is_list(Clients) ->
lists:foreach(fun disable_carbons/1, Clients);
disable_carbons(Client) ->
IqSet = escalus_stanza:carbons_disable(),
escalus_client:send(Client, IqSet),
Result = escalus_client:wait_for_stanza(Client),
escalus:assert(is_iq, [<<"result">>], Result).
run_prop(PropName, Property) ->
?AE(true, proper:quickcheck(proper:conjunction([{PropName, Property}]),
[verbose, long_result, {numtests, 3}])).
32 changes: 30 additions & 2 deletions big_tests/tests/mam_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@
archive_chat_markers/1,
dont_archive_chat_markers/1,
save_unicode_messages/1,
unicode_messages_can_be_extracted/1]).
unicode_messages_can_be_extracted/1,
stanza_id_is_appended_to_carbons/1]).

-import(distributed_helper, [mim/0,
require_rpc_nodes/1,
Expand Down Expand Up @@ -394,7 +395,8 @@ archived_cases() ->
filter_forwarded].

stanzaid_cases() ->
[message_with_stanzaid].
[message_with_stanzaid,
stanza_id_is_appended_to_carbons].

retract_cases() ->
[retract_message,
Expand Down Expand Up @@ -1499,6 +1501,32 @@ save_unicode_messages(Config) ->
end,
escalus_fresh:story(Config, [{alice, 1}, {bob, 1}], F).

stanza_id_is_appended_to_carbons(Config) ->
F = fun(Alice1, Alice2, Bob1, Bob2) ->
Msg = <<"OH, HAI!">>,
mongoose_helper:enable_carbons([Alice1, Alice2, Bob1, Bob2]),
escalus:send(Alice1, escalus_stanza:chat_to(Bob1, Msg)),
mam_helper:wait_for_archive_size(Alice1, 1),
escalus_client:wait_for_stanza(Bob1),
Alice2CC = escalus_client:wait_for_stanza(Alice2),
Bob2CC = escalus_client:wait_for_stanza(Bob2),

SID = fun(Packet, Direction) ->
exml_query:path(Packet, [{element_with_ns, Direction, <<"urn:xmpp:carbons:2">>},
{element_with_ns, <<"forwarded">>, <<"urn:xmpp:forward:0">>},
{element_with_ns, <<"message">>, <<"jabber:client">>},
{element_with_ns, <<"stanza-id">>, <<"urn:xmpp:sid:0">>},
{attr, <<"id">>}])
end,
?assert_equal(true, undefined =/= SID(Bob2CC, <<"received">>)),
?assert_equal(true, undefined =/= SID(Alice2CC, <<"sent">>)),
escalus:assert(is_forwarded_sent_message,
[escalus_client:full_jid(Alice1), escalus_client:full_jid(Bob1), Msg], Alice2CC),
escalus:assert(is_forwarded_received_message,
[escalus_client:full_jid(Alice1), escalus_client:full_jid(Bob1), Msg], Bob2CC)
end,
escalus_fresh:story(Config, [{alice, 2}, {bob, 2}], F).

muc_text_search_request(Config) ->
P = ?config(props, Config),
F = fun(Alice, Bob) ->
Expand Down
17 changes: 17 additions & 0 deletions big_tests/tests/mongoose_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
-export([ensure_muc_clean/0]).
-export([successful_rpc/3, successful_rpc/4, successful_rpc/5]).
-export([logout_user/2, logout_user/3]).
-export([enable_carbons/1, disable_carbons/1]).
-export([wait_until/2, wait_until/3, wait_for_user/3]).

-export([inject_module/1, inject_module/2, inject_module/3]).
Expand Down Expand Up @@ -261,6 +262,22 @@ successful_rpc(#{} = Spec, Module, Function, Args, Timeout) ->
Result
end.

enable_carbons(Clients) when is_list(Clients) ->
lists:foreach(fun enable_carbons/1, Clients);
enable_carbons(Client) ->
IqSet = escalus_stanza:carbons_enable(),
escalus_client:send(Client, IqSet),
Result = escalus_client:wait_for_stanza(Client),
escalus:assert(is_iq, [<<"result">>], Result).

disable_carbons(Clients) when is_list(Clients) ->
lists:foreach(fun disable_carbons/1, Clients);
disable_carbons(Client) ->
IqSet = escalus_stanza:carbons_disable(),
escalus_client:send(Client, IqSet),
Result = escalus_client:wait_for_stanza(Client),
escalus:assert(is_iq, [<<"result">>], Result).

logout_user(Config, User) ->
Node = distributed_helper:mim(),
logout_user(Config, User, Node).
Expand Down
6 changes: 6 additions & 0 deletions include/mongoose_ns.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@
-define(NS_HTTP_UPLOAD_030, <<"urn:xmpp:http:upload:0">>).
-define(NS_PUSH, <<"urn:xmpp:push:0">>). % Push Notifications v0.2.1
-define(NS_STANZAID, <<"urn:xmpp:sid:0">>).
-define(NS_RECEIPTS, <<"urn:xmpp:receipts">>).

-define(NS_HINTS, <<"urn:xmpp:hints">>).
-define(NS_CC_RULES, <<"urn:xmpp:carbons:rules:0">>).
-define(NS_CC_2, <<"urn:xmpp:carbons:2">>).
-define(NS_CC_1, <<"urn:xmpp:carbons:1">>).

-define(NS_RSM, <<"http://jabber.org/protocol/rsm">>).
-define(NS_EJABBERD_CONFIG, <<"ejabberd:config">>).
Expand Down
Loading