Skip to content

Commit

Permalink
Merge branch 'master' into toml-config
Browse files Browse the repository at this point in the history
  • Loading branch information
chrzaszcz committed Nov 5, 2020
2 parents d534fe3 + 74e6c8c commit e90e8a8
Show file tree
Hide file tree
Showing 133 changed files with 1,418 additions and 1,412 deletions.
2 changes: 1 addition & 1 deletion big_tests/default.spec
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
{suites, "tests", mod_aws_sns_SUITE}.
{suites, "tests", mod_blocking_SUITE}.
{suites, "tests", mod_event_pusher_rabbit_SUITE}.
{suites, "tests", mod_event_pusher_http_SUITE}.
{suites, "tests", mod_global_distrib_SUITE}.
{suites, "tests", mod_http_notification_SUITE}.
{suites, "tests", mod_http_upload_SUITE}.
{suites, "tests", mod_ping_SUITE}.
{suites, "tests", mod_time_SUITE}.
Expand Down
2 changes: 1 addition & 1 deletion big_tests/test.config
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@
{mod_privacy, "[modules.mod_privacy]
backend = \"rdbms\""},
{mod_private, "[modules.mod_private]
backend = \"mysql\""},
backend = \"rdbms\""},
{mod_offline, "[modules.mod_offline]
backend = \"rdbms\""},
{mod_vcard, "[modules.mod_vcard]
Expand Down
8 changes: 4 additions & 4 deletions big_tests/tests/accounts_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ admin_notify(Config) ->
[Username2, _Server2, _Pass2] = escalus_users:get_usp(Config, UserSpec2),
[AdminU, AdminS, AdminP] = escalus_users:get_usp(Config, AdminSpec),

rpc(mim(), ejabberd_auth, try_register, [AdminU, AdminS, AdminP]),
rpc(mim(), ejabberd_auth, try_register, [mongoose_helper:make_jid(AdminU, AdminS), AdminP]),
escalus:story(Config, [{admin, 1}], fun(Admin) ->
escalus:create_users(Config, escalus:get_users([Name1, Name2])),

Expand Down Expand Up @@ -198,12 +198,12 @@ null_password(Config) ->
{username, Name} = lists:keyfind(username, 1, Details),
{server, Server} = lists:keyfind(server, 1, Details),
escalus:assert(is_error, [<<"modify">>, <<"not-acceptable">>], Response),
false = rpc(mim(), ejabberd_auth, is_user_exists, [Name, Server]).
false = rpc(mim(), ejabberd_auth, does_user_exist, [mongoose_helper:make_jid(Name, Server)]).

check_unregistered(Config) ->
[{_, UserSpec}] = escalus_users:get_users([bob]),
[Username, Server, _Pass] = escalus_users:get_usp(Config, UserSpec),
false = rpc(mim(), ejabberd_auth, is_user_exists, [Username, Server]).
false = rpc(mim(), ejabberd_auth, does_user_exist, [mongoose_helper:make_jid(Username, Server)]).

bad_request_registration_cancelation(Config) ->

Expand Down Expand Up @@ -373,7 +373,7 @@ bad_cancelation_stanza() ->
user_exists(Name, Config) ->
{Name, Client} = escalus_users:get_user_by_name(Name),
[Username, Server, _Pass] = escalus_users:get_usp(Config, Client),
rpc(mim(), ejabberd_auth, is_user_exists, [Username, Server]).
rpc(mim(), ejabberd_auth, does_user_exist, [mongoose_helper:make_jid(Username, Server)]).

reload_mod_register_option(Config, Key, Value) ->
Host = domain(),
Expand Down
6 changes: 4 additions & 2 deletions big_tests/tests/ejabberdctl_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ end_per_testcase(delete_old_users, Config) ->
Users = escalus_users:get_users([alice, bob, kate, mike]),
lists:foreach(fun({_User, UserSpec}) ->
{Username, Domain, Pass} = get_user_data(UserSpec, Config),
rpc(mim(), ejabberd_auth, try_register, [Username, Domain, Pass])
JID = mongoose_helper:make_jid(Username, Domain),
rpc(mim(), ejabberd_auth, try_register, [JID, Pass])
end, Users),
escalus:end_per_testcase(delete_old_users, Config);
end_per_testcase(check_password_hash, Config) ->
Expand Down Expand Up @@ -1310,7 +1311,8 @@ set_last(User, Domain, TStamp) ->
delete_users(Config) ->
Users = escalus_users:get_users([alice, bob, kate, mike]),
lists:foreach(fun({User, Domain}) ->
rpc(mim(), ejabberd_auth, remove_user, [User, Domain])
JID = mongoose_helper:make_jid(User, Domain),
rpc(mim(), ejabberd_auth, remove_user, [JID])
end, get_registered_users()).

%%-----------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions big_tests/tests/login_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,8 @@ verify_format(GroupName, {_User, Props}) ->
Username = escalus_utils:jid_to_lower(proplists:get_value(username, Props)),
Server = proplists:get_value(server, Props),
Password = proplists:get_value(password, Props),

SPassword = rpc(mim(), ejabberd_auth, get_password, [Username, Server]),
JID = mongoose_helper:make_jid(Username, Server),
SPassword = rpc(mim(), ejabberd_auth, get_password, [JID]),
do_verify_format(GroupName, Password, SPassword).


Expand Down
11 changes: 6 additions & 5 deletions big_tests/tests/mam_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2990,13 +2990,14 @@ check_user_exist(Config) ->
%% when
[{_, AdminSpec}] = escalus_users:get_users([admin]),
[AdminU, AdminS, AdminP] = escalus_users:get_usp(Config, AdminSpec),
ok = rpc(mim(), ejabberd_auth, try_register, [AdminU, AdminS, AdminP]),
JID = mongoose_helper:make_jid(AdminU, AdminS),
ok = rpc(mim(), ejabberd_auth, try_register, [JID, AdminP]),
%% admin user already registered
true = rpc(mim(), ejabberd_users, does_user_exist, [AdminU, AdminS]),
false = rpc(mim(), ejabberd_users, does_user_exist, [<<"fake-user">>, AdminS]),
false = rpc(mim(), ejabberd_users, does_user_exist, [AdminU, <<"fake-domain">>]),
true = rpc(mim(), ejabberd_users, does_user_exist, [JID]),
false = rpc(mim(), ejabberd_users, does_user_exist, [mongoose_helper:make_jid(<<"fake-user">>, AdminS)]),
false = rpc(mim(), ejabberd_users, does_user_exist, [mongoose_helper:make_jid(AdminU, <<"fake-domain">>)]),
%% cleanup
ok = rpc(mim(), ejabberd_auth, remove_user, [AdminU, AdminS]).
ok = rpc(mim(), ejabberd_auth, remove_user, [JID]).

%% This function supports only one device, one user.
%% We don't send initial presence to avoid presence broadcasts between resources
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
%%%----------------------------------------------------------------------
%%% File : mod_http_notification_SUITE
%%% File : mod_event_pusher_http_SUITE
%%% Author : Baibossynv Valery <[email protected]>
%%% Purpose : Testing passing via http
%%% Created : 16 Dec 2015 by Baibossynv Valery <[email protected]>
%%%----------------------------------------------------------------------

-module(mod_http_notification_SUITE).
-module(mod_event_pusher_http_SUITE).
-author("[email protected]").

-compile(export_all).
Expand All @@ -14,7 +14,7 @@
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").

-define(ETS_TABLE, mod_http_notification).
-define(ETS_TABLE, mod_event_pusher_http).

-import(distributed_helper, [mim/0,
require_rpc_nodes/1,
Expand Down Expand Up @@ -176,8 +176,11 @@ stop_pool() ->

set_modules(Config0, Opts) ->
Config = dynamic_modules:save_modules(host(), Config0),
ModOpts = [{worker_timeout, 500}, {host, http_notifications_host()}] ++ Opts,
dynamic_modules:ensure_modules(host(), [{mod_http_notification, ModOpts}]),
ModOpts = [{backends,
[{http,
[{worker_timeout, 500},
{host, http_notifications_host()}] ++ Opts}]}],
dynamic_modules:ensure_modules(host(), [{mod_event_pusher, ModOpts}]),
Config.

start_http_listener(simple_message, Prefix) ->
Expand Down
4 changes: 4 additions & 0 deletions big_tests/tests/mongoose_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
-export([wait_until/2, wait_until/3, wait_for_user/3]).

-export([inject_module/1, inject_module/2, inject_module/3]).
-export([make_jid/2]).
-export([make_jid/3]).
-export([make_jid_noprep/3]).
-export([get_session_pid/2]).
Expand Down Expand Up @@ -373,6 +374,9 @@ inject_module(Node, Module, reload) ->
make_jid_noprep(User, Server, Resource) ->
jid:make_noprep(User, Server, Resource).

make_jid(User, Server) ->
jid:make(User, Server, <<>>).

make_jid(User, Server, Resource) ->
jid:make(User, Server, Resource).

Expand Down
12 changes: 8 additions & 4 deletions big_tests/tests/muc_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -459,20 +459,20 @@ domain() ->
ct:get_config({hosts, mim, domain}).

init_per_testcase(CaseName = load_already_registered_permanent_rooms, Config) ->
ok = rpc(mim(), meck, new, [mod_muc_room, [no_link, passthrough]]),
meck_room(),
meck_room_start(),
escalus:init_per_testcase(CaseName, Config);
init_per_testcase(CaseName = create_already_registered_room, Config) ->
ok = rpc(mim(), meck, new, [mod_muc_room, [no_link, passthrough]]),
meck_room(),
meck_room_start(),
escalus:init_per_testcase(CaseName, Config);
init_per_testcase(CaseName = check_presence_route_to_offline_room, Config) ->
ok = rpc(mim(), meck, new, [mod_muc_room, [no_link, passthrough]]),
meck_room(),
meck_room_start(),
meck_room_route(),
escalus:init_per_testcase(CaseName, Config);
init_per_testcase(CaseName = check_message_route_to_offline_room, Config) ->
ok = rpc(mim(), meck, new, [mod_muc_room, [no_link, passthrough]]),
meck_room(),
meck_room_start(),
meck_room_route(),
escalus:init_per_testcase(CaseName, Config);
Expand Down Expand Up @@ -534,6 +534,10 @@ init_per_testcase(CaseName, Config) when CaseName =:= disco_features_with_mam;
init_per_testcase(CaseName, Config) ->
escalus:init_per_testcase(CaseName, Config).

meck_room() ->
RPCSpec = (mim())#{timeout => timer:seconds(10)}, % it takes long to compile this module
ok = rpc(RPCSpec, meck, new, [mod_muc_room, [no_link, passthrough]]).

%% Meck will register a fake room right before a 'real' room is started
meck_room_start() ->
rpc(mim(), meck, expect, [mod_muc_room, start,
Expand Down
69 changes: 64 additions & 5 deletions big_tests/tests/muc_http_api_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@
%%--------------------------------------------------------------------

all() ->
[{group, positive}].
[{group, positive},
{group, negative}].

groups() ->
G = [{positive, [parallel], success_response() ++ complex()}],
G = [{positive, [parallel], success_response() ++ complex()},
{negative, [parallel], failure_response()}],
ct_helper:repeat_all_until_all_ok(G).

success_response() ->
Expand All @@ -52,6 +54,9 @@ complex() ->
multiparty_multiprotocol
].

failure_response() ->
[failed_invites,
failed_messages].

%%--------------------------------------------------------------------
%% Init & teardown
Expand Down Expand Up @@ -93,7 +98,15 @@ create_room(Config) ->
Body = #{name => Name,
owner => escalus_client:short_jid(Alice),
nick => <<"ali">>},
{{<<"201">>, _}, Name} = rest_helper:post(admin, Path, Body),
Res = rest_helper:make_request(#{role => admin,
method => <<"POST">>,
path => Path,
body => Body,
return_headers => true}),
{{<<"201">>, _}, Headers, Name} = Res,
Exp = <<"/api/mucs/", Host/binary, "/", Name/binary>>,
Uri = uri_string:parse(proplists:get_value(<<"location">>, Headers)),
?assertEqual(Exp, maps:get(path, Uri)),
%% Service acknowledges room creation (10.1.1 Ex. 154), then
%% (presumably 7.2.16) sends room subject, finally the IQ
%% result of the IQ request (10.1.2) for an instant room. The
Expand All @@ -113,6 +126,8 @@ invite_online_user_to_room(Config) ->
Body = #{sender => escalus_client:short_jid(Alice),
recipient => escalus_client:short_jid(Bob),
reason => Reason},
{{<<"404">>, _}, <<"room does not exist">>} = rest_helper:post(admin, Path, Body),
set_up_room(Config, Alice),
{{<<"204">>, _}, <<"">>} = rest_helper:post(admin, Path, Body),
Stanza = escalus:wait_for_stanza(Bob),
is_direct_invitation(Stanza),
Expand All @@ -136,8 +151,6 @@ send_message_to_room(Config) ->
Message = <<"Greetings!">>,
Body = #{from => escalus_client:short_jid(Bob),
body => Message},
%% The HTTP call in question. Notice: status 200 because no
%% resource is created.
{{<<"204">>, _}, <<"">>} = rest_helper:post(admin, Path, Body),
Got = escalus:wait_for_stanza(Bob),
escalus:assert(is_message, Got),
Expand Down Expand Up @@ -265,11 +278,57 @@ multiparty_multiprotocol(Config) ->
user_sees_message_from(Alice, Room, 2))
end).

failed_invites(Config) ->
escalus:fresh_story(Config, [{alice, 1}, {bob, 1}], fun(Alice, Bob) ->
Name = set_up_room(Config, Alice),
BAlice = escalus_client:short_jid(Alice),
BBob = escalus_client:short_jid(Bob),
% non-existing room
{{<<"404">>, _}, <<"room does not exist">>} = send_invite(<<"thisroomdoesnotexist">>, BAlice, BBob),
% invite with bad jid
{{<<"400">>, _}, <<"Invalid jid:", _/binary>>} = send_invite(Name, BAlice, <<"@badjid">>),
{{<<"400">>, _}, <<"Invalid jid:", _/binary>>} = send_invite(Name, <<"@badjid">>, BBob),
ok
end).

failed_messages(Config) ->
escalus:fresh_story(Config, [{alice, 1}, {bob, 1}], fun(Alice, Bob) ->
Name = set_up_room(Config, Alice),
% non-existing room
BAlice = escalus_client:short_jid(Alice),
BBob = escalus_client:short_jid(Bob),
{{<<"404">>, _}, <<"room does not exist">>} = send_invite(<<"thisroomdoesnotexist">>, BAlice, BBob),
% invite with bad jid
{{<<"400">>, _}, <<"Invalid jid:", _/binary>>} = send_invite(Name, BAlice, <<"@badjid">>),
{{<<"400">>, _}, <<"Invalid jid:", _/binary>>} = send_invite(Name, <<"@badjid">>, BBob),
ok
end).


%%--------------------------------------------------------------------
%% Ancillary (adapted from the MUC suite)
%%--------------------------------------------------------------------

set_up_room(Config, Alice) ->
% create a room first
Name = ?config(room_name, Config),
Host = <<"localhost">>,
Path = <<"/mucs/", Host/binary>>,
Body = #{name => Name,
owner => escalus_client:short_jid(Alice),
nick => <<"ali">>},
Res = rest_helper:post(admin, Path, Body),
{{<<"201">>, _}, Name} = Res,
Name.

send_invite(RoomName, BinFrom, BinTo) ->
Path = <<"/mucs/localhost/", RoomName/binary, "/participants">>,
Reason = <<"I think you'll like this room!">>,
Body = #{sender => BinFrom,
recipient => BinTo,
reason => Reason},
rest_helper:post(admin, Path, Body).

make_distinct_name(Prefix) ->
{_, S, US} = os:timestamp(),
L = lists:flatten([integer_to_list(S rem 100), ".", integer_to_list(US)]),
Expand Down
26 changes: 22 additions & 4 deletions big_tests/tests/muc_light_http_api_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ success_response() ->
negative_response() ->
[delete_room_by_non_owner,
delete_non_existent_room,
delete_room_without_having_a_membership
delete_room_without_having_a_membership,
create_non_unique_room
].

%%--------------------------------------------------------------------
Expand Down Expand Up @@ -200,7 +201,7 @@ delete_room_by_non_owner(Config) ->
[{alice, 1}, {bob, 1}, {kate, 1}],
fun(Alice, Bob, Kate)->
{{<<"403">>, <<"Forbidden">>},
<<"Command not available for this user">>} =
<<"you can not delete this room">>} =
check_delete_room(Config, RoomName, RoomName,
Alice, [Bob, Kate], Bob)
end).
Expand All @@ -210,7 +211,7 @@ delete_non_existent_room(Config) ->
escalus:fresh_story(Config,
[{alice, 1}, {bob, 1}, {kate, 1}],
fun(Alice, Bob, Kate)->
{{<<"500">>, _}, _} =
{{<<"404">>, _}, <<"room does not exist">>} =
check_delete_room(Config, RoomName, <<"some_non_existent_room">>,
Alice, [Bob, Kate], Alice)
end).
Expand All @@ -220,12 +221,29 @@ delete_room_without_having_a_membership(Config) ->
escalus:fresh_story(Config,
[{alice, 1}, {bob, 1}, {kate, 1}],
fun(Alice, Bob, Kate)->
{{<<"500">>, _}, _} =
{{<<"403">>, _}, <<"given user does not occupy this room">>} =
check_delete_room(Config, RoomName, RoomName,
Alice, [Bob], Kate)
end).


create_non_unique_room(Config) ->
escalus:fresh_story(Config, [{alice, 1}], fun(Alice) ->
Domain = <<"localhost">>,
Path = <<"/muc-lights", $/, Domain/binary>>,
RandBits = base16:encode(crypto:strong_rand_bytes(5)),
Name = <<"wonderland">>,
RoomID = <<"just_some_id_", RandBits/binary>>,
Body = #{ id => RoomID,
name => Name,
owner => escalus_client:short_jid(Alice),
subject => <<"Lewis Carol">>
},
{{<<"201">>, _}, _RoomJID} = rest_helper:putt(admin, Path, Body),
{{<<"403">>, _}, <<"Room already exists">>} = rest_helper:putt(admin, Path, Body),
ok
end).

%%--------------------------------------------------------------------
%% Ancillary (borrowed and adapted from the MUC and MUC Light suites)
%%--------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion big_tests/tests/oauth_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,8 @@ verify_format(GroupName, {_User, Props}) ->
Username = escalus_utils:jid_to_lower(proplists:get_value(username, Props)),
Server = proplists:get_value(server, Props),
Password = proplists:get_value(password, Props),
SPassword = rpc(mim(), ejabberd_auth, get_password, [Username, Server]),
JID = mongoose_helper:make_jid(Username, Server),
SPassword = rpc(mim(), ejabberd_auth, get_password, [JID]),
do_verify_format(GroupName, Password, SPassword).

do_verify_format(login_scram, _Password, SPassword) ->
Expand Down
Loading

0 comments on commit e90e8a8

Please sign in to comment.