Skip to content

Commit

Permalink
Merge pull request #3720 from esl/graphql-cli-test-gdpr
Browse files Browse the repository at this point in the history
Changing gdpr tests
  • Loading branch information
Premwoik authored Aug 1, 2022
2 parents 2f53e0a + 06189f5 commit 491e5c3
Showing 1 changed file with 28 additions and 35 deletions.
63 changes: 28 additions & 35 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_tests()},
{admin_gdpr_cli, [], admin_stats_tests()}].

admin_stats_handler() ->
[admin_gdpr_test,
admin_stats_tests() ->
[admin_retrive_user_data,
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 @@ -44,43 +50,30 @@ end_per_testcase(CaseName, Config) ->

% Admin test cases

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

admin_gdpr_test(Config, Alice) ->
admin_retrive_user_data(Config, Alice) ->
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

0 comments on commit 491e5c3

Please sign in to comment.