Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
chrzaszcz committed Jul 4, 2024
1 parent a5b924a commit a4afca1
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 71 deletions.
5 changes: 3 additions & 2 deletions big_tests/tests/amp_big_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,9 @@ amp_test_helper_code() ->
" end.\n".

declared_events() ->
[
{mod_privacy_set, #{host_type => host_type()}} % tested by privacy helpers
[ % tested by privacy helpers
{mod_privacy_set, #{host_type => host_type()}},
{mod_privacy_get, #{host_type => host_type()}}
].

end_per_suite(C) ->
Expand Down
4 changes: 2 additions & 2 deletions big_tests/tests/graphql_roster_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ admin_list_contacts_story(Config, Alice, Bob) ->
[#{<<"subscription">> := <<"NONE">>, <<"ask">> := <<"NONE">>, <<"jid">> := BobBin,
<<"name">> := BobName, <<"groups">> := ?DEFAULT_GROUPS}] =
get_ok_value([data, roster, listContacts], Res),
roster_helper:assert_roster_event(Alice, mod_roster_get).
roster_helper:assert_roster_event(escalus_client:short_jid(Alice), mod_roster_get).

admin_list_contacts_wrong_user(Config) ->
% User with a non-existent domain
Expand Down Expand Up @@ -548,7 +548,7 @@ user_list_contacts_story(Config, Alice, Bob) ->
[#{<<"subscription">> := <<"NONE">>, <<"ask">> := <<"NONE">>, <<"jid">> := BobBin,
<<"name">> := Name, <<"groups">> := ?DEFAULT_GROUPS}] =
get_ok_value(?LIST_CONTACTS_PATH, Res),
roster_helper:assert_roster_event(Alice, mod_roster_get).
roster_helper:assert_roster_event(escalus_client:short_jid(Alice), mod_roster_get).

user_get_contact(Config) ->
escalus:fresh_story_with_config(Config, [{alice, 1}, {bob, 1}],
Expand Down
2 changes: 2 additions & 0 deletions big_tests/tests/instrument_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
-export([assert/3, assert_one/3, assert_not_emitted/3, assert_not_emitted/2, assert_not_emitted/1,
wait_and_assert/3, wait_and_assert_new/3, assert/4]).

-export([timestamp/0]).

-import(distributed_helper, [rpc/4, mim/0]).

-include_lib("eunit/include/eunit.hrl").
Expand Down
2 changes: 1 addition & 1 deletion big_tests/tests/mam_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3286,7 +3286,7 @@ prefs_set_request(Config) ->
?assert_equal(ResultIQ1, ResultIQ2),
ok
end,
escalus:story(Config, [{alice, 1}], F).
escalus:fresh_story(Config, [{alice, 1}], F).

query_get_request(Config) ->
F = fun(Alice) ->
Expand Down
38 changes: 23 additions & 15 deletions big_tests/tests/mod_blocking_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,13 @@ messages_from_blocked_user_dont_arrive(Config) ->
Config, [{alice, 1}, {bob, 1}],
fun(User1, User2) ->
user_blocks(User1, [User2]),
TS = instrument_helper:timestamp(),
message(User2, User1, <<"Hi!">>),
ct:sleep(100),
escalus_assert:has_no_stanzas(User1),
privacy_helper:gets_error(User2, <<"cancel">>, <<"service-unavailable">>),
privacy_helper:assert_privacy_check_packet_event(User2, #{dir => out}),
privacy_helper:assert_privacy_check_packet_event(User1, #{dir => in, blocked_count => 1})
privacy_helper:assert_privacy_check_packet_event(User2, #{dir => out}, TS),
privacy_helper:assert_privacy_check_packet_event(User1, #{dir => in, blocked_count => 1}, TS)
end).

messages_from_unblocked_user_arrive_again(Config) ->
Expand Down Expand Up @@ -437,10 +438,11 @@ notify_blockee(Config) ->

%%
get_blocklist(User) ->
TS = instrument_helper:timestamp(),
IQGet = get_blocklist_stanza(),
escalus_client:send(User, IQGet),
Result = escalus_client:wait_for_stanza(User),
privacy_helper:assert_privacy_get_event(User),
privacy_helper:assert_privacy_get_event(User, TS),
Result.

%%
Expand Down Expand Up @@ -589,14 +591,15 @@ get_blocklist_items(Items) ->
end, Items).

user_blocks(Blocker, Blockees) when is_list(Blockees) ->
TS = instrument_helper:timestamp(),
BlockeeJIDs = [ escalus_utils:jid_to_lower(escalus_client:short_jid(B)) || B <- Blockees ],
AddStanza = block_users_stanza(BlockeeJIDs),
escalus_client:send(Blocker, AddStanza),
Res = escalus:wait_for_stanzas(Blocker, 2),
CheckPush = fun(E) -> is_xep191_push(<<"block">>, BlockeeJIDs, E) end,
Preds = [is_iq_result, CheckPush],
escalus:assert_many(Preds, Res),
privacy_helper:assert_privacy_set_event(Blocker, #{}).
privacy_helper:assert_privacy_set_event(Blocker, #{}, TS).

blocklist_is_empty(BlockList) ->
escalus:assert(is_iq_result, BlockList),
Expand All @@ -607,19 +610,21 @@ blocklist_contains_jid(BlockList, Client) ->
escalus:assert(fun blocklist_result_has/2, [JID], BlockList).

user_unblocks(Unblocker, Unblockees) when is_list(Unblockees) ->
TS = instrument_helper:timestamp(),
UnblockeeJIDs = [ escalus_utils:jid_to_lower(escalus_client:short_jid(B)) || B <- Unblockees ],
AddStanza = unblock_users_stanza(UnblockeeJIDs),
escalus_client:send(Unblocker, AddStanza),
Res = escalus:wait_for_stanzas(Unblocker, 2),
CheckPush = fun(E) -> is_xep191_push(<<"unblock">>, UnblockeeJIDs, E) end,
Preds = [is_iq_result, CheckPush],
escalus:assert_many(Preds, Res),
privacy_helper:assert_privacy_set_event(Unblocker, #{});
privacy_helper:assert_privacy_set_event(Unblocker, #{}, TS);
user_unblocks(Unblocker, Unblockee) ->
TS = instrument_helper:timestamp(),
JID = escalus_utils:jid_to_lower(escalus_client:short_jid(Unblockee)),
escalus_client:send(Unblocker, unblock_user_stanza(JID)),
user_gets_remove_result(Unblocker, [JID]),
privacy_helper:assert_privacy_set_event(Unblocker, #{}).
privacy_helper:assert_privacy_set_event(Unblocker, #{}, TS).

blocklist_doesnt_contain_jid(BlockList, Client) ->
JID = escalus_utils:jid_to_lower(escalus_client:short_jid(Client)),
Expand All @@ -642,32 +647,35 @@ message(From, To, MsgTxt) ->

message_is_delivered(From, [To|_] = Tos, MessageText) ->
BareTo = escalus_utils:jid_to_lower(escalus_client:short_jid(To)),
TS = instrument_helper:timestamp(),
escalus:send(From, escalus_stanza:chat_to(BareTo, MessageText)),
[ escalus:assert(is_chat_message, [MessageText], escalus:wait_for_stanza(C)) ||
C <- Tos ],
privacy_helper:assert_privacy_check_packet_event(From, #{dir => out}),
privacy_helper:assert_privacy_check_packet_event(To, #{dir => in});
privacy_helper:assert_privacy_check_packet_event(From, #{dir => out}, TS),
privacy_helper:assert_privacy_check_packet_event(To, #{dir => in}, TS);
message_is_delivered(From, To, MessageText) ->
BareTo = escalus_utils:jid_to_lower(escalus_client:short_jid(To)),
TS = instrument_helper:timestamp(),
escalus:send(From, escalus_stanza:chat_to(BareTo, MessageText)),
escalus:assert(is_chat_message, [MessageText], escalus:wait_for_stanza(To)),
privacy_helper:assert_privacy_check_packet_event(From, #{dir => out}),
privacy_helper:assert_privacy_check_packet_event(To, #{dir => in}).
privacy_helper:assert_privacy_check_packet_event(From, #{dir => out}, TS),
privacy_helper:assert_privacy_check_packet_event(To, #{dir => in}, TS).

message_is_blocked_by_recipient(From, To) ->
TS = instrument_helper:timestamp(),
message_is_not_delivered(From, [To], <<"You blocked me!">>),
privacy_helper:gets_error(From, <<"cancel">>, <<"service-unavailable">>),
privacy_helper:assert_privacy_check_packet_event(From, #{dir => out}),
privacy_helper:assert_privacy_check_packet_event(To, #{dir => in, blocked_count => 1}).
privacy_helper:assert_privacy_check_packet_event(From, #{dir => out}, TS),
privacy_helper:assert_privacy_check_packet_event(To, #{dir => in, blocked_count => 1}, TS).

message_is_blocked_by_sender(From, To) ->
TS = instrument_helper:timestamp(),
message_is_not_delivered(From, [To], <<"I blocked you!">>),
client_gets_blocking_error(From),
privacy_helper:assert_privacy_check_packet_event(From, #{dir => out, blocked_count => 1}).
privacy_helper:assert_privacy_check_packet_event(From, #{dir => out, blocked_count => 1}, TS).

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)),
escalus:send(From, escalus_stanza:chat_to(To, MessageText)),
clients_have_no_messages(Tos).

clients_have_no_messages(Cs) when is_list (Cs) -> [ client_has_no_messages(C) || C <- Cs ].
Expand Down
14 changes: 7 additions & 7 deletions big_tests/tests/mod_global_distrib_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -452,13 +452,13 @@ test_two_way_pm(Alice, Eve) ->
fun(#{count := 1, time := T, jid := Jid}) ->
Jid =:= jid:to_lower(jid:from_binary(EveJid)) andalso T >= 0
end),
instrument_helper:assert_one(
instrument_helper:assert(
mod_global_distrib_outgoing_established, #{},
fun(#{count := 1, host := <<"reg1">>}) -> true end),
instrument_helper:assert(
mod_global_distrib_outgoing_queue, #{},
fun(#{time := Time, host := <<"reg1">>}) -> Time >= 0 end),
instrument_helper:assert_one(
instrument_helper:assert(
mod_global_distrib_outgoing_messages, #{},
fun(#{count := 1, host := <<"reg1">>}) -> true end).

Expand Down Expand Up @@ -509,11 +509,11 @@ test_instrumentation_events_on_one_host(Config) ->
Host = <<"localhost.bis">>,
instrument_helper:assert(mod_global_distrib_incoming_established, #{},
fun(#{count := 1, peer := _}) -> true end),
instrument_helper:assert_one(mod_global_distrib_incoming_first_packet, #{},
instrument_helper:assert(mod_global_distrib_incoming_first_packet, #{},
fun(#{count := 1, host := H}) -> H =:= Host end),
instrument_helper:assert(mod_global_distrib_incoming_transfer, #{},
fun(#{time := T, host := H}) when T >= 0 -> H =:= Host end),
instrument_helper:assert_one(mod_global_distrib_incoming_messages, #{},
instrument_helper:assert(mod_global_distrib_incoming_messages, #{},
fun(#{count := 1, host := H}) -> H =:= Host end),
instrument_helper:assert(mod_global_distrib_incoming_queue, #{},
fun(#{time := T, host := H}) when T >= 0 -> H =:= Host end),
Expand All @@ -522,7 +522,7 @@ test_instrumentation_events_on_one_host(Config) ->
escalus_client:stop(Config1, Eve),

instrument_helper:wait_and_assert(mod_global_distrib_incoming_closed, #{},
fun(#{count := 1, host := H}) -> H =:= Host end).
fun(#{count := 1, host := undefined}) -> true end).

test_muc_conversation_history(Config0) ->
AliceSpec = escalus_fresh:create_fresh_user(Config0, alice),
Expand Down Expand Up @@ -671,8 +671,8 @@ test_component_disconnect(Config) ->
escalus:send(User, escalus_stanza:chat_to(Addr, <<"Hi!">>)),
Error = escalus:wait_for_stanza(User, 5000),
escalus:assert(is_error, [<<"cancel">>, <<"service-unavailable">>], Error),
instrument_helper:assert_one(mod_global_distrib_outgoing_closed, #{},
fun(#{count := 1, host := <<"reg1">>}) -> true end)
instrument_helper:assert(mod_global_distrib_outgoing_closed, #{},
fun(#{count := 1, host := <<"reg1">>}) -> true end)
end,

AliceStory = fun(User) ->
Expand Down
32 changes: 20 additions & 12 deletions big_tests/tests/privacy_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@
-module(privacy_SUITE).
-compile([export_all, nowarn_export_all]).

-include_lib("exml/include/exml.hrl").
-include_lib("escalus/include/escalus.hrl").
-include_lib("common_test/include/ct.hrl").
-include_lib("escalus/include/escalus_xmlns.hrl").

-define(SLEEP_TIME, 50).

-import(privacy_helper, [assert_privacy_get_event/1,
assert_privacy_get_event/2,
assert_privacy_set_event/2,
assert_privacy_check_packet_event/2,
assert_privacy_push_item_event/2]).
assert_privacy_check_packet_event/3,
assert_privacy_push_item_event/2,
assert_privacy_push_item_event/3]).

%%--------------------------------------------------------------------
%% Suite configuration
Expand Down Expand Up @@ -195,10 +194,11 @@ get_all_lists_with_active(Config) ->

privacy_helper:set_and_activate(Alice, {<<"deny_client">>, Bob}),

TS = instrument_helper:timestamp(),
escalus:send(Alice, escalus_stanza:privacy_get_all()),
escalus:assert(is_privacy_result_with_active, [<<"deny_client">>],
escalus:wait_for_stanza(Alice)),
assert_privacy_get_event(Alice)
assert_privacy_get_event(Alice, TS)

end).

Expand All @@ -209,10 +209,11 @@ get_all_lists_with_default(Config) ->
privacy_helper:set_list(Alice, {<<"allow_client">>, Bob}),
privacy_helper:set_default_list(Alice, <<"allow_client">>),

TS = instrument_helper:timestamp(),
escalus:send(Alice, escalus_stanza:privacy_get_all()),
escalus:assert(is_privacy_result_with_default,
escalus:wait_for_stanza(Alice)),
assert_privacy_get_event(Alice)
assert_privacy_get_event(Alice, TS)

end).

Expand Down Expand Up @@ -243,13 +244,14 @@ get_existing_list(Config) ->

privacy_helper:set_list(Alice, {<<"deny_client">>, Bob}),

TS = instrument_helper:timestamp(),
escalus:send(Alice, escalus_stanza:privacy_get_lists([<<"deny_client">>])),
Response = escalus:wait_for_stanza(Alice),

<<"deny_client">> = exml_query:path(Response, [{element, <<"query">>},
{element, <<"list">>},
{attr, <<"name">>}]),
assert_privacy_get_event(Alice)
assert_privacy_get_event(Alice, TS)

end).

Expand Down Expand Up @@ -391,19 +393,24 @@ remove_list(Config) ->
privacy_helper:send_set_list(Alice, {<<"deny_client">>, Bob}),

%% These are the pushed notification and iq result.
escalus_client:wait_for_stanzas(Alice, 2),
escalus:assert_many([
fun privacy_helper:is_privacy_list_push/1,
is_iq_result
], escalus_client:wait_for_stanzas(Alice, 2)),
assert_privacy_push_item_event(Alice, 1),

%% Request list deletion by sending an empty list.
RemoveRequest = escalus_stanza:privacy_set_list(
escalus_stanza:privacy_list(<<"someList">>, [])),
escalus_client:send(Alice, RemoveRequest),

%% These too are the pushed notification and iq result.
TS = instrument_helper:timestamp(),
escalus:assert_many([
fun privacy_helper:is_privacy_list_push/1,
is_iq_result
], escalus_client:wait_for_stanzas(Alice, 2)),
assert_privacy_push_item_event(Alice, 1),
assert_privacy_push_item_event(Alice, 1, TS),

escalus_client:send(Alice,
escalus_stanza:privacy_get_lists([<<"someList">>])),
Expand Down Expand Up @@ -432,10 +439,11 @@ block_jid_message(Config) ->
%% Blocking only applies to incoming messages, so Alice can still send
%% Bob a message
%% and Bob gets nothing
TS = instrument_helper:timestamp(),
escalus_client:send(Alice, escalus_stanza:chat_to(Bob, <<"Hi, Bobbb!">>)),
escalus_assert:is_chat_message(<<"Hi, Bobbb!">>, escalus_client:wait_for_stanza(Bob)),
assert_privacy_check_packet_event(Alice, #{dir => out}),
assert_privacy_check_packet_event(Bob, #{dir => in})
assert_privacy_check_packet_event(Alice, #{dir => out}, TS),
assert_privacy_check_packet_event(Bob, #{dir => in}, TS)

end).

Expand Down
Loading

0 comments on commit a4afca1

Please sign in to comment.