5050 change_nick_form_iq /1 ,
5151 set_nick /2 ,
5252 assert_room_event /2 ,
53+ assert_room_events /3 ,
5354 wait_for_room_count /1 ,
5455 count_rooms /0
5556 ]).
9899% %--------------------------------------------------------------------
99100
100101all () -> [
102+ acl_deny ,
101103 {group , disco },
102104 {group , disco_with_mam },
103105 {group , disco_rsm },
@@ -134,6 +136,9 @@ groups() ->
134136 deep_hibernation_metrics_are_updated ,
135137 can_found_in_db_when_stopped
136138 ]},
139+ {hibernation_failures , [], [hibernated_room_is_stopped_and_restored_by_presence_user_not_allowed ,
140+ hibernated_room_is_stopped_and_restoration_by_presence_fails
141+ ]},
137142 {disco , [parallel ], [
138143 disco_service ,
139144 disco_features ,
@@ -155,6 +160,7 @@ groups() ->
155160 moderator_kick_with_reason ,
156161 moderator_kick_unauthorized ,
157162 moderator_voice ,
163+ visitor_is_not_allowed_to_send ,
158164 moderator_voice_with_reason ,
159165 moderator_voice_unauthorized ,
160166 moderator_voice_list ,
@@ -226,6 +232,7 @@ groups() ->
226232 subject ,
227233 no_subject ,
228234 send_to_all ,
235+ member_must_not_send_service_messages ,
229236 send_and_receive_private_message_client_with_x_elem ,
230237 send_and_receive_private_message_client_without_x_elem ,
231238 send_private_groupchat ,
@@ -409,6 +416,10 @@ init_per_group(hibernation, Config) ->
409416 Config1 = dynamic_modules :save_modules (host_type (), Config ),
410417 setup_mam (mam_helper :backend ()),
411418 Config1 ;
419+ init_per_group (hibernation_failures , Config ) ->
420+ Config1 = dynamic_modules :save_modules (host_type (), Config ),
421+ setup_mam (mam_helper :backend ()),
422+ Config1 ;
412423init_per_group (register_over_s2s , Config ) ->
413424 Config1 = s2s_helper :init_s2s (Config ),
414425 Config2 = s2s_helper :configure_s2s (both_plain , Config1 ),
@@ -471,6 +482,8 @@ end_per_group(G, Config) when G =:= http_auth_no_server;
471482 dynamic_modules :restore_modules (Config );
472483end_per_group (hibernation , Config ) ->
473484 dynamic_modules :restore_modules (Config );
485+ end_per_group (hibernation_failures , Config ) ->
486+ dynamic_modules :restore_modules (Config );
474487end_per_group (register_over_s2s , Config ) ->
475488 s2s_helper :end_s2s (Config ),
476489 escalus :delete_users (Config , escalus :get_users ([alice2 , bob , kate ]));
@@ -604,6 +617,15 @@ end_per_testcase(CaseName = room_creation_not_allowed, Config) ->
604617end_per_testcase (CaseName = create_instant_persistent_room , Config ) ->
605618 dynamic_modules :restore_modules (Config ),
606619 escalus :end_per_testcase (CaseName , Config );
620+ end_per_testcase (CaseName = acl_deny , Config ) ->
621+ unload_meck (),
622+ escalus :end_per_testcase (CaseName , Config );
623+ end_per_testcase (CaseName = hibernated_room_is_stopped_and_restored_by_presence_user_not_allowed , Config ) ->
624+ unload_meck (),
625+ escalus :end_per_testcase (CaseName , Config );
626+ end_per_testcase (CaseName = hibernated_room_is_stopped_and_restoration_by_presence_fails , Config ) ->
627+ unload_meck (),
628+ escalus :end_per_testcase (CaseName , Config );
607629end_per_testcase (CaseName , Config ) ->
608630 escalus :end_per_testcase (CaseName , Config ).
609631
@@ -811,6 +833,31 @@ moderator_voice(ConfigIn) ->
811833 escalus :assert (Pred2 , escalus :wait_for_stanza (Bob ))
812834 end ).
813835
836+ visitor_is_not_allowed_to_send (ConfigIn ) ->
837+ UserSpecs = [{alice , 1 }, {bob , 1 }],
838+ story_with_room (ConfigIn , moderator_room_opts (), UserSpecs , fun (Config , Alice , Bob ) ->
839+ % % Alice joins room
840+ escalus :send (Alice , stanza_muc_enter_room (? config (room , Config ), <<" alice" >>)),
841+ escalus :wait_for_stanzas (Alice , 2 ),
842+ % % Bob joins room
843+ escalus :send (Bob , stanza_muc_enter_room (? config (room , Config ), <<" bob" >>)),
844+ escalus :wait_for_stanzas (Bob , 3 ),
845+ % % Skip Bob's presence
846+ escalus :wait_for_stanza (Alice ),
847+ % % Alice makes Bob a visitor
848+ escalus :send (Alice , stanza_set_roles (? config (room ,Config ),
849+ [{<<" bob" >>,<<" visitor" >>}])),
850+ Msg = <<" chat message" >>,
851+ Id = <<" MyID" >>,
852+ Stanza = escalus_stanza :set_id (
853+ escalus_stanza :groupchat_to (room_address (? config (room , Config )), Msg ), Id ),
854+ escalus :send (Bob , Stanza ),
855+ Res = escalus :wait_for_stanza (Bob ),
856+ ? assertEqual (<<" error" >>, exml_query :attr (Res , <<" type" >>)),
857+ ? assertEqual (<<" 403" >>, exml_query :path (Res , [{element , <<" error" >>}, {attr , <<" code" >>}])),
858+ ok
859+ end ).
860+
814861moderator_voice_with_reason (ConfigIn ) ->
815862 UserSpecs = [{alice , 1 }, {bob , 1 }],
816863 story_with_room (ConfigIn , moderator_room_opts (), UserSpecs , fun (Config , Alice , Bob ) ->
@@ -2630,6 +2677,41 @@ send_to_all(ConfigIn) ->
26302677 escalus_assert :has_no_stanzas (Kate )
26312678 end ).
26322679
2680+ acl_deny (ConfigIn ) ->
2681+ ok = rpc (mim (), meck , expect , [acl , match_rule ,
2682+ fun (_ , _ , muc , # jid {luser = K }) ->
2683+ case K of
2684+ <<" kate" , _ /binary >> -> deny ;
2685+ _ -> allow
2686+ end ;
2687+ (_ , _ , _ , _ ) ->
2688+ allow
2689+ end ]),
2690+ UserSpecs = [{alice , 1 }, {bob , 1 }, {kate , 1 }],
2691+ story_with_room (ConfigIn , [], UserSpecs , fun (Config , _Alice , Bob , Kate ) ->
2692+ escalus :send (Bob , stanza_muc_enter_room (? config (room , Config ), escalus_utils :get_username (Bob ))),
2693+ escalus :wait_for_stanzas (Bob , 2 ),
2694+ escalus :send (Kate , stanza_muc_enter_room (? config (room , Config ), escalus_utils :get_username (Kate ))),
2695+ Res = escalus_client :wait_for_stanza (Kate ),
2696+ escalus :assert (is_presence_with_type , [<<" error" >>], Res ),
2697+ ? assertEqual (<<" 403" >>, exml_query :path (Res , [{element , <<" error" >>}, {attr , <<" code" >>}])),
2698+ ok
2699+ end ).
2700+
2701+ member_must_not_send_service_messages (ConfigIn ) ->
2702+ UserSpecs = [{alice , 1 }, {bob , 1 }],
2703+ story_with_room (ConfigIn , [], UserSpecs , fun (Config , _Alice , Bob ) ->
2704+ escalus :send (Bob , stanza_muc_enter_room (? config (room , Config ), escalus_utils :get_username (Bob ))),
2705+ escalus :wait_for_stanzas (Bob , 2 ),
2706+ Msg = <<" chat message" >>,
2707+ Id = <<" MyID" >>,
2708+ Stanza = escalus_stanza :set_id (escalus_stanza :groupchat_to (muc_host (), Msg ), Id ),
2709+ escalus :send (Bob , Stanza ),
2710+ Res = escalus :wait_for_stanza (Bob ),
2711+ ? assertEqual (<<" error" >>, exml_query :attr (Res , <<" type" >>)),
2712+ ? assertEqual (<<" 403" >>, exml_query :path (Res , [{element , <<" error" >>}, {attr , <<" code" >>}])),
2713+ ok
2714+ end ).
26332715
26342716% Examples 46, 47
26352717send_and_receive_private_message_client_with_x_elem (ConfigIn ) ->
@@ -4468,7 +4550,6 @@ hibernated_room_is_stopped_and_restored_by_presence(Config) ->
44684550 escalus :wait_for_stanza (Bob ),
44694551 leave_room (RoomName , Bob ),
44704552 true = wait_for_room_to_be_stopped (Pid , timer :seconds (8 )),
4471- ct :sleep (timer :seconds (1 )),
44724553
44734554 escalus :send (Bob , stanza_join_room (RoomName , <<" bob" >>)),
44744555 Presence = escalus :wait_for_stanza (Bob , ? WAIT_TIMEOUT ),
@@ -4483,6 +4564,59 @@ hibernated_room_is_stopped_and_restored_by_presence(Config) ->
44834564 destroy_room (muc_host (), RoomName ),
44844565 forget_room (host_type (), muc_host (), RoomName ).
44854566
4567+ hibernated_room_is_stopped_and_restored_by_presence_user_not_allowed (Config ) ->
4568+ RoomName = fresh_room_name (),
4569+ ok = rpc (mim (), meck , expect , [acl , match_rule ,
4570+ fun (_ , _ , muc_create , # jid {luser = K }) ->
4571+ case K of
4572+ <<" bob" , _ /binary >> -> deny ;
4573+ _ -> allow
4574+ end ;
4575+ (_ , _ , _ , _ ) ->
4576+ allow
4577+ end ]),
4578+ escalus :fresh_story (Config , [{alice , 1 }, {bob , 1 }], fun (Alice , Bob ) ->
4579+ Opts = [{persistentroom , true },
4580+ {subject , <<" Restorable" >>}],
4581+ Result = given_fresh_room_with_participants_is_hibernated (Alice , RoomName , Opts , Bob ),
4582+ {ok , _RoomJID , Pid } = Result ,
4583+ leave_room (RoomName , Alice ),
4584+ escalus :wait_for_stanza (Bob ),
4585+ leave_room (RoomName , Bob ),
4586+ true = wait_for_room_to_be_stopped (Pid , timer :seconds (8 )),
4587+ escalus :send (Bob , stanza_join_room (RoomName , <<" bob" >>)),
4588+ Presence = escalus :wait_for_stanza (Bob , ? WAIT_TIMEOUT ),
4589+ escalus :assert (is_presence_with_type , [<<" error" >>], Presence ),
4590+ ? assertEqual (<<" 405" >>, exml_query :path (Presence , [{element , <<" error" >>}, {attr , <<" code" >>}])),
4591+ ok
4592+ end ),
4593+ destroy_room (muc_host (), RoomName ),
4594+ forget_room (host_type (), muc_host (), RoomName ).
4595+
4596+ hibernated_room_is_stopped_and_restoration_by_presence_fails (Config ) ->
4597+ RoomName = fresh_room_name (),
4598+ escalus :fresh_story (Config , [{alice , 1 }, {bob , 1 }], fun (Alice , Bob ) ->
4599+ Opts = [{persistentroom , true },
4600+ {subject , <<" Restorable" >>}],
4601+ Result = given_fresh_room_with_participants_is_hibernated (Alice , RoomName , Opts , Bob ),
4602+ {ok , _RoomJID , Pid } = Result ,
4603+ leave_room (RoomName , Alice ),
4604+ escalus :wait_for_stanza (Bob ),
4605+ leave_room (RoomName , Bob ),
4606+ true = wait_for_room_to_be_stopped (Pid , timer :seconds (8 )),
4607+ ok = rpc (mim (), meck , expect , [mod_muc_backend , restore_room ,
4608+ fun (_ , _ , _ ) ->
4609+ {error , fails }
4610+ end ]),
4611+ escalus :send (Bob , stanza_join_room (RoomName , <<" bob" >>)),
4612+ Presence = escalus :wait_for_stanza (Bob , ? WAIT_TIMEOUT ),
4613+ escalus :assert (is_presence_with_type , [<<" error" >>], Presence ),
4614+ ? assertEqual (<<" 503" >>, exml_query :path (Presence , [{element , <<" error" >>}, {attr , <<" code" >>}])),
4615+ ok
4616+ end ),
4617+ destroy_room (muc_host (), RoomName ),
4618+ forget_room (host_type (), muc_host (), RoomName ).
4619+
44864620stopped_rooms_history_is_available (Config ) ->
44874621 RoomName = fresh_room_name (),
44884622 escalus :fresh_story (Config , [{alice , 1 }, {bob , 1 }], fun (Alice , Bob ) ->
@@ -5475,3 +5609,15 @@ fresh_nick_name(Prefix) ->
54755609
54765610fresh_nick_name () ->
54775611 fresh_room_name (binary :encode_hex (crypto :strong_rand_bytes (5 ), lowercase )).
5612+
5613+ stop_room (Room ) ->
5614+ {ok , Pid } = rpc (mim (), mod_muc_online_backend , find_room_pid ,
5615+ [domain_helper :host_type (), muc_host (), Room ]),
5616+ Pid ! stop_persistent_room_process ,
5617+ WaitFun = fun () ->
5618+ rpc (mim (), mod_muc_online_backend , find_room_pid ,
5619+ [domain_helper :host_type (), muc_host (), Room ])
5620+ end ,
5621+ wait_helper :wait_until (WaitFun , {error , not_found }),
5622+ ok .
5623+
0 commit comments