Skip to content

Commit

Permalink
Merge branch 'master' into feature/mongoose_c2s
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonVides committed Dec 2, 2022
2 parents 29c7bdc + 83ed0f6 commit 984d59f
Show file tree
Hide file tree
Showing 101 changed files with 1,827 additions and 1,134 deletions.
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))).
26 changes: 19 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,15 @@ 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 name that is not stringprepped
Resp3 = register_user(unprep(Domain), unprep(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),
?assertMatch({_, _}, binary:match(get_coercion_err_msg(Resp4), <<"empty_user_name">>)),
% Try to register a user with an invalid name
Resp5 = register_user(Domain, <<"@invalid">>, Password, Config),
?assertMatch({_, _}, binary:match(get_coercion_err_msg(Resp5), <<"failed_to_parse_user_name">>)).

admin_register_random_user(Config) ->
Password = <<"my_password">>,
Expand Down
19 changes: 14 additions & 5 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_with_unprepped_name,
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_with_unprepped_name,
admin_gdpr_no_user_test,
domain_admin_retrieve_user_data_no_permission].

Expand Down Expand Up @@ -65,16 +68,22 @@ 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 = escalus_fresh:create_users(Config, [{alice, 1}]),
User = escalus_users:get_username(Config1, alice),
admin_retrieve_user_data(Config1, User, domain()).

admin_retrieve_user_data(Config, Alice) ->
admin_retrieve_user_data_with_unprepped_name(Config) ->
Config1 = escalus_fresh:create_users(Config, [{alice, 1}]),
User = escalus_users:get_username(Config1, alice),
admin_retrieve_user_data(Config1, unprep(User), unprep(domain())).

admin_retrieve_user_data(Config, User, Domain) ->
Filename = random_filename(Config),
Res = admin_retrieve_personal_data(escalus_client:username(Alice), escalus_client:server(Alice),
list_to_binary(Filename), Config),
Res = admin_retrieve_personal_data(User, Domain, list_to_binary(Filename), Config),
ParsedResult = get_ok_value([data, gdpr, retrievePersonalData], Res),
?assertEqual(<<"Data retrieved">>, ParsedResult),
FullPath = get_mim_cwd() ++ "/" ++ Filename,
Dir = make_dir_name(Filename, escalus_client:username(Alice)),
Dir = make_dir_name(Filename, User),
ct:log("extracting logs ~s", [Dir]),
?assertMatch({ok, _}, zip:extract(FullPath, [{cwd, Dir}])).

Expand Down
75 changes: 62 additions & 13 deletions big_tests/tests/graphql_http_upload_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

-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,
get_err_msg/1, get_err_code/1, get_unauthorized/1]).
get_err_msg/1, get_err_code/1, get_coercion_err_msg/1, get_unauthorized/1]).

-include_lib("eunit/include/eunit.hrl").

Expand Down Expand Up @@ -46,6 +47,8 @@ domain_admin_groups() ->

user_http_upload_tests() ->
[user_get_url_test,
user_get_url_test_no_content_type,
user_get_url_test_empty_filename,
user_get_url_zero_size,
user_get_url_too_large_size,
user_get_url_zero_timeout].
Expand All @@ -55,6 +58,8 @@ user_http_upload_not_configured_tests() ->

admin_http_upload_tests() ->
[admin_get_url_test,
admin_get_url_test_no_content_type,
admin_get_url_test_empty_filename,
admin_get_url_zero_size,
admin_get_url_too_large_size,
admin_get_url_zero_timeout,
Expand All @@ -65,6 +70,8 @@ admin_http_upload_not_configured_tests() ->

domain_admin_http_upload_tests() ->
[admin_get_url_test,
admin_get_url_test_no_content_type,
admin_get_url_test_empty_filename,
admin_get_url_zero_size,
admin_get_url_too_large_size,
admin_get_url_zero_timeout,
Expand Down Expand Up @@ -147,18 +154,40 @@ user_get_url_test(Config) ->
user_get_url_test(Config, Alice) ->
Result = user_get_url(<<"test">>, 123, <<"Test">>, 123, Alice, Config),
ParsedResult = get_ok_value([data, httpUpload, getUrl], Result),
#{<<"PutUrl">> := PutURL, <<"GetUrl">> := GetURL, <<"Header">> := _Headers} = ParsedResult,
#{<<"putUrl">> := PutURL, <<"getUrl">> := GetURL, <<"headers">> := _Headers} = ParsedResult,
?assertMatch({_, _}, binary:match(PutURL, [?S3_HOSTNAME])),
?assertMatch({_, _}, binary:match(GetURL, [?S3_HOSTNAME])).

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

user_get_url_test_no_content_type(Config, Alice) ->
user_get_url_test_no_content_type(Config, Alice, null),
user_get_url_test_no_content_type(Config, Alice, <<"">>).

user_get_url_test_no_content_type(Config, Alice, ContentType) ->
Result = user_get_url(<<"test">>, 123, ContentType, 123, Alice, Config),
ParsedResult = get_ok_value([data, httpUpload, getUrl], Result),
#{<<"putUrl">> := PutURL, <<"getUrl">> := GetURL, <<"headers">> := _Headers} = ParsedResult,
?assertMatch({_, _}, binary:match(PutURL, [?S3_HOSTNAME])),
?assertMatch({_, _}, binary:match(GetURL, [?S3_HOSTNAME])).

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

user_get_url_test_empty_filename(Config, Alice) ->
Result = user_get_url(<<"">>, 123, <<"Test">>, 123, Alice, Config),
?assertMatch({_, _}, binary:match(get_coercion_err_msg(Result), <<"Given string is empty">>)).

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

user_get_url_zero_size(Config, Alice) ->
Result = user_get_url(<<"test">>, 0, <<"Test">>, 123, Alice, Config),
?assertEqual(<<"size_error">>, get_err_code(Result)),
?assertEqual(<<"size must be positive integer">>, get_err_msg(Result)).
?assertMatch({_, _}, binary:match(get_coercion_err_msg(Result), <<"Value is not a positive integer">>)).

user_get_url_too_large_size(Config) ->
escalus:fresh_story_with_config(Config, [{alice, 1}],
Expand All @@ -175,8 +204,7 @@ user_get_url_zero_timeout(Config) ->

user_get_url_zero_timeout(Config, Alice) ->
Result = user_get_url(<<"test">>, 123, <<"Test">>, 0, Alice, Config),
?assertEqual(<<"timeout_error">>, get_err_code(Result)),
?assertEqual(<<"timeout must be positive integer">>, get_err_msg(Result)).
?assertMatch({_, _}, binary:match(get_coercion_err_msg(Result), <<"Value is not a positive integer">>)).

user_http_upload_not_configured(Config) ->
escalus:fresh_story_with_config(Config, [{alice, 1}],
Expand All @@ -190,16 +218,34 @@ 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,
#{<<"putUrl">> := PutURL, <<"getUrl">> := GetURL, <<"headers">> := _Headers} = ParsedResult,
?assertMatch({_, _}, binary:match(PutURL, [?S3_HOSTNAME])),
?assertMatch({_, _}, binary:match(GetURL, [?S3_HOSTNAME])).

admin_get_url_test_no_content_type(Config) ->
admin_get_url_test_no_content_type(Config, null),
admin_get_url_test_no_content_type(Config, <<"">>).

admin_get_url_test_no_content_type(Config, ContentType) ->
Result = admin_get_url(domain(), <<"test">>, 123, ContentType, 123, Config),
ParsedResult = get_ok_value([data, httpUpload, getUrl], Result),
#{<<"putUrl">> := PutURL, <<"getUrl">> := GetURL, <<"headers">> := _Headers} = ParsedResult,
?assertMatch({_, _}, binary:match(PutURL, [?S3_HOSTNAME])),
?assertMatch({_, _}, binary:match(GetURL, [?S3_HOSTNAME])).

admin_get_url_test_empty_filename(Config) ->
Result = admin_get_url(domain(), <<"">>, 123, <<"Test">>, 123, Config),
?assertMatch({_, _}, binary:match(get_coercion_err_msg(Result), <<"Given string is empty">>)).

admin_get_url_zero_size(Config) ->
Result = admin_get_url(domain(), <<"test">>, 0, <<"Test">>, 123, Config),
?assertEqual(<<"size_error">>, get_err_code(Result)),
?assertEqual(<<"size must be positive integer">>, get_err_msg(Result)).
?assertMatch({_, _}, binary:match(get_coercion_err_msg(Result), <<"Value is not a positive integer">>)).

admin_get_url_too_large_size(Config) ->
Result = admin_get_url(domain(), <<"test">>, 100000, <<"Test">>, 123, Config),
Expand All @@ -208,16 +254,19 @@ admin_get_url_too_large_size(Config) ->

admin_get_url_zero_timeout(Config) ->
Result = admin_get_url(domain(), <<"test">>, 123, <<"Test">>, 0, Config),
?assertEqual(<<"timeout_error">>, get_err_code(Result)),
?assertEqual(<<"timeout must be positive integer">>, get_err_msg(Result)).
?assertMatch({_, _}, binary:match(get_coercion_err_msg(Result), <<"Value is not a positive integer">>)).

admin_get_url_no_domain(Config) ->
Result = admin_get_url(<<"AAAAA">>, <<"test">>, 123, <<"Test">>, 123, Config),
?assertEqual(<<"domain_not_found">>, get_err_code(Result)),
?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
Loading

0 comments on commit 984d59f

Please sign in to comment.