17
17
-module (mod_blocking_SUITE ).
18
18
-compile ([export_all , nowarn_export_all ]).
19
19
20
+ -include_lib (" common_test/include/ct.hrl" ).
20
21
-include_lib (" exml/include/exml.hrl" ).
21
22
-include_lib (" eunit/include/eunit.hrl" ).
22
23
-include_lib (" escalus/include/escalus_xmlns.hrl" ).
@@ -33,7 +34,9 @@ all() ->
33
34
{group , effect },
34
35
{group , offline },
35
36
{group , errors },
36
- {group , pushes }
37
+ {group , pushes },
38
+ {group , muc },
39
+ {group , muc_light }
37
40
].
38
41
39
42
groups () ->
@@ -43,7 +46,9 @@ groups() ->
43
46
{offline , [sequence ], offline_test_cases ()},
44
47
{errors , [parallel ], error_test_cases ()},
45
48
{pushes , [parallel ], push_test_cases ()},
46
- {notify , [parallel ], notify_test_cases ()}
49
+ {notify , [parallel ], notify_test_cases ()},
50
+ {muc , [parallel ], muc_test_cases ()},
51
+ {muc_light , [parallel ], muc_light_test_cases ()}
47
52
].
48
53
49
54
manage_test_cases () ->
@@ -81,12 +86,19 @@ offline_test_cases() ->
81
86
82
87
error_test_cases () ->
83
88
[blocker_cant_send_to_blockee ].
89
+
84
90
push_test_cases () ->
85
91
[block_push_sent ].
86
92
87
93
notify_test_cases () ->
88
94
[notify_blockee ].
89
95
96
+ muc_test_cases () ->
97
+ [messages_from_blocked_user_dont_arrive_muc ].
98
+
99
+ muc_light_test_cases () ->
100
+ [messages_from_blocked_user_dont_arrive_muc_light ].
101
+
90
102
suite () ->
91
103
escalus :suite ().
92
104
@@ -108,9 +120,28 @@ end_per_suite(Config) ->
108
120
escalus :end_per_suite (Config ),
109
121
instrument_helper :stop ().
110
122
123
+ init_per_group (muc , Config ) ->
124
+ muc_helper :load_muc (),
125
+ mongoose_helper :ensure_muc_clean (),
126
+ init_per_group (generic , Config );
127
+ init_per_group (muc_light , Config0 ) ->
128
+ HostType = domain_helper :host_type (),
129
+ Config1 = dynamic_modules :save_modules (HostType , Config0 ),
130
+ Backend = mongoose_helper :mnesia_or_rdbms_backend (),
131
+ MucLightConfig = config_parser_helper :mod_config (mod_muc_light , #{backend => Backend }),
132
+ dynamic_modules :ensure_modules (HostType , [{mod_muc_light , MucLightConfig }]),
133
+ init_per_group (generic , Config1 );
111
134
init_per_group (_GroupName , Config ) ->
112
135
escalus_fresh :create_users (Config , escalus :get_users ([alice , bob , kate , mike , john ])).
113
136
137
+ end_per_group (muc , Config ) ->
138
+ mongoose_helper :ensure_muc_clean (),
139
+ muc_helper :unload_muc (),
140
+ Config ;
141
+ end_per_group (muc_light , Config ) ->
142
+ muc_light_helper :clear_db (domain_helper :host_type ()),
143
+ dynamic_modules :restore_modules (Config ),
144
+ Config ;
114
145
end_per_group (_GroupName , Config ) ->
115
146
Config .
116
147
@@ -240,6 +271,47 @@ messages_from_blocked_user_dont_arrive(Config) ->
240
271
privacy_helper :assert_privacy_check_packet_event (User1 , #{dir => in , blocked_count => 1 }, TS )
241
272
end ).
242
273
274
+ messages_from_blocked_user_dont_arrive_muc (ConfigIn ) ->
275
+ muc_helper :story_with_room (ConfigIn , [], [{alice , 1 }, {bob , 1 }], fun (Config , Alice , Bob ) ->
276
+ RoomJid = ? config (room , Config ),
277
+ BobNick = escalus_utils :get_username (Bob ),
278
+ escalus :send (Bob , muc_helper :stanza_muc_enter_room (RoomJid , BobNick )),
279
+ escalus :wait_for_stanzas (Bob , 2 ),
280
+ AliceNick = escalus_utils :get_username (Alice ),
281
+ escalus :send (Alice , muc_helper :stanza_muc_enter_room (RoomJid , AliceNick )),
282
+ escalus :wait_for_stanza (Bob ),
283
+ escalus :wait_for_stanzas (Alice , 3 ),
284
+
285
+ user_blocks (Alice , [Bob ], muc ),
286
+ TS = instrument_helper :timestamp (),
287
+ Stanza = escalus_stanza :groupchat_to (muc_helper :room_address (? config (room , Config )), <<" Hello" >>),
288
+ escalus :send (Bob , Stanza ),
289
+ ct :sleep (100 ),
290
+ % We don't expect Bob to get an error from Alice as this would lead to
291
+ % her being kicked out of the room
292
+ escalus_assert :has_no_stanzas (Alice ),
293
+ privacy_helper :assert_privacy_check_packet_event (Bob , #{dir => out }, TS ),
294
+ privacy_helper :assert_privacy_check_packet_event (Alice , #{dir => in , blocked_count => 1 }, TS )
295
+ end ).
296
+
297
+ messages_from_blocked_user_dont_arrive_muc_light (Config ) ->
298
+ escalus :fresh_story (Config , [{alice , 1 }, {bob , 1 }], fun (Alice , Bob ) ->
299
+ RoomName = <<" blocking-testroom" >>,
300
+ muc_light_helper :create_room (RoomName , muc_light_helper :muc_host (),
301
+ Alice , [Bob ], Config , muc_light_helper :ver (1 )),
302
+
303
+ user_blocks (Alice , [Bob ], muc_light ),
304
+ TS = instrument_helper :timestamp (),
305
+ Stanza = escalus_stanza :groupchat_to (muc_light_helper :room_bin_jid (RoomName ), <<" Hello" >>),
306
+ escalus :send (Bob , Stanza ),
307
+ ct :sleep (100 ),
308
+ % We don't expect Bob to get an error from Alice as this would lead to
309
+ % her being kicked out of the room
310
+ escalus_assert :has_no_stanzas (Alice ),
311
+ privacy_helper :assert_privacy_check_packet_event (Bob , #{dir => out }, TS ),
312
+ privacy_helper :assert_privacy_check_packet_event (Alice , #{dir => in , blocked_count => 1 }, TS )
313
+ end ).
314
+
243
315
messages_from_unblocked_user_arrive_again (Config ) ->
244
316
escalus :fresh_story (
245
317
Config , [{alice , 1 }, {bob , 1 }],
@@ -594,9 +666,12 @@ get_blocklist_items(Items) ->
594
666
maps :get (<<" jid" >>, A )
595
667
end , Items ).
596
668
597
- user_blocks (Blocker , Blockees ) when is_list (Blockees ) ->
669
+ user_blocks (Blocker , Blockees ) ->
670
+ user_blocks (Blocker , Blockees , pm ).
671
+
672
+ user_blocks (Blocker , Blockees , ChatType ) when is_list (Blockees ) ->
598
673
TS = instrument_helper :timestamp (),
599
- BlockeeJIDs = [ escalus_utils : jid_to_lower ( escalus_client : short_jid ( B )) || B <- Blockees ] ,
674
+ BlockeeJIDs = blockee_jids ( Blockees , ChatType ) ,
600
675
AddStanza = block_users_stanza (BlockeeJIDs ),
601
676
escalus_client :send (Blocker , AddStanza ),
602
677
Res = escalus :wait_for_stanzas (Blocker , 2 ),
@@ -605,6 +680,15 @@ user_blocks(Blocker, Blockees) when is_list(Blockees) ->
605
680
escalus :assert_many (Preds , Res ),
606
681
privacy_helper :assert_privacy_set_event (Blocker , #{}, TS ).
607
682
683
+ blockee_jids (Blockees , pm ) ->
684
+ [escalus_utils :jid_to_lower (escalus_client :short_jid (B )) || B <- Blockees ];
685
+ blockee_jids (Blockees , muc ) ->
686
+ MucHost = muc_helper :muc_host (),
687
+ [<<MucHost /binary , " /" , (escalus_client :username (B ))/binary >> || B <- Blockees ];
688
+ blockee_jids (Blockees , muc_light ) ->
689
+ MucHost = muc_light_helper :muc_host (),
690
+ [<<MucHost /binary , " /" , (escalus_client :short_jid (B ))/binary >> || B <- Blockees ].
691
+
608
692
blocklist_is_empty (BlockList ) ->
609
693
escalus :assert (is_iq_result , BlockList ),
610
694
escalus :assert (fun is_blocklist_result_empty /1 , BlockList ).
0 commit comments