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

Properly handle incoming presence of type error by MUC room #1307

Merged
merged 1 commit into from
May 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions apps/ejabberd/src/mod_muc_room.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1036,8 +1036,7 @@ process_presence_error(From, Packet, Lang, StateData) ->
true ->
ErrorText
= <<"This participant is kicked from the room because he sent an error presence">>,
expulse_participant(Packet, From, StateData, translate:translate(Lang, ErrorText)),
StateData;
expulse_participant(Packet, From, StateData, translate:translate(Lang, ErrorText));
_ ->
StateData
end.
Expand Down
36 changes: 35 additions & 1 deletion test.disabled/ejabberd_tests/tests/muc_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ groups() -> [
mediated_invite,
one2one_chat_to_muc,
exit_room,
exit_room_with_status
exit_room_with_status,
kicked_after_sending_malformed_presence
]},
{owner, [parallel], [
%% fails, see testcase
Expand Down Expand Up @@ -2691,6 +2692,39 @@ exit_room_with_status(Config1) ->
end),
destroy_room(Config).

kicked_after_sending_malformed_presence(Config1) ->
AliceSpec = given_fresh_spec(Config1, alice),
Config = given_fresh_room(Config1, AliceSpec, []),
escalus:fresh_story(Config, [{bob, 1}, {kate, 1}], fun(Bob, Kate) ->
%% GIVEN An user is in the room
Room = ?config(room, Config),
Username = escalus_utils:get_username(Bob),
Stanza = stanza_muc_enter_room(Room, Username),
escalus:send(Bob, Stanza),
Presence = escalus:wait_for_stanza(Bob),
is_self_presence(Bob, ?config(room, Config), Presence),
escalus:assert(is_message, escalus:wait_for_stanza(Bob)), %% subject
%% WHEN The user sends a malformed presence
Error = stanza_to_room(escalus_stanza:presence(<<"error">>), Room, Username),
escalus:send(Bob, Error),

%% THAN He is kicked from the room
PresenceUn = escalus:wait_for_stanza(Bob),
escalus:assert(is_presence_with_type, [<<"unavailable">>], PresenceUn),
escalus:assert(is_stanza_from, [room_address(Room, Username)], PresenceUn),

%% THAN He is actually kicked
%% Kate should not receive his presence
KateUsername = escalus_utils:get_username(Kate),
KateStanza = stanza_muc_enter_room(Room, KateUsername),
escalus:send(Kate, KateStanza),
KatePresence = escalus:wait_for_stanza(Kate),
is_self_presence(Kate, ?config(room, Config), KatePresence),
escalus:assert(is_message, escalus:wait_for_stanza(Kate)), %% subject
ok
end),
destroy_room(Config).

%%-------------------------------------------------------------------
%% Tests
%%--------------------------------------------------------------------
Expand Down