Skip to content

Commit

Permalink
Merge pull request #3295 from esl/remove-domain-auth
Browse files Browse the repository at this point in the history
Support domain removal in the RDBMS auth backend
  • Loading branch information
vkatsuba authored Sep 23, 2021
2 parents a75e7d5 + baf4758 commit def9c13
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 20 deletions.
44 changes: 25 additions & 19 deletions big_tests/tests/domain_removal_SUITE.erl
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
-module(domain_removal_SUITE).

%% API
-export([all/0,
groups/0,
init_per_suite/1,
end_per_suite/1,
init_per_group/2,
end_per_group/2,
init_per_testcase/2,
end_per_testcase/2]).

-export([mam_pm_removal/1,
mam_muc_removal/1,
inbox_removal/1,
muc_light_removal/1,
muc_light_blocking_removal/1,
private_removal/1,
roster_removal/1]).
-compile(export_all).

-import(distributed_helper, [mim/0, rpc/4, subhost_pattern/1]).
-import(domain_helper, [host_type/0, domain/0]).
Expand All @@ -25,17 +9,20 @@
-include_lib("escalus/include/escalus.hrl").
-include_lib("escalus/include/escalus_xmlns.hrl").
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
-include_lib("exml/include/exml_stream.hrl").

all() ->
[{group, mam_removal},
[{group, auth_removal},
{group, mam_removal},
{group, inbox_removal},
{group, muc_light_removal},
{group, private_removal},
{group, roster_removal}].

groups() ->
[
{auth_removal, [], [auth_removal]},
{mam_removal, [], [mam_pm_removal,
mam_muc_removal]},
{inbox_removal, [], [inbox_removal]},
Expand Down Expand Up @@ -89,7 +76,10 @@ group_to_modules(inbox_removal) ->
group_to_modules(private_removal) ->
[{mod_private, [{backend, rdbms}]}];
group_to_modules(roster_removal) ->
[{mod_roster, [{backend, rdbms}]}].
[{mod_roster, [{backend, rdbms}]}];
group_to_modules(auth_removal) ->
[].


%%%===================================================================
%%% Testcase specific setup/teardown
Expand All @@ -111,6 +101,22 @@ end_per_testcase(TestCase, Config) ->
%%% Test Cases
%%%===================================================================

auth_removal(Config) ->
FreshConfig = escalus_fresh:create_users(Config, [{alice, 1}, {alice_bis, 1}]),
AliceSpec = escalus_users:get_userspec(FreshConfig, alice),
AliceBisSpec = escalus_users:get_userspec(FreshConfig, alice_bis),
connect_and_disconnect(AliceSpec),
connect_and_disconnect(AliceBisSpec),
?assertMatch([_Alice], rpc(mim(), ejabberd_auth, get_vh_registered_users, [domain()])),
run_remove_domain(),
?assertMatch({error, {connection_step_failed, _, _}}, escalus_connection:start(AliceSpec)),
connect_and_disconnect(AliceBisSpec), % different domain - not removed
?assertEqual([], rpc(mim(), ejabberd_auth, get_vh_registered_users, [domain()])).

connect_and_disconnect(Spec) ->
{ok, Client, _} = escalus_connection:start(Spec),
escalus_connection:stop(Client).

mam_pm_removal(Config) ->
F = fun(Alice, Bob) ->
escalus:send(Alice, escalus_stanza:chat_to(Bob, <<"OH, HAI!">>)),
Expand Down
2 changes: 2 additions & 0 deletions src/auth/ejabberd_auth.erl
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,8 @@ get_auth_method_as_a_list(undefined) -> [];
get_auth_method_as_a_list(AuthMethod) when is_list(AuthMethod) -> AuthMethod;
get_auth_method_as_a_list(AuthMethod) when is_atom(AuthMethod) -> [AuthMethod].

-spec remove_domain(mongoose_hooks:simple_acc(), mongooseim:host_type(), jid:lserver()) ->
mongoose_hooks:simple_acc().
remove_domain(Acc, HostType, Domain) ->
F = fun(Mod) -> mongoose_gen_auth:remove_domain(Mod, HostType, Domain) end,
call_auth_modules_for_host_type(HostType, F, #{op => map}),
Expand Down
10 changes: 9 additions & 1 deletion src/auth/ejabberd_auth_rdbms.erl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
get_password_s/3,
does_user_exist/3,
remove_user/3,
remove_domain/2,
supports_sasl_module/2,
supported_features/0
]).
Expand Down Expand Up @@ -285,6 +286,11 @@ remove_user(HostType, LUser, LServer) ->
end,
ok.

-spec remove_domain(mongooseim:host_type(), jid:lserver()) -> ok.
remove_domain(HostType, Domain) ->
execute_successfully(HostType, auth_remove_domain, [Domain]),
ok.

-spec supported_features() -> [atom()].
supported_features() -> [dynamic_domains].

Expand Down Expand Up @@ -420,7 +426,9 @@ prepare_queries(HostType) ->
<<"SELECT COUNT(*) FROM users WHERE server = ? AND username LIKE ? ESCAPE '$'">>),
prepare_count_users(HostType),
prepare(auth_count_users_without_scram, users, [server],
<<"SELECT COUNT(*) FROM users WHERE server = ? AND pass_details is NULL">>).
<<"SELECT COUNT(*) FROM users WHERE server = ? AND pass_details is NULL">>),
prepare(auth_remove_domain, users, [server],
<<"DELETE FROM users WHERE server = ?">>).

prepare_count_users(HostType) ->
case {ejabberd_auth:get_opt(HostType, rdbms_users_number_estimate),
Expand Down

0 comments on commit def9c13

Please sign in to comment.