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

Use the DomainName type in GraphQL #3856

Merged
merged 6 commits into from
Nov 18, 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
2 changes: 2 additions & 0 deletions big_tests/tests/common_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ get_bjid(UserSpec) ->
Server = proplists:get_value(server, UserSpec),
<<User/binary,"@",Server/binary>>.

unprep(Bin) when is_binary(Bin) ->
list_to_binary(string:titlecase(binary_to_list(Bin))).
23 changes: 16 additions & 7 deletions big_tests/tests/graphql_account_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

-compile([export_all, nowarn_export_all]).

-import(common_helper, [unprep/1]).
-import(distributed_helper, [mim/0, require_rpc_nodes/1, rpc/4]).
-import(graphql_helper, [execute_command/4, execute_user_command/5, get_listener_port/1,
get_listener_config/1, get_ok_value/2, get_err_msg/1,
Expand Down Expand Up @@ -199,9 +200,11 @@ admin_list_users(Config) ->
Domain = domain_helper:domain(),
Username = jid:nameprep(escalus_users:get_username(Config, alice)),
JID = <<Username/binary, "@", Domain/binary>>,
Resp2 = list_users(Domain, Config),
Users = get_ok_value([data, account, listUsers], Resp2),
?assert(lists:member(JID, Users)).
Resp1 = list_users(Domain, Config),
Users = get_ok_value([data, account, listUsers], Resp1),
?assert(lists:member(JID, Users)),
Resp2 = list_users(unprep(Domain), Config),
?assertEqual(Users, get_ok_value([data, account, listUsers], Resp2)).

admin_list_users_unknown_domain(Config) ->
Resp = list_users(<<"unknown-domain">>, Config),
Expand All @@ -210,8 +213,11 @@ admin_list_users_unknown_domain(Config) ->
admin_count_users(Config) ->
% A domain with at least one user
Domain = domain_helper:domain(),
Resp2 = count_users(Domain, Config),
?assert(0 < get_ok_value([data, account, countUsers], Resp2)).
Resp1 = count_users(Domain, Config),
Count = get_ok_value([data, account, countUsers], Resp1),
?assert(0 < Count),
Resp2 = count_users(unprep(Domain), Config),
?assertEqual(Count, get_ok_value([data, account, countUsers], Resp2)).

admin_count_users_unknown_domain(Config) ->
Resp = count_users(<<"unknown-domain">>, Config),
Expand Down Expand Up @@ -306,9 +312,12 @@ admin_register_user(Config) ->
% Try to register a user with existing name
Resp2 = register_user(Domain, Username, Password, Config),
?assertNotEqual(nomatch, binary:match(get_err_msg(Resp2), <<"already registered">>)),
% Try again, this time with a domain name that is not stringprepped
Resp3 = register_user(unprep(Domain), Username, Password, Config),
?assertNotEqual(nomatch, binary:match(get_err_msg(Resp3), <<"already registered">>)),
% Try to register a user without any name
Resp3 = register_user(Domain, <<>>, Password, Config),
?assertNotEqual(nomatch, binary:match(get_err_msg(Resp3), <<"Invalid JID">>)).
Resp4 = register_user(Domain, <<>>, Password, Config),
?assertNotEqual(nomatch, binary:match(get_err_msg(Resp4), <<"Invalid JID">>)).

admin_register_random_user(Config) ->
Password = <<"my_password">>,
Expand Down
13 changes: 11 additions & 2 deletions big_tests/tests/graphql_gdpr_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

-compile([export_all, nowarn_export_all]).

-import(common_helper, [unprep/1]).
-import(domain_helper, [host_type/0, domain/0]).
-import(distributed_helper, [mim/0, rpc/4, require_rpc_nodes/1]).
-import(graphql_helper, [execute_command/4, execute_user_command/5, user_to_bin/1,
Expand All @@ -25,6 +26,7 @@ groups() ->

admin_gdpr_tests() ->
[admin_retrieve_user_data,
admin_retrieve_user_data_for_unprepped_domain,
admin_gdpr_no_user_test,
admin_gdpr_empty_filename_test,
admin_gdpr_access_denied_erofs,
Expand All @@ -34,6 +36,7 @@ admin_gdpr_tests() ->

domain_admin_gdpr_tests() ->
[admin_retrieve_user_data,
admin_retrieve_user_data_for_unprepped_domain,
admin_gdpr_no_user_test,
domain_admin_retrieve_user_data_no_permission].

Expand Down Expand Up @@ -65,11 +68,17 @@ end_per_testcase(CaseName, Config) ->
% Admin test cases

admin_retrieve_user_data(Config) ->
escalus:fresh_story_with_config(Config, [{alice, 1}], fun admin_retrieve_user_data/2).
Config1 = [{domain, domain()} | Config],
escalus:fresh_story_with_config(Config1, [{alice, 1}], fun admin_retrieve_user_data/2).

admin_retrieve_user_data_for_unprepped_domain(Config) ->
Config1 = [{domain, unprep(domain())} | Config],
escalus:fresh_story_with_config(Config1, [{alice, 1}], fun admin_retrieve_user_data/2).

admin_retrieve_user_data(Config, Alice) ->
Filename = random_filename(Config),
Res = admin_retrieve_personal_data(escalus_client:username(Alice), escalus_client:server(Alice),
Domain = ?config(domain, Config),
Res = admin_retrieve_personal_data(escalus_client:username(Alice), Domain,
list_to_binary(Filename), Config),
ParsedResult = get_ok_value([data, gdpr, retrievePersonalData], Res),
?assertEqual(<<"Data retrieved">>, ParsedResult),
Expand Down
13 changes: 11 additions & 2 deletions big_tests/tests/graphql_http_upload_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

-compile([export_all, nowarn_export_all]).

-import(common_helper, [unprep/1]).
-import(distributed_helper, [mim/0, require_rpc_nodes/1]).
-import(domain_helper, [host_type/0, domain/0, secondary_domain/0]).
-import(graphql_helper, [execute_user_command/5, execute_command/4, get_ok_value/2,
Expand Down Expand Up @@ -190,7 +191,11 @@ user_http_upload_not_configured(Config, Alice) ->
% Admin test cases

admin_get_url_test(Config) ->
Result = admin_get_url(domain(), <<"test">>, 123, <<"Test">>, 123, Config),
admin_get_url_test(Config, domain()),
admin_get_url_test(Config, unprep(domain())).

admin_get_url_test(Config, Domain) ->
Result = admin_get_url(Domain, <<"test">>, 123, <<"Test">>, 123, Config),
ParsedResult = get_ok_value([data, httpUpload, getUrl], Result),
#{<<"PutUrl">> := PutURL, <<"GetUrl">> := GetURL, <<"Header">> := _Headers} = ParsedResult,
?assertMatch({_, _}, binary:match(PutURL, [?S3_HOSTNAME])),
Expand All @@ -217,7 +222,11 @@ admin_get_url_no_domain(Config) ->
?assertEqual(<<"domain does not exist">>, get_err_msg(Result)).

admin_http_upload_not_configured(Config) ->
Result = admin_get_url(domain(), <<"test">>, 123, <<"Test">>, 123, Config),
admin_http_upload_not_configured(Config, domain()),
admin_http_upload_not_configured(Config, unprep(domain())).

admin_http_upload_not_configured(Config, Domain) ->
Result = admin_get_url(Domain, <<"test">>, 123, <<"Test">>, 123, Config),
?assertEqual(<<"deps_not_loaded">>, get_err_code(Result)),
?assertEqual(<<"Some of required modules or services are not loaded">>, get_err_msg(Result)).

Expand Down
17 changes: 13 additions & 4 deletions big_tests/tests/graphql_inbox_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

-compile([export_all, nowarn_export_all]).

-import(common_helper, [unprep/1]).
-import(distributed_helper, [mim/0, require_rpc_nodes/1, rpc/4]).
-import(domain_helper, [host_type/0, domain/0]).
-import(graphql_helper, [execute_user_command/5, execute_command/4, user_to_bin/1,
get_ok_value/2, get_err_msg/1, get_err_code/1, get_not_loaded/1,
get_unauthorized/1]).

-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
-include("inbox.hrl").

Expand Down Expand Up @@ -55,6 +57,7 @@ admin_inbox_tests() ->
admin_try_flush_nonexistent_user_bin,
admin_try_flush_user_bin_nonexistent_domain,
admin_flush_domain_bin,
admin_flush_unprepped_domain_bin,
admin_try_flush_nonexistent_domain_bin,
admin_flush_global_bin,
admin_flush_global_bin_after_days,
Expand Down Expand Up @@ -155,13 +158,18 @@ admin_try_flush_user_bin_nonexistent_domain(Config) ->
?assertErrCode(Res, domain_not_found).

admin_flush_domain_bin(Config) ->
escalus:fresh_story_with_config(Config, [{alice, 1}, {alice_bis, 1}, {kate, 1}],
Config1 = [{domain, domain()} | Config],
escalus:fresh_story_with_config(Config1, [{alice, 1}, {alice_bis, 1}, {kate, 1}],
fun admin_flush_domain_bin/4).

admin_flush_unprepped_domain_bin(Config) ->
Config1 = [{domain, unprep(domain())} | Config],
escalus:fresh_story_with_config(Config1, [{alice, 1}, {alice_bis, 1}, {kate, 1}],
fun admin_flush_domain_bin/4).

admin_flush_domain_bin(Config, Alice, AliceBis, Kate) ->
RoomBinJID = create_room_and_make_users_leave(Alice, AliceBis, Kate),
Domain = domain_helper:domain(),
Res = flush_domain_bin(Domain, Config),
Res = flush_domain_bin(?config(domain, Config), Config),
NumOfRows = get_ok_value(p(flushDomainBin), Res),
?assertEqual(1, NumOfRows),
inbox_helper:check_inbox(Kate, [], #{box => bin}),
Expand Down Expand Up @@ -213,7 +221,8 @@ admin_flush_user_bin_inbox_not_configured(Config, Alice) ->
get_not_loaded(flush_user_bin(Alice, Config)).

admin_flush_domain_bin_inbox_not_configured(Config) ->
get_not_loaded(flush_domain_bin(domain(), Config)).
get_not_loaded(flush_domain_bin(domain(), Config)),
get_not_loaded(flush_domain_bin(unprep(domain()), Config)).

admin_flush_global_bin_inbox_not_configured(Config) ->
get_not_loaded(flush_global_bin(host_type(), 10, Config)).
Expand Down
15 changes: 9 additions & 6 deletions big_tests/tests/graphql_last_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

-compile([export_all, nowarn_export_all]).

-import(common_helper, [unprep/1]).
-import(distributed_helper, [mim/0, require_rpc_nodes/1, rpc/4]).
-import(graphql_helper, [execute_command/4, execute_user_command/5, user_to_bin/1, user_to_jid/1,
get_ok_value/2, get_err_msg/1, get_err_code/1, get_unauthorized/1,
Expand Down Expand Up @@ -311,6 +312,8 @@ admin_count_active_users_story(Config, Alice, Bob) ->
set_last(Bob, now_dt_with_offset(10), Config),
Res = admin_count_active_users(Domain, null, Config),
?assertEqual(2, get_ok_value(p(countActiveUsers), Res)),
Res1 = admin_count_active_users(unprep(Domain), null, Config),
?assertEqual(2, get_ok_value(p(countActiveUsers), Res1)),
Res2 = admin_count_active_users(Domain, now_dt_with_offset(30), Config),
?assertEqual(0, get_ok_value(p(countActiveUsers), Res2)).

Expand Down Expand Up @@ -561,22 +564,22 @@ admin_get_last_not_configured_story(Config, Alice) ->

admin_count_active_users_last_not_configured(Config) ->
Domain = domain_helper:domain(),
Res = admin_count_active_users(Domain, null, Config),
get_not_loaded(Res).
get_not_loaded(admin_count_active_users(Domain, null, Config)),
get_not_loaded(admin_count_active_users(unprep(Domain), null, Config)).

admin_remove_old_users_domain_last_not_configured(Config) ->
Domain = domain_helper:domain(),
Res = admin_remove_old_users(Domain, now_dt_with_offset(150), Config),
get_not_loaded(Res).
get_not_loaded(admin_remove_old_users(Domain, now_dt_with_offset(150), Config)),
get_not_loaded(admin_remove_old_users(unprep(Domain), now_dt_with_offset(150), Config)).

admin_remove_old_users_global_last_not_configured(Config) ->
Res = admin_remove_old_users(null, now_dt_with_offset(150), Config),
get_ok_value([], Res).

admin_list_old_users_domain_last_not_configured(Config) ->
Domain = domain_helper:domain(),
Res = admin_list_old_users(Domain, now_dt_with_offset(150), Config),
get_not_loaded(Res).
get_not_loaded(admin_list_old_users(Domain, now_dt_with_offset(150), Config)),
get_not_loaded(admin_list_old_users(unprep(Domain), now_dt_with_offset(150), Config)).

admin_list_old_users_global_last_not_configured(Config) ->
Res = admin_list_old_users(null, now_dt_with_offset(150), Config),
Expand Down
30 changes: 28 additions & 2 deletions big_tests/tests/graphql_muc_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

-compile([export_all, nowarn_export_all]).

-import(common_helper, [unprep/1]).
-import(distributed_helper, [mim/0, require_rpc_nodes/1, rpc/4]).
-import(graphql_helper, [execute_command/4, execute_user_command/5, get_ok_value/2, get_err_msg/1,
get_coercion_err_msg/1, user_to_bin/1, user_to_full_bin/1, user_to_jid/1,
Expand Down Expand Up @@ -40,6 +41,7 @@ admin_groups() ->

user_muc_tests() ->
[user_create_and_delete_room,
user_create_room_with_unprepped_domain,
user_try_delete_nonexistent_room,
user_try_delete_room_by_not_owner,
user_try_create_instant_room_with_nonexistent_domain,
Expand Down Expand Up @@ -97,6 +99,7 @@ user_muc_not_configured_tests() ->

admin_muc_tests() ->
[admin_create_and_delete_room,
admin_create_room_with_unprepped_domain,
admin_try_create_instant_room_with_nonexistent_domain,
admin_try_create_instant_room_with_nonexistent_user,
admin_try_delete_nonexistent_room,
Expand Down Expand Up @@ -151,6 +154,7 @@ admin_muc_not_configured_tests() ->

domain_admin_muc_tests() ->
[admin_create_and_delete_room,
admin_create_room_with_unprepped_domain,
admin_try_create_instant_room_with_nonexistent_domain,
admin_try_delete_nonexistent_room,
domain_admin_create_and_delete_room_no_permission,
Expand Down Expand Up @@ -287,8 +291,10 @@ admin_list_rooms_story(Config, Alice, Bob) ->
BobRoom = rand_name(),
muc_helper:create_instant_room(AliceRoom, AliceJID, <<"Ali">>, []),
muc_helper:create_instant_room(BobRoom, BobJID, <<"Bob">>, [{public_list, false}]),
Res = list_rooms(muc_helper:muc_host(), Alice, null, null, Config),
#{<<"rooms">> := Rooms } = get_ok_value(?LIST_ROOMS_PATH, Res),
Res1 = list_rooms(muc_helper:muc_host(), Alice, null, null, Config),
#{<<"rooms">> := Rooms } = get_ok_value(?LIST_ROOMS_PATH, Res1),
Res2 = list_rooms(unprep(muc_helper:muc_host()), Alice, null, null, Config),
#{<<"rooms">> := Rooms } = get_ok_value(?LIST_ROOMS_PATH, Res2),
?assert(contain_room(AliceRoom, Rooms)),
?assert(contain_room(BobRoom, Rooms)).

Expand All @@ -312,6 +318,15 @@ admin_create_and_delete_room_story(Config, Alice) ->
Res4 = list_rooms(MUCServer, Alice, null, null, Config),
?assertNot(contain_room(Name, get_ok_value(?LIST_ROOMS_PATH, Res4))).

admin_create_room_with_unprepped_domain(Config) ->
FreshConfig = escalus_fresh:create_users(Config, [{alice, 1}]),
AliceJid = escalus_users:get_jid(FreshConfig, alice),
Name = rand_name(),
MUCServer = unprep(muc_helper:muc_host()),
Res = create_instant_room(MUCServer, Name, AliceJid, <<"Ali">>, FreshConfig),
?assertMatch(#{<<"title">> := Name, <<"private">> := false, <<"usersNumber">> := 0},
get_ok_value(?CREATE_INSTANT_ROOM_PATH, Res)).

admin_try_create_instant_room_with_nonexistent_domain(Config) ->
escalus:fresh_story_with_config(Config, [{alice, 1}],
fun admin_try_create_instant_room_with_nonexistent_domain_story/2).
Expand Down Expand Up @@ -975,6 +990,17 @@ user_create_and_delete_room_story(Config, Alice) ->
Res4 = user_list_rooms(Alice, MUCServer, null, null, Config),
?assertNot(contain_room(Name, get_ok_value(?LIST_ROOMS_PATH, Res4))).

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

user_create_room_with_unprepped_domain_story(Config, Alice) ->
Name = rand_name(),
MUCServer = unprep(muc_helper:muc_host()),
Res = user_create_instant_room(Alice, MUCServer, Name, <<"Ali">>, Config),
?assertMatch(#{<<"title">> := Name, <<"private">> := false, <<"usersNumber">> := 0},
get_ok_value(?CREATE_INSTANT_ROOM_PATH, Res)).

user_try_create_instant_room_with_nonexistent_domain(Config) ->
escalus:fresh_story_with_config(Config, [{alice, 1}],
fun user_try_create_instant_room_with_nonexistent_domain_story/2).
Expand Down
30 changes: 29 additions & 1 deletion big_tests/tests/graphql_muc_light_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

-compile([export_all, nowarn_export_all]).

-import(common_helper, [unprep/1]).
-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_msg/1,
Expand Down Expand Up @@ -48,7 +49,7 @@ groups() ->
{admin_cli, [], admin_groups()},
{user_muc_light, [parallel], user_muc_light_tests()},
{user_muc_light_not_configured, [], user_muc_light_not_configured_tests()},
{admin_muc_light, [parallel], admin_muc_light_tests()},
{admin_muc_light, [], admin_muc_light_tests()},
{domain_admin_muc_light, [], domain_admin_muc_light_tests()},
{admin_muc_light_not_configured, [], admin_muc_light_not_configured_tests()}].

Expand All @@ -62,6 +63,7 @@ admin_groups() ->

user_muc_light_tests() ->
[user_create_room,
user_create_room_with_unprepped_domain,
user_create_room_with_custom_fields,
user_create_identified_room,
user_change_room_config,
Expand Down Expand Up @@ -94,6 +96,7 @@ user_muc_light_not_configured_tests() ->

admin_muc_light_tests() ->
[admin_create_room,
admin_create_room_with_unprepped_domain,
admin_create_room_with_custom_fields,
admin_create_identified_room,
admin_change_room_config,
Expand Down Expand Up @@ -122,6 +125,7 @@ admin_muc_light_tests() ->

domain_admin_muc_light_tests() ->
[admin_create_room,
admin_create_room_with_unprepped_domain,
admin_create_room_with_custom_fields,
domain_admin_create_room_no_permission,
admin_create_identified_room,
Expand Down Expand Up @@ -258,6 +262,19 @@ user_create_room_story(Config, Alice) ->
Res2 = user_create_room(Alice, ?UNKNOWN_DOMAIN, Name, Subject, null, Config),
?assertNotEqual(nomatch, binary:match(get_err_msg(Res2), <<"not found">>)).

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

user_create_room_with_unprepped_domain_story(Config, Alice) ->
MucServer = ?config(muc_light_host, Config),
Name = <<"room with unprepped domain">>,
Subject = <<"testing">>,
Res = user_create_room(Alice, unprep(MucServer), Name, Subject, null, Config),
#{<<"jid">> := JID, <<"name">> := Name, <<"subject">> := Subject} =
get_ok_value(?CREATE_ROOM_PATH, Res),
?assertMatch(#jid{lserver = MucServer}, jid:from_binary_noprep(JID)).

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

Expand Down Expand Up @@ -931,6 +948,17 @@ admin_create_room_story(Config, Alice) ->
Res2 = create_room(?UNKNOWN_DOMAIN, Name, AliceBin, Subject, null, Config),
?assertNotEqual(nomatch, binary:match(get_err_msg(Res2), <<"not found">>)).

admin_create_room_with_unprepped_domain(Config) ->
FreshConfig = escalus_fresh:create_users(Config, [{alice, 1}]),
AliceBin = escalus_users:get_jid(FreshConfig, alice),
MucServer = ?config(muc_light_host, Config),
Name = <<"room with unprepped domain">>,
Subject = <<"testing">>,
Res = create_room(unprep(MucServer), Name, AliceBin, Subject, null, Config),
#{<<"jid">> := JID, <<"name">> := Name, <<"subject">> := Subject} =
get_ok_value(?CREATE_ROOM_PATH, Res),
?assertMatch(#jid{lserver = MucServer}, jid:from_binary_noprep(JID)).

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

Expand Down
Loading