From 2cd1488d787159216992d638830deb5fe3a8b708 Mon Sep 17 00:00:00 2001 From: Janusz Jakubiec Date: Wed, 27 Jul 2022 14:16:00 +0200 Subject: [PATCH 1/2] Changing gdpr tests --- big_tests/tests/graphql_gdpr_SUITE.erl | 53 +++++++++++--------------- 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/big_tests/tests/graphql_gdpr_SUITE.erl b/big_tests/tests/graphql_gdpr_SUITE.erl index 8e38a162fe..d2c4564dda 100644 --- a/big_tests/tests/graphql_gdpr_SUITE.erl +++ b/big_tests/tests/graphql_gdpr_SUITE.erl @@ -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"). @@ -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()}, + {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) -> @@ -49,11 +55,9 @@ admin_gdpr_test(Config) -> admin_gdpr_test(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)), @@ -61,26 +65,15 @@ admin_gdpr_test(Config, Alice) -> ?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)), From 06189f59c23115c2be700ca446f6788dd7e86298 Mon Sep 17 00:00:00 2001 From: Janusz Jakubiec Date: Mon, 1 Aug 2022 09:54:03 +0200 Subject: [PATCH 2/2] Fixing CR issues --- big_tests/tests/graphql_gdpr_SUITE.erl | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/big_tests/tests/graphql_gdpr_SUITE.erl b/big_tests/tests/graphql_gdpr_SUITE.erl index d2c4564dda..ce06709329 100644 --- a/big_tests/tests/graphql_gdpr_SUITE.erl +++ b/big_tests/tests/graphql_gdpr_SUITE.erl @@ -18,11 +18,11 @@ all() -> {group, admin_gdpr_cli}]. groups() -> - [{admin_gdpr_http, [], admin_stats_handler()}, - {admin_gdpr_cli, [], 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) -> @@ -50,10 +50,10 @@ 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), Res = admin_retrieve_personal_data(escalus_client:username(Alice), escalus_client:server(Alice), list_to_binary(Filename), Config),