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

Fix muc validation in graphql #3799

Merged
merged 3 commits into from
Oct 21, 2022
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
9 changes: 9 additions & 0 deletions big_tests/tests/graphql_muc_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ user_muc_tests() ->
user_try_delete_nonexistent_room,
user_try_delete_room_by_not_owner,
user_try_create_instant_room_with_nonexistent_domain,
user_try_create_instant_room_with_invalid_name,
user_list_rooms,
user_list_room_users,
user_list_room_users_without_anonymous_mode,
Expand Down Expand Up @@ -982,6 +983,14 @@ user_try_create_instant_room_with_nonexistent_domain_story(Config, Alice) ->
Res = user_create_instant_room(Alice, <<"unknown">>, rand_name(), <<"Ali">>, Config),
?assertNotEqual(nomatch, binary:match(get_err_msg(Res), <<"not found">>)).

user_try_create_instant_room_with_invalid_name(Config) ->
escalus:fresh_story_with_config(Config, [{alice, 1}],
fun user_try_create_instant_room_with_invalid_name_story/2).

user_try_create_instant_room_with_invalid_name_story(Config, Alice) ->
Res = user_create_instant_room(Alice, muc_helper:muc_host(), <<"test room">>, <<"Ali">>, Config),
?assertNotEqual(nomatch, binary:match(get_err_msg(Res), <<"Room name or domain is invalid">>)).

user_try_delete_nonexistent_room(Config) ->
escalus:fresh_story_with_config(Config, [{alice, 1}],
fun user_try_delete_nonexistent_room_story/2).
Expand Down
2 changes: 1 addition & 1 deletion priv/graphql/schemas/admin/muc.gql
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Allow admin to get information about Multi-User Chat rooms.
type MUCAdminQuery @protected @use(modules: ["mod_muc"]){
"Get MUC rooms under the given MUC domain"
#There is no @use directive because it is currently impossible to get HostType from mucDomain in directive code
listRooms(mucDomain: String!, from: JID, limit: Int, index: Int): MUCRoomsPayload!
listRooms(mucDomain: String!, from: JID!, limit: Int, index: Int): MUCRoomsPayload!
@protected(type: DOMAIN, args: ["from"])
"Get configuration of the MUC room"
getRoomConfig(room: JID!): MUCRoomConfig
Expand Down
11 changes: 6 additions & 5 deletions src/mod_muc_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,9 @@ create_instant_room(MUCDomain, Name, OwnerJID, Nick) ->
%% Because these stanzas are sent on the owner's behalf through
%% the HTTP API, they will certainly receive stanzas as a
%% consequence, even if their client(s) did not initiate this.
case ejabberd_auth:does_user_exist(OwnerJID) of
true ->
BareRoomJID = jid:make_bare(Name, MUCDomain),
UserRoomJID = jid:make(Name, MUCDomain, Nick),
case {ejabberd_auth:does_user_exist(OwnerJID), jid:make_bare(Name, MUCDomain)} of
{true, BareRoomJID = #jid{}} ->
UserRoomJID = jid:replace_resource(BareRoomJID, Nick),
%% Send presence to create a room.
ejabberd_router:route(OwnerJID, UserRoomJID,
presence(OwnerJID, UserRoomJID, undefined)),
Expand All @@ -115,7 +114,9 @@ create_instant_room(MUCDomain, Name, OwnerJID, Nick) ->
Error ->
Error
end;
false ->
{true, error} ->
{invalid_input, "Room name or domain is invalid"};
{false, _} ->
?USER_NOT_FOUND_RESULT
end.

Expand Down