Skip to content

Commit

Permalink
Merge pull request #2312 from esl/gdpr-remove-offline
Browse files Browse the repository at this point in the history
Remove personal data from mod_offline
  • Loading branch information
ludwikbukowski authored May 21, 2019
2 parents f5d93fa + a795c28 commit 8883d0e
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 21 deletions.
Binary file added big_tests/.DS_Store
Binary file not shown.
60 changes: 45 additions & 15 deletions big_tests/tests/gdpr_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
remove_roster/1,
retrieve_mam/1,
retrieve_offline/1,
remove_offline/1,
retrieve_pubsub_payloads/1,
retrieve_created_pubsub_nodes/1,
retrieve_all_pubsub_data/1,
Expand Down Expand Up @@ -97,12 +98,14 @@ groups() ->
{remove_personal_data, [], [
% per type
remove_vcard,
remove_roster
remove_roster,
remove_offline
]},
{remove_personal_data_with_mods_disabled, [], [
% per type
remove_vcard,
remove_roster
remove_roster,
remove_offline
]}
].

Expand Down Expand Up @@ -132,6 +135,9 @@ end_per_group(_GN, Config) ->

init_per_testcase(retrieve_inbox = CN, Config) ->
init_inbox(CN, Config);
init_per_testcase(remove_offline = CN, Config) ->
offline_started(),
escalus:init_per_testcase(CN, Config);
init_per_testcase(retrieve_inbox_for_multiple_messages = CN, Config) ->
init_inbox(CN, Config);
init_per_testcase(retrieve_vcard = CN, Config) ->
Expand All @@ -158,7 +164,7 @@ init_per_testcase(retrieve_mam = CN, Config) ->
escalus:init_per_testcase(CN, Config)
end;
init_per_testcase(remove_roster = CN, Config) ->
Backend = pick_backend_for_roster(),
Backend = pick_backend_as_riak_or_rdbms(),
dynamic_modules:ensure_modules(domain(), [{mod_roster, [{backend, Backend}]}]),
escalus:init_per_testcase(CN, Config);
init_per_testcase(CN, Config) ->
Expand Down Expand Up @@ -188,15 +194,6 @@ inbox_opts() ->
{groupchat, [muclight]},
{markers, [displayed]}].

pick_backend_for_roster() ->
IsRiak = mam_helper:is_riak_enabled(domain()),
IsRdbms = mongoose_helper:is_rdbms_enabled(domain()),
if
IsRiak -> riak;
IsRdbms -> rdbms;
true -> mnesia
end.

pick_backend_for_mam() ->
BackendsList = [
{mam_helper:is_cassandra_enabled(domain()), cassandra},
Expand All @@ -213,16 +210,18 @@ pick_backend_for_mam() ->
mam_required_modules(Backend) ->
[{mod_mam_meta, [{backend, Backend}, {pm, []}]}].

pick_backend_for_vcard() ->
pick_backend_as_riak_or_rdbms() ->
BackendsList = [
{mam_helper:is_riak_enabled(domain()), riak},
{mongoose_helper:is_rdbms_enabled(domain()), rdbms}
],
proplists:get_value(true, BackendsList, mnesia).


vcard_required_modules() ->
[{mod_vcard, [{backend, pick_backend_for_vcard()}]}].
[{mod_vcard, [{backend, pick_backend_as_riak_or_rdbms()}]}].

offline_required_modules() ->
[{mod_offline, [{backend, pick_backend_as_riak_or_rdbms()}]}].

pubsub_required_modules() ->
[{mod_caps, []}, {mod_pubsub, [
Expand All @@ -236,6 +235,9 @@ pubsub_required_modules() ->
vcard_started() ->
dynamic_modules:ensure_modules(domain(), vcard_required_modules()).

offline_started() ->
dynamic_modules:ensure_modules(domain(), offline_required_modules()).

%% -------------------------------------------------------------
%% Test cases
%% -------------------------------------------------------------
Expand Down Expand Up @@ -358,6 +360,34 @@ retrieve_offline(Config) ->
Alice, Config, "offline", ExpectedHeader, ExpectedItems)
end).

remove_offline(Config) ->
escalus:fresh_story(Config, [{alice, 1}, {bob, 1}, {kate, 1}], fun(Alice, Bob, Kate) ->
mongoose_helper:logout_user(Config, Alice),
Body1 = <<"Hey!">>,
Body2 = <<"Here is Johnny!">>,
Body3 = <<"Where is Johnny ?">>,
escalus:send(Bob, escalus_stanza:chat_to(Alice, Body1)),
escalus:send(Bob, escalus_stanza:chat_to(Alice, Body2)),
escalus:send(Kate, escalus_stanza:chat_to(Alice, Body3)),
%% Well, jid_to_lower works for any binary :)
AliceU = escalus_utils:jid_to_lower(escalus_client:username(Alice)),
AliceS = escalus_utils:jid_to_lower(escalus_client:server(Alice)),
mongoose_helper:wait_until(
fun() ->
mongoose_helper:successful_rpc(mod_offline_backend, count_offline_messages,
[AliceU, AliceS, 10])
end, 3),

maybe_stop_and_unload_module(mod_offline, mod_offline_backend, Config),
{0, _} = unregister(Alice, Config),

mongoose_helper:wait_until(
fun() ->
mongoose_helper:successful_rpc(mod_offline, get_personal_data,
[AliceU, AliceS])
end, [{offline, ["timestamp","from", "to", "packet"],[]}])
end).

retrieve_pubsub_payloads(Config) ->
escalus:fresh_story(Config, [{alice, 1}], fun(Alice) ->
Node1 = {_Domain, NodeName1} = pubsub_tools:pubsub_node(),
Expand Down
18 changes: 15 additions & 3 deletions src/mod_offline.erl
Original file line number Diff line number Diff line change
Expand Up @@ -576,13 +576,25 @@ remove_old_messages(Host, Days) ->
mod_offline_backend:remove_old_messages(Host, Timestamp).

%% #rh

remove_user(Acc, User, Server) ->
R = remove_user(User, Server),
mongoose_lib:log_if_backend_error(R, ?MODULE, ?LINE, {Acc, User, Server}),
remove_user(User, Server),
Acc.

remove_user(User, Server) ->
mod_offline_backend:remove_user(User, Server).
LUser = jid:nodeprep(User),
LServer = jid:nodeprep(Server),
lists:foreach(fun(B) ->
try
B:remove_user(LUser, LServer)
catch
E:R ->
Stack = erlang:get_stacktrace(),
?WARNING_MSG("issue=remove_user_failed "
"reason=~p:~p "
"stacktrace=~1000p ", [E, R, Stack]),
ok
end end, mongoose_lib:find_behaviour_implementations(mod_offline)).

%% Warn senders that their messages have been discarded:
discard_warn_sender(Acc, Msgs) ->
Expand Down
4 changes: 1 addition & 3 deletions src/mod_offline_mnesia.erl
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ count_offline_messages(LUser, LServer, _MaxNeeded) ->
_ -> 0
end.

remove_user(User, Server) ->
LUser = jid:nodeprep(User),
LServer = jid:nameprep(Server),
remove_user(LUser, LServer) ->
US = {LUser, LServer},
F = fun() ->
mnesia:delete({offline_msg, US})
Expand Down

0 comments on commit 8883d0e

Please sign in to comment.