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 types in subscribeAllToAll roster GraphQL API #3756

Merged
merged 1 commit into from
Sep 14, 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
5 changes: 4 additions & 1 deletion big_tests/tests/graphql_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ init_domain_admin_handler(Config) ->
Password = base16:encode(crypto:strong_rand_bytes(8)),
Creds = {<<"admin@", Domain/binary>>, Password},
ok = domain_helper:set_domain_password(mim(), Domain, Password),
add_specs([{protocol, http}, {domain_admin, Creds}, {schema_endpoint, domain_admin}
add_specs([{protocol, http}, {domain_admin, Creds}, {schema_endpoint, domain_admin}
| Config]);
false -> {skip, require_rdbms}
end.
Expand Down Expand Up @@ -143,6 +143,9 @@ get_unauthorized({Code, #{<<"errors">> := Errors}}) ->
assert_response_code(unauthorized, Code),
?assertEqual(<<"no_permissions">>, ErrorCode).

get_bad_request({Code, _Msg}) ->
assert_response_code(bad_request, Code).

get_coercion_err_msg({Code, #{<<"errors">> := [Error]}}) ->
assert_response_code(bad_request, Code),
?assertEqual(<<"input_coercion">>, get_value([extensions, code], Error)),
Expand Down
76 changes: 70 additions & 6 deletions big_tests/tests/graphql_roster_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
-import(distributed_helper, [mim/0, require_rpc_nodes/1, rpc/4]).
-import(graphql_helper, [execute_user_command/5, execute_command/4, get_listener_port/1,
get_listener_config/1, get_ok_value/2, get_err_value/2, get_err_msg/1,
get_err_msg/2, user_to_jid/1, user_to_bin/1, get_unauthorized/1]).
get_err_msg/2, get_bad_request/1, user_to_jid/1, user_to_bin/1,
get_unauthorized/1]).

-include_lib("eunit/include/eunit.hrl").
-include_lib("../../include/mod_roster.hrl").
Expand Down Expand Up @@ -55,8 +56,12 @@ admin_roster_tests() ->
admin_set_mutual_subscription_try_disconnect_nonexistent_users,
admin_subscribe_to_all,
admin_subscribe_to_all_with_wrong_user,
admin_subscribe_to_all_no_groups,
admin_subscribe_to_all_without_arguments,
admin_subscribe_all_to_all,
admin_subscribe_all_to_all_with_wrong_user,
admin_subscribe_all_to_all_no_groups,
admin_subscribe_all_to_all_without_arguments,
admin_list_contacts,
admin_list_contacts_wrong_user,
admin_get_contact,
Expand All @@ -81,9 +86,13 @@ domain_admin_tests() ->
domain_admin_subscribe_to_all_no_permission,
admin_subscribe_to_all,
domain_admin_subscribe_to_all_with_wrong_user,
admin_subscribe_to_all_no_groups,
admin_subscribe_to_all_without_arguments,
domain_admin_subscribe_all_to_all_no_permission,
admin_subscribe_all_to_all,
domain_admin_subscribe_all_to_all_with_wrong_user,
admin_subscribe_all_to_all_no_groups,
admin_subscribe_all_to_all_without_arguments,
admin_list_contacts,
domain_admin_list_contacts_wrong_user,
domain_admin_list_contacts_no_permission,
Expand Down Expand Up @@ -314,6 +323,23 @@ admin_subscribe_to_all_with_wrong_user_story(Config, Alice, Bob) ->
check_contacts([Bob], Alice),
check_contacts([Alice], Bob).

admin_subscribe_to_all_no_groups(Config) ->
escalus:fresh_story_with_config(Config, [{alice, 1}, {bob, 1}, {kate, 1}],
fun admin_subscribe_to_all_no_groups_story/4).

admin_subscribe_to_all_no_groups_story(Config, Alice, Bob, Kate) ->
EmptyGroups = [],
Res = admin_subscribe_to_all(Alice, [Bob, Kate], null, Config),
check_if_created_succ(?SUBSCRIBE_TO_ALL_PATH, Res),

check_contacts([Bob, Kate], Alice, EmptyGroups),
check_contacts([Alice], Bob, EmptyGroups),
check_contacts([Alice], Kate, EmptyGroups).

admin_subscribe_to_all_without_arguments(Config) ->
Res = admin_subscribe_to_all_no_args(Config),
get_bad_request(Res).

admin_subscribe_all_to_all(Config) ->
escalus:fresh_story_with_config(Config, [{alice, 1}, {bob, 1}, {kate, 1}],
fun admin_subscribe_all_to_all_story/4).
Expand All @@ -340,6 +366,23 @@ admin_subscribe_all_to_all_with_wrong_user_story(Config, Alice, Bob) ->
check_contacts([Bob], Alice),
check_contacts([Alice], Bob).

admin_subscribe_all_to_all_no_groups(Config) ->
escalus:fresh_story_with_config(Config, [{alice, 1}, {bob, 1}, {kate, 1}],
fun admin_subscribe_all_to_all_no_groups_story/4).

admin_subscribe_all_to_all_no_groups_story(Config, Alice, Bob, Kate) ->
EmptyGroups = [],
Res = admin_subscribe_all_to_all([Alice, Bob, Kate], null, Config),
check_if_created_succ(?SUBSCRIBE_ALL_TO_ALL_PATH, Res),

check_contacts([Bob, Kate], Alice, EmptyGroups),
check_contacts([Alice, Kate], Bob, EmptyGroups),
check_contacts([Alice, Bob], Kate, EmptyGroups).

admin_subscribe_all_to_all_without_arguments(Config) ->
Res = admin_subscribe_all_to_all_no_args(Config),
get_bad_request(Res).

admin_list_contacts(Config) ->
escalus:fresh_story_with_config(Config, [{alice, 1}, {bob, 1}],
fun admin_list_contacts_story/3).
Expand Down Expand Up @@ -655,6 +698,9 @@ user_add_contact(User, Contact, Config) ->
user_add_contact(User, Contact, Name, ?DEFAULT_GROUPS, Config).

check_contacts(ContactClients, User) ->
check_contacts(ContactClients, User, ?DEFAULT_GROUPS).

check_contacts(ContactClients, User, ContactGroups) ->
Expected = [escalus_utils:jid_to_lower(escalus_client:short_jid(Client))
|| Client <- ContactClients],
ExpectedNames = [escalus_client:username(Client) || Client <- ContactClients],
Expand All @@ -663,7 +709,7 @@ check_contacts(ContactClients, User) ->
ActualNames = [ Name || #roster{name = Name} <- ActualContacts],
?assertEqual(lists:sort(Expected), lists:sort(Actual)),
?assertEqual(lists:sort(ExpectedNames), lists:sort(ActualNames)),
[?assertEqual(?DEFAULT_GROUPS, Groups) || #roster{groups = Groups} <- ActualContacts].
[?assertEqual(ContactGroups, Groups) || #roster{groups = Groups} <- ActualContacts].

check_if_created_succ(Path, Res) ->
OkList = get_ok_value(Path, Res),
Expand Down Expand Up @@ -692,10 +738,16 @@ get_roster(User, Contact) ->
full]).

make_contacts(Users) ->
[make_contact(U) || U <- Users].
make_contacts(Users, ?DEFAULT_GROUPS).

make_contacts(Users, Groups) ->
[make_contact(U, Groups) || U <- Users].

make_contact(U) ->
#{jid => user_to_bin(U), name => escalus_utils:get_username(U), groups => ?DEFAULT_GROUPS}.
make_contact(U, ?DEFAULT_GROUPS).

make_contact(U, Groups) ->
#{jid => user_to_bin(U), name => escalus_utils:get_username(U), groups => Groups}.

%% Commands

Expand Down Expand Up @@ -725,13 +777,25 @@ admin_mutual_subscription(User, Contact, Action, Config) ->
execute_command(<<"roster">>, <<"setMutualSubscription">>, Vars, Config).

admin_subscribe_to_all(User, Contacts, Config) ->
Vars = #{user => make_contact(User), contacts => make_contacts(Contacts)},
admin_subscribe_to_all(User, Contacts, ?DEFAULT_GROUPS, Config).

admin_subscribe_to_all(User, Contacts, Groups, Config) ->
Vars = #{user => make_contact(User, Groups), contacts => make_contacts(Contacts, Groups)},
execute_command(<<"roster">>, <<"subscribeToAll">>, Vars, Config).

admin_subscribe_to_all_no_args(Config) ->
execute_command(<<"roster">>, <<"subscribeToAll">>, #{}, Config).

admin_subscribe_all_to_all(Users, Config) ->
Vars = #{contacts => make_contacts(Users)},
admin_subscribe_all_to_all(Users, ?DEFAULT_GROUPS, Config).

admin_subscribe_all_to_all(Users, Groups, Config) ->
Vars = #{contacts => make_contacts(Users, Groups)},
execute_command(<<"roster">>, <<"subscribeAllToAll">>, Vars, Config).

admin_subscribe_all_to_all_no_args(Config) ->
execute_command(<<"roster">>, <<"subscribeAllToAll">>, #{}, Config).

admin_list_contacts(User, Config) ->
Vars = #{user => user_to_bin(User)},
execute_command(<<"roster">>, <<"listContacts">>, Vars, Config).
Expand Down
2 changes: 1 addition & 1 deletion priv/graphql/schemas/admin/roster.gql
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type RosterAdminMutation @protected{
subscribeToAll(user: ContactInput!, contacts: [ContactInput!]!): [String]!
@protected(type: DOMAIN, args: ["user.jid"])
"Set mutual subscriptions between all of the given contacts"
subscribeAllToAll(contacts: [ContactInput!]): [String]!
subscribeAllToAll(contacts: [ContactInput!]!): [String]!
@protected(type: DOMAIN, args: ["contacts.jid"])
}

Expand Down
3 changes: 2 additions & 1 deletion src/graphql/admin/mongoose_graphql_roster_admin_mutation.erl
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,5 @@ do_subscribe_all_to_all([User | Contacts]) ->
do_subscribe_to_all(User, Contacts) ++ do_subscribe_all_to_all(Contacts).

contact_input_map_to_tuple(#{<<"jid">> := JID, <<"name">> := Name, <<"groups">> := Groups}) ->
{JID, Name, Groups}.
Groups1 = null_to_default(Groups, []),
{JID, Name, Groups1}.