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

Changing gdpr tests #3720

Merged
merged 2 commits into from
Aug 1, 2022
Merged
Changes from 1 commit
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
53 changes: 23 additions & 30 deletions big_tests/tests/graphql_gdpr_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

-compile([export_all, nowarn_export_all]).

-import(distributed_helper, [require_rpc_nodes/1]).
-import(domain_helper, [host_type/0, domain/0]).
-import(graphql_helper, [execute_user/3, execute_auth/2, user_to_bin/1]).
-import(distributed_helper, [mim/0, rpc/4]).
-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,
get_ok_value/2, get_err_code/1]).

-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
Expand All @@ -14,25 +14,31 @@ suite() ->
require_rpc_nodes([mim]) ++ escalus:suite().

all() ->
[{group, admin_gdpr}].
[{group, admin_gdpr_http},
{group, admin_gdpr_cli}].

groups() ->
[{admin_gdpr, [], admin_stats_handler()}].
[{admin_gdpr_http, [], admin_stats_handler()},
JanuszJakubiec marked this conversation as resolved.
Show resolved Hide resolved
{admin_gdpr_cli, [], admin_stats_handler()}].

admin_stats_handler() ->
[admin_gdpr_test,
admin_gdpr_no_user_test].

init_per_suite(Config) ->
escalus:init_per_suite(Config).
Config1 = escalus:init_per_suite(Config),
ejabberd_node_utils:init(mim(), Config1).

end_per_suite(Config) ->
escalus:end_per_suite(Config).

init_per_group(_, Config) ->
graphql_helper:init_admin_handler(Config).
init_per_group(admin_gdpr_http, Config) ->
graphql_helper:init_admin_handler(Config);
init_per_group(admin_gdpr_cli, Config) ->
graphql_helper:init_admin_cli(Config).

end_per_group(_, _Config) ->
graphql_helper:clean(),
escalus_fresh:clean().

init_per_testcase(CaseName, Config) ->
Expand All @@ -49,38 +55,25 @@ admin_gdpr_test(Config) ->

admin_gdpr_test(Config, Alice) ->
JanuszJakubiec marked this conversation as resolved.
Show resolved Hide resolved
Filename = random_filename(Config),
Vars = #{<<"username">> => escalus_client:username(Alice),
<<"domain">> => escalus_client:server(Alice),
<<"resultFilepath">> => list_to_binary(Filename)},
Result = admin_retrieve_personal_data(Config, Vars),
ParsedResult = ok_result(<<"gdpr">>, <<"retrievePersonalData">>, Result),
Res = admin_retrieve_personal_data(escalus_client:username(Alice), escalus_client:server(Alice),
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)),
ct:log("extracting logs ~s", [Dir]),
?assertMatch({ok, _}, zip:extract(FullPath, [{cwd, Dir}])).

admin_gdpr_no_user_test(Config) ->
Vars = #{<<"username">> => <<"AAAA">>, <<"domain">> => domain(),
<<"resultFilepath">> => <<"AAA">>},
Result = admin_retrieve_personal_data(Config, Vars),
ParsedResult = error_result(<<"extensions">>, <<"code">>, Result),
?assertEqual(<<"user_does_not_exist_error">>, ParsedResult).
Res = admin_retrieve_personal_data(<<"AAAA">>, domain(), <<"AAA">>, Config),
?assertEqual(<<"user_does_not_exist_error">>, get_err_code(Res)).

% Helpers

admin_retrieve_personal_data(Config, Vars) ->
Query = <<"query Q1($username: String!, $domain: String!, $resultFilepath: String!)
{gdpr{retrievePersonalData(username: $username, domain: $domain,
resultFilepath: $resultFilepath)}}">>,
Body = #{query => Query, operationName => <<"Q1">>, variables => Vars},
execute_auth(Body, Config).

error_result(What1, What2, {{<<"200">>, <<"OK">>}, #{<<"errors">> := [Data]}}) ->
maps:get(What2, maps:get(What1, Data)).

ok_result(What1, What2, {{<<"200">>, <<"OK">>}, #{<<"data">> := Data}}) ->
maps:get(What2, maps:get(What1, Data)).
admin_retrieve_personal_data(Username, Domain, ResultFilepath, Config) ->
Vars = #{<<"username">> => Username, <<"domain">> => Domain,
<<"resultFilepath">> => ResultFilepath},
execute_command(<<"gdpr">>, <<"retrievePersonalData">>, Vars, Config).

random_filename(Config) ->
TCName = atom_to_list(?config(tc_name, Config)),
Expand Down