2013-04-08 11:12:54 +02:00
|
|
|
%%%-------------------------------------------------------------------
|
2017-01-03 15:58:52 +01:00
|
|
|
%%% Author : Evgeny Khramtsov <ekhramtsov@process-one.net>
|
2013-04-08 11:12:54 +02:00
|
|
|
%%% Created : 2 Jun 2013 by Evgeniy Khramtsov <ekhramtsov@process-one.net>
|
2017-01-03 15:58:52 +01:00
|
|
|
%%%
|
|
|
|
%%%
|
|
|
|
%%% ejabberd, Copyright (C) 2002-2017 ProcessOne
|
|
|
|
%%%
|
|
|
|
%%% This program is free software; you can redistribute it and/or
|
|
|
|
%%% modify it under the terms of the GNU General Public License as
|
|
|
|
%%% published by the Free Software Foundation; either version 2 of the
|
|
|
|
%%% License, or (at your option) any later version.
|
|
|
|
%%%
|
|
|
|
%%% This program is distributed in the hope that it will be useful,
|
|
|
|
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
%%% General Public License for more details.
|
|
|
|
%%%
|
|
|
|
%%% You should have received a copy of the GNU General Public License along
|
|
|
|
%%% with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
%%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
%%%
|
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
2013-04-08 11:12:54 +02:00
|
|
|
-module(ejabberd_SUITE).
|
|
|
|
|
|
|
|
-compile(export_all).
|
|
|
|
|
2016-10-17 12:37:23 +02:00
|
|
|
-import(suite, [init_config/1, connect/1, disconnect/1, recv_message/1,
|
|
|
|
recv/1, recv_presence/1, send/2, send_recv/2, my_jid/1,
|
|
|
|
server_jid/1, pubsub_jid/1, proxy_jid/1, muc_jid/1,
|
|
|
|
muc_room_jid/1, my_muc_jid/1, peer_muc_jid/1,
|
|
|
|
mix_jid/1, mix_room_jid/1, get_features/2, recv_iq/1,
|
|
|
|
re_register/1, is_feature_advertised/2, subscribe_to_events/1,
|
2017-03-07 12:20:50 +01:00
|
|
|
is_feature_advertised/3, set_opt/3,
|
|
|
|
auth_SASL/2, auth_SASL/3, auth_SASL/4,
|
2016-10-17 12:37:23 +02:00
|
|
|
wait_for_master/1, wait_for_slave/1, flush/1,
|
|
|
|
make_iq_result/1, start_event_relay/0, alt_room_jid/1,
|
2013-06-26 19:55:29 +02:00
|
|
|
stop_event_relay/1, put_event/2, get_event/1,
|
2016-09-20 13:04:07 +02:00
|
|
|
bind/1, auth/1, auth/2, open_session/1, open_session/2,
|
2016-09-23 11:30:33 +02:00
|
|
|
zlib/1, starttls/1, starttls/2, close_socket/1, init_stream/1,
|
2016-10-22 12:01:45 +02:00
|
|
|
auth_legacy/2, auth_legacy/3, tcp_connect/1, send_text/2,
|
|
|
|
set_roster/3, del_roster/1]).
|
2013-06-26 19:55:29 +02:00
|
|
|
-include("suite.hrl").
|
2013-06-19 12:11:20 +02:00
|
|
|
|
2013-04-08 11:12:54 +02:00
|
|
|
suite() ->
|
2016-10-22 12:01:45 +02:00
|
|
|
[{timetrap, {seconds, 120}}].
|
2013-04-08 11:12:54 +02:00
|
|
|
|
|
|
|
init_per_suite(Config) ->
|
2013-06-26 19:55:29 +02:00
|
|
|
NewConfig = init_config(Config),
|
|
|
|
DataDir = proplists:get_value(data_dir, NewConfig),
|
2013-06-14 17:23:57 +02:00
|
|
|
{ok, CWD} = file:get_cwd(),
|
2013-06-26 19:55:29 +02:00
|
|
|
ExtAuthScript = filename:join([DataDir, "extauth.py"]),
|
|
|
|
LDIFFile = filename:join([DataDir, "ejabberd.ldif"]),
|
2013-06-26 04:29:50 +02:00
|
|
|
{ok, _} = file:copy(ExtAuthScript, filename:join([CWD, "extauth.py"])),
|
2013-06-25 19:05:37 +02:00
|
|
|
{ok, _} = ldap_srv:start(LDIFFile),
|
2016-09-23 11:30:33 +02:00
|
|
|
inet_db:add_host({127,0,0,1}, [binary_to_list(?S2S_VHOST),
|
|
|
|
binary_to_list(?MNESIA_VHOST)]),
|
|
|
|
inet_db:set_domain(binary_to_list(randoms:get_string())),
|
|
|
|
inet_db:set_lookup([file, native]),
|
2016-03-24 10:02:13 +01:00
|
|
|
start_ejabberd(NewConfig),
|
2013-06-26 19:55:29 +02:00
|
|
|
NewConfig.
|
2013-04-08 11:12:54 +02:00
|
|
|
|
2016-03-24 10:02:13 +01:00
|
|
|
start_ejabberd(Config) ->
|
|
|
|
case proplists:get_value(backends, Config) of
|
|
|
|
all ->
|
|
|
|
ok = application:start(ejabberd, transient);
|
|
|
|
Backends when is_list(Backends) ->
|
|
|
|
Hosts = lists:map(fun(Backend) -> Backend ++ ".localhost" end, Backends),
|
|
|
|
application:load(ejabberd),
|
|
|
|
AllHosts = Hosts ++ ["localhost"], %% We always need localhost for the generic no_db tests
|
|
|
|
application:set_env(ejabberd, hosts, AllHosts),
|
|
|
|
ok = application:start(ejabberd, transient)
|
|
|
|
end.
|
|
|
|
|
2013-04-08 11:12:54 +02:00
|
|
|
end_per_suite(_Config) ->
|
2016-03-24 10:02:13 +01:00
|
|
|
application:stop(ejabberd).
|
2013-04-08 11:12:54 +02:00
|
|
|
|
2016-03-24 10:02:13 +01:00
|
|
|
-define(BACKENDS, [mnesia,redis,mysql,pgsql,sqlite,ldap,extauth,riak]).
|
|
|
|
|
|
|
|
init_per_group(Group, Config) ->
|
|
|
|
case lists:member(Group, ?BACKENDS) of
|
|
|
|
false ->
|
|
|
|
%% Not a backend related group, do default init:
|
|
|
|
do_init_per_group(Group, Config);
|
|
|
|
true ->
|
|
|
|
case proplists:get_value(backends, Config) of
|
|
|
|
all ->
|
|
|
|
%% All backends enabled
|
|
|
|
do_init_per_group(Group, Config);
|
|
|
|
Backends ->
|
|
|
|
%% Skipped backends that were not explicitely enabled
|
|
|
|
case lists:member(atom_to_list(Group), Backends) of
|
|
|
|
true ->
|
|
|
|
do_init_per_group(Group, Config);
|
|
|
|
false ->
|
|
|
|
{skip, {disabled_backend, Group}}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end.
|
|
|
|
|
|
|
|
do_init_per_group(no_db, Config) ->
|
2013-06-26 19:55:29 +02:00
|
|
|
re_register(Config),
|
2016-10-17 12:37:23 +02:00
|
|
|
set_opt(persistent_room, false, Config);
|
2016-03-24 10:02:13 +01:00
|
|
|
do_init_per_group(mnesia, Config) ->
|
2013-06-19 13:30:31 +02:00
|
|
|
mod_muc:shutdown_rooms(?MNESIA_VHOST),
|
2013-06-19 12:11:20 +02:00
|
|
|
set_opt(server, ?MNESIA_VHOST, Config);
|
2016-03-24 10:02:13 +01:00
|
|
|
do_init_per_group(redis, Config) ->
|
2016-02-19 15:06:41 +01:00
|
|
|
mod_muc:shutdown_rooms(?REDIS_VHOST),
|
|
|
|
set_opt(server, ?REDIS_VHOST, Config);
|
2016-03-24 10:02:13 +01:00
|
|
|
do_init_per_group(mysql, Config) ->
|
2016-04-20 11:27:32 +02:00
|
|
|
case catch ejabberd_sql:sql_query(?MYSQL_VHOST, [<<"select 1;">>]) of
|
2013-06-19 12:11:20 +02:00
|
|
|
{selected, _, _} ->
|
2013-06-19 13:30:31 +02:00
|
|
|
mod_muc:shutdown_rooms(?MYSQL_VHOST),
|
2013-06-19 12:11:20 +02:00
|
|
|
create_sql_tables(mysql, ?config(base_dir, Config)),
|
|
|
|
set_opt(server, ?MYSQL_VHOST, Config);
|
|
|
|
Err ->
|
|
|
|
{skip, {mysql_not_available, Err}}
|
|
|
|
end;
|
2016-03-24 10:02:13 +01:00
|
|
|
do_init_per_group(pgsql, Config) ->
|
2016-04-20 11:27:32 +02:00
|
|
|
case catch ejabberd_sql:sql_query(?PGSQL_VHOST, [<<"select 1;">>]) of
|
2013-06-19 12:11:20 +02:00
|
|
|
{selected, _, _} ->
|
2013-06-19 13:30:31 +02:00
|
|
|
mod_muc:shutdown_rooms(?PGSQL_VHOST),
|
2013-06-19 12:11:20 +02:00
|
|
|
create_sql_tables(pgsql, ?config(base_dir, Config)),
|
|
|
|
set_opt(server, ?PGSQL_VHOST, Config);
|
|
|
|
Err ->
|
|
|
|
{skip, {pgsql_not_available, Err}}
|
|
|
|
end;
|
2016-03-24 10:02:13 +01:00
|
|
|
do_init_per_group(sqlite, Config) ->
|
2016-04-20 11:27:32 +02:00
|
|
|
case catch ejabberd_sql:sql_query(?SQLITE_VHOST, [<<"select 1;">>]) of
|
2015-03-16 19:53:19 +01:00
|
|
|
{selected, _, _} ->
|
|
|
|
mod_muc:shutdown_rooms(?SQLITE_VHOST),
|
|
|
|
set_opt(server, ?SQLITE_VHOST, Config);
|
|
|
|
Err ->
|
|
|
|
{skip, {sqlite_not_available, Err}}
|
|
|
|
end;
|
2016-03-24 10:02:13 +01:00
|
|
|
do_init_per_group(ldap, Config) ->
|
2013-06-21 19:23:56 +02:00
|
|
|
set_opt(server, ?LDAP_VHOST, Config);
|
2016-03-24 10:02:13 +01:00
|
|
|
do_init_per_group(extauth, Config) ->
|
2013-06-26 04:29:50 +02:00
|
|
|
set_opt(server, ?EXTAUTH_VHOST, Config);
|
2016-03-24 10:02:13 +01:00
|
|
|
do_init_per_group(riak, Config) ->
|
2014-07-09 20:59:45 +02:00
|
|
|
case ejabberd_riak:is_connected() of
|
|
|
|
true ->
|
|
|
|
mod_muc:shutdown_rooms(?RIAK_VHOST),
|
|
|
|
NewConfig = set_opt(server, ?RIAK_VHOST, Config),
|
|
|
|
clear_riak_tables(NewConfig);
|
|
|
|
Err ->
|
|
|
|
{skip, {riak_not_available, Err}}
|
|
|
|
end;
|
2016-09-23 11:30:33 +02:00
|
|
|
do_init_per_group(s2s, Config) ->
|
|
|
|
ejabberd_config:add_option(s2s_use_starttls, required_trusted),
|
|
|
|
ejabberd_config:add_option(domain_certfile, "cert.pem"),
|
|
|
|
Port = ?config(s2s_port, Config),
|
|
|
|
set_opt(server, ?COMMON_VHOST,
|
|
|
|
set_opt(xmlns, ?NS_SERVER,
|
|
|
|
set_opt(type, server,
|
|
|
|
set_opt(server_port, Port,
|
|
|
|
set_opt(stream_from, ?S2S_VHOST,
|
|
|
|
set_opt(lang, <<"">>, Config))))));
|
2016-09-21 09:45:11 +02:00
|
|
|
do_init_per_group(component, Config) ->
|
|
|
|
Server = ?config(server, Config),
|
|
|
|
Port = ?config(component_port, Config),
|
|
|
|
set_opt(xmlns, ?NS_COMPONENT,
|
|
|
|
set_opt(server, <<"component.", Server/binary>>,
|
|
|
|
set_opt(type, component,
|
|
|
|
set_opt(server_port, Port,
|
2016-09-23 11:30:33 +02:00
|
|
|
set_opt(stream_version, undefined,
|
2016-09-21 09:45:11 +02:00
|
|
|
set_opt(lang, <<"">>, Config))))));
|
2016-09-25 08:57:56 +02:00
|
|
|
do_init_per_group(GroupName, Config) ->
|
2013-06-15 15:28:14 +02:00
|
|
|
Pid = start_event_relay(),
|
2016-09-25 08:57:56 +02:00
|
|
|
NewConfig = set_opt(event_relay, Pid, Config),
|
|
|
|
case GroupName of
|
|
|
|
anonymous -> set_opt(anonymous, true, NewConfig);
|
|
|
|
_ -> NewConfig
|
|
|
|
end.
|
2013-04-08 11:12:54 +02:00
|
|
|
|
2013-06-19 12:11:20 +02:00
|
|
|
end_per_group(mnesia, _Config) ->
|
|
|
|
ok;
|
2016-02-19 15:06:41 +01:00
|
|
|
end_per_group(redis, _Config) ->
|
|
|
|
ok;
|
2013-06-19 12:11:20 +02:00
|
|
|
end_per_group(mysql, _Config) ->
|
|
|
|
ok;
|
|
|
|
end_per_group(pgsql, _Config) ->
|
|
|
|
ok;
|
2015-03-16 19:53:19 +01:00
|
|
|
end_per_group(sqlite, _Config) ->
|
|
|
|
ok;
|
2013-06-19 12:11:20 +02:00
|
|
|
end_per_group(no_db, _Config) ->
|
|
|
|
ok;
|
2013-06-21 19:23:56 +02:00
|
|
|
end_per_group(ldap, _Config) ->
|
|
|
|
ok;
|
2013-06-26 04:29:50 +02:00
|
|
|
end_per_group(extauth, _Config) ->
|
|
|
|
ok;
|
2016-11-18 11:38:08 +01:00
|
|
|
end_per_group(riak, Config) ->
|
|
|
|
case ejabberd_riak:is_connected() of
|
|
|
|
true ->
|
|
|
|
clear_riak_tables(Config);
|
|
|
|
false ->
|
|
|
|
Config
|
|
|
|
end;
|
2016-09-21 09:45:11 +02:00
|
|
|
end_per_group(component, _Config) ->
|
|
|
|
ok;
|
2016-09-23 11:30:33 +02:00
|
|
|
end_per_group(s2s, _Config) ->
|
|
|
|
ejabberd_config:add_option(s2s_use_starttls, false);
|
2013-06-15 15:28:14 +02:00
|
|
|
end_per_group(_GroupName, Config) ->
|
|
|
|
stop_event_relay(Config),
|
2016-09-25 08:57:56 +02:00
|
|
|
set_opt(anonymous, false, Config).
|
2013-04-08 11:12:54 +02:00
|
|
|
|
2013-06-19 12:11:20 +02:00
|
|
|
init_per_testcase(stop_ejabberd, Config) ->
|
2016-10-22 12:01:45 +02:00
|
|
|
NewConfig = set_opt(resource, <<"">>,
|
|
|
|
set_opt(anonymous, true, Config)),
|
|
|
|
open_session(bind(auth(connect(NewConfig))));
|
2013-04-08 11:12:54 +02:00
|
|
|
init_per_testcase(TestCase, OrigConfig) ->
|
2016-10-22 12:01:45 +02:00
|
|
|
Test = atom_to_list(TestCase),
|
|
|
|
IsMaster = lists:suffix("_master", Test),
|
|
|
|
IsSlave = lists:suffix("_slave", Test),
|
|
|
|
if IsMaster or IsSlave ->
|
|
|
|
subscribe_to_events(OrigConfig);
|
|
|
|
true ->
|
|
|
|
ok
|
|
|
|
end,
|
2016-09-20 13:04:07 +02:00
|
|
|
TestGroup = proplists:get_value(
|
|
|
|
name, ?config(tc_group_properties, OrigConfig)),
|
2013-06-15 18:45:18 +02:00
|
|
|
Server = ?config(server, OrigConfig),
|
2016-09-20 13:04:07 +02:00
|
|
|
Resource = case TestGroup of
|
2016-09-25 08:57:56 +02:00
|
|
|
anonymous ->
|
|
|
|
<<"">>;
|
2016-09-20 13:04:07 +02:00
|
|
|
legacy_auth ->
|
|
|
|
randoms:get_string();
|
|
|
|
_ ->
|
|
|
|
?config(resource, OrigConfig)
|
|
|
|
end,
|
2014-07-20 20:43:16 +02:00
|
|
|
MasterResource = ?config(master_resource, OrigConfig),
|
|
|
|
SlaveResource = ?config(slave_resource, OrigConfig),
|
2016-10-17 12:37:23 +02:00
|
|
|
Mode = if IsSlave -> slave;
|
|
|
|
IsMaster -> master;
|
|
|
|
true -> single
|
|
|
|
end,
|
2014-07-20 20:43:16 +02:00
|
|
|
IsCarbons = lists:prefix("carbons_", Test),
|
2016-09-20 13:04:07 +02:00
|
|
|
IsReplaced = lists:prefix("replaced_", Test),
|
|
|
|
User = if IsReplaced -> <<"test_single!#$%^*()`~+-;_=[]{}|\\">>;
|
2016-11-18 11:38:08 +01:00
|
|
|
IsCarbons and not (IsMaster or IsSlave) ->
|
|
|
|
<<"test_single!#$%^*()`~+-;_=[]{}|\\">>;
|
2016-09-20 13:04:07 +02:00
|
|
|
IsMaster or IsCarbons -> <<"test_master!#$%^*()`~+-;_=[]{}|\\">>;
|
2016-05-24 17:44:07 +02:00
|
|
|
IsSlave -> <<"test_slave!#$%^*()`~+-;_=[]{}|\\">>;
|
|
|
|
true -> <<"test_single!#$%^*()`~+-;_=[]{}|\\">>
|
2013-06-15 15:28:14 +02:00
|
|
|
end,
|
2016-10-17 12:37:23 +02:00
|
|
|
Nick = if IsSlave -> ?config(slave_nick, OrigConfig);
|
|
|
|
IsMaster -> ?config(master_nick, OrigConfig);
|
|
|
|
true -> ?config(nick, OrigConfig)
|
|
|
|
end,
|
2014-07-20 20:43:16 +02:00
|
|
|
MyResource = if IsMaster and IsCarbons -> MasterResource;
|
|
|
|
IsSlave and IsCarbons -> SlaveResource;
|
|
|
|
true -> Resource
|
|
|
|
end,
|
|
|
|
Slave = if IsCarbons ->
|
2016-05-24 17:44:07 +02:00
|
|
|
jid:make(<<"test_master!#$%^*()`~+-;_=[]{}|\\">>, Server, SlaveResource);
|
2016-09-20 13:04:07 +02:00
|
|
|
IsReplaced ->
|
|
|
|
jid:make(User, Server, Resource);
|
2014-07-20 20:43:16 +02:00
|
|
|
true ->
|
2016-05-24 17:44:07 +02:00
|
|
|
jid:make(<<"test_slave!#$%^*()`~+-;_=[]{}|\\">>, Server, Resource)
|
2014-07-20 20:43:16 +02:00
|
|
|
end,
|
|
|
|
Master = if IsCarbons ->
|
2016-05-24 17:44:07 +02:00
|
|
|
jid:make(<<"test_master!#$%^*()`~+-;_=[]{}|\\">>, Server, MasterResource);
|
2016-09-20 13:04:07 +02:00
|
|
|
IsReplaced ->
|
|
|
|
jid:make(User, Server, Resource);
|
2014-07-20 20:43:16 +02:00
|
|
|
true ->
|
2016-05-24 17:44:07 +02:00
|
|
|
jid:make(<<"test_master!#$%^*()`~+-;_=[]{}|\\">>, Server, Resource)
|
2014-07-20 20:43:16 +02:00
|
|
|
end,
|
2016-10-17 12:37:23 +02:00
|
|
|
Config1 = set_opt(user, User,
|
|
|
|
set_opt(slave, Slave,
|
|
|
|
set_opt(master, Master,
|
|
|
|
set_opt(resource, MyResource,
|
|
|
|
set_opt(nick, Nick,
|
|
|
|
set_opt(mode, Mode, OrigConfig)))))),
|
|
|
|
Config2 = if IsSlave ->
|
|
|
|
set_opt(peer_nick, ?config(master_nick, Config1), Config1);
|
|
|
|
IsMaster ->
|
|
|
|
set_opt(peer_nick, ?config(slave_nick, Config1), Config1);
|
|
|
|
true ->
|
|
|
|
Config1
|
|
|
|
end,
|
|
|
|
Config = if IsSlave -> set_opt(peer, Master, Config2);
|
|
|
|
IsMaster -> set_opt(peer, Slave, Config2);
|
|
|
|
true -> Config2
|
|
|
|
end,
|
2016-09-20 13:04:07 +02:00
|
|
|
case Test of
|
|
|
|
"test_connect" ++ _ ->
|
2013-04-08 11:12:54 +02:00
|
|
|
Config;
|
2017-01-23 11:51:05 +01:00
|
|
|
"test_legacy_auth_feature" ->
|
|
|
|
connect(Config);
|
2016-09-20 13:04:07 +02:00
|
|
|
"test_legacy_auth" ++ _ ->
|
2016-09-23 11:30:33 +02:00
|
|
|
init_stream(set_opt(stream_version, undefined, Config));
|
2016-09-20 13:04:07 +02:00
|
|
|
"test_auth" ++ _ ->
|
2013-04-08 11:12:54 +02:00
|
|
|
connect(Config);
|
2016-09-20 13:04:07 +02:00
|
|
|
"test_starttls" ++ _ ->
|
2013-06-14 16:16:32 +02:00
|
|
|
connect(Config);
|
2016-09-20 13:04:07 +02:00
|
|
|
"test_zlib" ->
|
2013-06-14 16:45:04 +02:00
|
|
|
connect(Config);
|
2016-09-20 13:04:07 +02:00
|
|
|
"test_register" ->
|
2013-06-14 10:47:50 +02:00
|
|
|
connect(Config);
|
2016-09-20 13:04:07 +02:00
|
|
|
"auth_md5" ->
|
2013-04-08 11:12:54 +02:00
|
|
|
connect(Config);
|
2016-09-20 13:04:07 +02:00
|
|
|
"auth_plain" ->
|
2013-04-08 11:12:54 +02:00
|
|
|
connect(Config);
|
2017-03-07 12:20:50 +01:00
|
|
|
"auth_external" ++ _ ->
|
|
|
|
connect(Config);
|
2016-09-20 13:04:07 +02:00
|
|
|
"unauthenticated_" ++ _ ->
|
|
|
|
connect(Config);
|
|
|
|
"test_bind" ->
|
2013-04-08 11:12:54 +02:00
|
|
|
auth(connect(Config));
|
2016-09-20 13:04:07 +02:00
|
|
|
"sm_resume" ->
|
2014-07-22 11:59:31 +02:00
|
|
|
auth(connect(Config));
|
2016-09-20 13:04:07 +02:00
|
|
|
"sm_resume_failed" ->
|
2016-05-24 22:20:58 +02:00
|
|
|
auth(connect(Config));
|
2016-09-20 13:04:07 +02:00
|
|
|
"test_open_session" ->
|
2013-04-08 11:12:54 +02:00
|
|
|
bind(auth(connect(Config)));
|
2016-09-20 13:04:07 +02:00
|
|
|
"replaced" ++ _ ->
|
|
|
|
auth(connect(Config));
|
2013-06-15 15:28:14 +02:00
|
|
|
_ when IsMaster or IsSlave ->
|
|
|
|
Password = ?config(password, Config),
|
|
|
|
ejabberd_auth:try_register(User, Server, Password),
|
|
|
|
open_session(bind(auth(connect(Config))));
|
2016-09-23 11:30:33 +02:00
|
|
|
_ when TestGroup == s2s_tests ->
|
|
|
|
auth(connect(starttls(connect(Config))));
|
2013-04-08 11:12:54 +02:00
|
|
|
_ ->
|
|
|
|
open_session(bind(auth(connect(Config))))
|
|
|
|
end.
|
|
|
|
|
|
|
|
end_per_testcase(_TestCase, _Config) ->
|
|
|
|
ok.
|
|
|
|
|
2016-09-20 13:04:07 +02:00
|
|
|
legacy_auth_tests() ->
|
|
|
|
{legacy_auth, [parallel],
|
2017-01-23 11:51:05 +01:00
|
|
|
[test_legacy_auth_feature,
|
|
|
|
test_legacy_auth,
|
2016-09-20 13:04:07 +02:00
|
|
|
test_legacy_auth_digest,
|
|
|
|
test_legacy_auth_no_resource,
|
|
|
|
test_legacy_auth_bad_jid,
|
|
|
|
test_legacy_auth_fail]}.
|
|
|
|
|
2013-06-21 19:23:56 +02:00
|
|
|
no_db_tests() ->
|
2016-09-25 08:57:56 +02:00
|
|
|
[{anonymous, [parallel],
|
2016-09-20 13:04:07 +02:00
|
|
|
[test_connect_bad_xml,
|
2016-09-23 11:30:33 +02:00
|
|
|
test_connect_unexpected_xml,
|
2016-09-20 13:04:07 +02:00
|
|
|
test_connect_unknown_ns,
|
2016-09-21 09:45:11 +02:00
|
|
|
test_connect_bad_xmlns,
|
2016-09-20 13:04:07 +02:00
|
|
|
test_connect_bad_ns_stream,
|
|
|
|
test_connect_bad_lang,
|
|
|
|
test_connect_bad_to,
|
|
|
|
test_connect_missing_to,
|
|
|
|
test_connect,
|
|
|
|
unauthenticated_iq,
|
2017-01-23 11:51:05 +01:00
|
|
|
unauthenticated_message,
|
|
|
|
unauthenticated_presence,
|
2013-06-14 18:35:14 +02:00
|
|
|
test_starttls,
|
|
|
|
test_zlib,
|
|
|
|
test_auth,
|
|
|
|
test_bind,
|
|
|
|
test_open_session,
|
2016-09-20 13:04:07 +02:00
|
|
|
codec_failure,
|
|
|
|
unsupported_query,
|
|
|
|
bad_nonza,
|
|
|
|
invalid_from,
|
2016-09-25 09:17:03 +02:00
|
|
|
legacy_iq,
|
2013-06-14 18:35:14 +02:00
|
|
|
ping,
|
|
|
|
version,
|
|
|
|
time,
|
|
|
|
stats,
|
2013-06-19 12:11:20 +02:00
|
|
|
disco]},
|
2016-09-23 11:30:33 +02:00
|
|
|
{presence_and_s2s, [sequence],
|
2016-09-25 08:57:56 +02:00
|
|
|
[test_auth_fail,
|
|
|
|
presence,
|
2016-09-23 11:30:33 +02:00
|
|
|
s2s_dialback,
|
|
|
|
s2s_optional,
|
|
|
|
s2s_required,
|
|
|
|
s2s_required_trusted]},
|
2017-03-07 12:20:50 +01:00
|
|
|
auth_external,
|
|
|
|
auth_external_no_jid,
|
|
|
|
auth_external_no_user,
|
|
|
|
auth_external_malformed_jid,
|
|
|
|
auth_external_wrong_jid,
|
|
|
|
auth_external_wrong_server,
|
|
|
|
auth_external_invalid_cert,
|
2016-11-18 11:38:08 +01:00
|
|
|
sm_tests:single_cases(),
|
2017-02-21 10:38:03 +01:00
|
|
|
sm_tests:master_slave_cases(),
|
2016-10-17 12:37:23 +02:00
|
|
|
muc_tests:single_cases(),
|
|
|
|
muc_tests:master_slave_cases(),
|
2016-11-18 11:38:08 +01:00
|
|
|
proxy65_tests:single_cases(),
|
|
|
|
proxy65_tests:master_slave_cases(),
|
|
|
|
replaced_tests:master_slave_cases()].
|
2016-10-07 09:31:03 +02:00
|
|
|
|
2014-07-20 20:43:16 +02:00
|
|
|
db_tests(riak) ->
|
|
|
|
%% No support for mod_pubsub
|
2013-06-19 12:11:20 +02:00
|
|
|
[{single_user, [sequence],
|
|
|
|
[test_register,
|
2016-09-20 13:04:07 +02:00
|
|
|
legacy_auth_tests(),
|
2013-06-19 12:11:20 +02:00
|
|
|
auth_plain,
|
|
|
|
auth_md5,
|
|
|
|
presence_broadcast,
|
2013-06-14 18:35:14 +02:00
|
|
|
last,
|
2016-11-07 08:10:57 +01:00
|
|
|
roster_tests:single_cases(),
|
2013-06-14 18:35:14 +02:00
|
|
|
private,
|
2016-10-22 12:01:45 +02:00
|
|
|
privacy_tests:single_cases(),
|
2016-11-18 11:38:08 +01:00
|
|
|
vcard_tests:single_cases(),
|
2016-10-17 12:37:23 +02:00
|
|
|
muc_tests:single_cases(),
|
2016-11-18 11:38:08 +01:00
|
|
|
offline_tests:single_cases(),
|
2017-04-15 13:41:14 +02:00
|
|
|
carbons_tests:single_cases(),
|
2013-06-15 15:28:14 +02:00
|
|
|
test_unregister]},
|
2016-10-17 12:37:23 +02:00
|
|
|
muc_tests:master_slave_cases(),
|
2016-10-22 12:01:45 +02:00
|
|
|
privacy_tests:master_slave_cases(),
|
2016-11-07 08:10:57 +01:00
|
|
|
roster_tests:master_slave_cases(),
|
2016-11-08 13:15:19 +01:00
|
|
|
offline_tests:master_slave_cases(),
|
2016-11-18 11:38:08 +01:00
|
|
|
vcard_tests:master_slave_cases(),
|
2017-04-15 13:41:14 +02:00
|
|
|
announce_tests:master_slave_cases(),
|
|
|
|
carbons_tests:master_slave_cases()];
|
2016-02-19 15:06:41 +01:00
|
|
|
db_tests(DB) when DB == mnesia; DB == redis ->
|
2014-07-09 14:38:45 +02:00
|
|
|
[{single_user, [sequence],
|
|
|
|
[test_register,
|
2016-09-20 13:04:07 +02:00
|
|
|
legacy_auth_tests(),
|
2014-07-09 14:38:45 +02:00
|
|
|
auth_plain,
|
|
|
|
auth_md5,
|
|
|
|
presence_broadcast,
|
|
|
|
last,
|
2016-11-07 08:10:57 +01:00
|
|
|
roster_tests:single_cases(),
|
2014-07-09 14:38:45 +02:00
|
|
|
private,
|
2016-10-22 12:01:45 +02:00
|
|
|
privacy_tests:single_cases(),
|
2016-11-18 11:38:08 +01:00
|
|
|
vcard_tests:single_cases(),
|
|
|
|
pubsub_tests:single_cases(),
|
2016-10-17 12:37:23 +02:00
|
|
|
muc_tests:single_cases(),
|
2016-11-08 13:15:19 +01:00
|
|
|
offline_tests:single_cases(),
|
2016-11-18 11:38:08 +01:00
|
|
|
mam_tests:single_cases(),
|
|
|
|
carbons_tests:single_cases(),
|
|
|
|
csi_tests:single_cases(),
|
2017-07-20 20:22:50 +02:00
|
|
|
push_tests:single_cases(),
|
2014-07-09 14:38:45 +02:00
|
|
|
test_unregister]},
|
2016-10-17 12:37:23 +02:00
|
|
|
muc_tests:master_slave_cases(),
|
2016-10-22 12:01:45 +02:00
|
|
|
privacy_tests:master_slave_cases(),
|
2016-11-18 11:38:08 +01:00
|
|
|
pubsub_tests:master_slave_cases(),
|
2016-11-07 08:10:57 +01:00
|
|
|
roster_tests:master_slave_cases(),
|
2016-11-08 13:15:19 +01:00
|
|
|
offline_tests:master_slave_cases(),
|
2016-11-18 11:38:08 +01:00
|
|
|
mam_tests:master_slave_cases(),
|
|
|
|
vcard_tests:master_slave_cases(),
|
|
|
|
announce_tests:master_slave_cases(),
|
|
|
|
carbons_tests:master_slave_cases(),
|
2017-07-20 20:22:50 +02:00
|
|
|
csi_tests:master_slave_cases(),
|
|
|
|
push_tests:master_slave_cases()];
|
2014-07-09 14:38:45 +02:00
|
|
|
db_tests(_) ->
|
|
|
|
[{single_user, [sequence],
|
|
|
|
[test_register,
|
2016-09-20 13:04:07 +02:00
|
|
|
legacy_auth_tests(),
|
2016-10-17 12:37:23 +02:00
|
|
|
auth_plain,
|
|
|
|
auth_md5,
|
|
|
|
presence_broadcast,
|
|
|
|
last,
|
2016-11-07 08:10:57 +01:00
|
|
|
roster_tests:single_cases(),
|
2016-10-17 12:37:23 +02:00
|
|
|
private,
|
2016-10-22 12:01:45 +02:00
|
|
|
privacy_tests:single_cases(),
|
2016-11-18 11:38:08 +01:00
|
|
|
vcard_tests:single_cases(),
|
|
|
|
pubsub_tests:single_cases(),
|
2016-10-17 12:37:23 +02:00
|
|
|
muc_tests:single_cases(),
|
2016-11-08 13:15:19 +01:00
|
|
|
offline_tests:single_cases(),
|
2016-11-18 11:38:08 +01:00
|
|
|
mam_tests:single_cases(),
|
2016-10-17 12:37:23 +02:00
|
|
|
test_unregister]},
|
|
|
|
muc_tests:master_slave_cases(),
|
2016-10-22 12:01:45 +02:00
|
|
|
privacy_tests:master_slave_cases(),
|
2016-11-18 11:38:08 +01:00
|
|
|
pubsub_tests:master_slave_cases(),
|
2016-11-07 08:10:57 +01:00
|
|
|
roster_tests:master_slave_cases(),
|
2016-11-08 13:15:19 +01:00
|
|
|
offline_tests:master_slave_cases(),
|
2016-11-18 11:38:08 +01:00
|
|
|
mam_tests:master_slave_cases(),
|
|
|
|
vcard_tests:master_slave_cases(),
|
2017-03-30 09:31:51 +02:00
|
|
|
announce_tests:master_slave_cases(),
|
|
|
|
carbons_tests:master_slave_cases()].
|
2014-07-09 14:38:45 +02:00
|
|
|
|
2013-06-21 19:23:56 +02:00
|
|
|
ldap_tests() ->
|
|
|
|
[{ldap_tests, [sequence],
|
|
|
|
[test_auth,
|
2016-09-20 13:04:07 +02:00
|
|
|
test_auth_fail,
|
2016-03-25 17:30:12 +01:00
|
|
|
vcard_get,
|
2016-03-25 17:42:58 +01:00
|
|
|
ldap_shared_roster_get]}].
|
2013-06-21 19:23:56 +02:00
|
|
|
|
2013-06-26 04:29:50 +02:00
|
|
|
extauth_tests() ->
|
|
|
|
[{extauth_tests, [sequence],
|
|
|
|
[test_auth,
|
2016-09-20 13:04:07 +02:00
|
|
|
test_auth_fail,
|
2013-06-26 04:29:50 +02:00
|
|
|
test_unregister]}].
|
|
|
|
|
2016-09-21 09:45:11 +02:00
|
|
|
component_tests() ->
|
2016-09-23 11:30:33 +02:00
|
|
|
[{component_connect, [parallel],
|
2016-09-21 09:45:11 +02:00
|
|
|
[test_connect_bad_xml,
|
2016-09-23 11:30:33 +02:00
|
|
|
test_connect_unexpected_xml,
|
2016-09-21 09:45:11 +02:00
|
|
|
test_connect_unknown_ns,
|
|
|
|
test_connect_bad_xmlns,
|
|
|
|
test_connect_bad_ns_stream,
|
|
|
|
test_connect_missing_to,
|
|
|
|
test_connect,
|
|
|
|
test_auth,
|
2016-09-23 11:30:33 +02:00
|
|
|
test_auth_fail]},
|
|
|
|
{component_tests, [sequence],
|
2017-01-23 11:51:05 +01:00
|
|
|
[test_missing_from,
|
|
|
|
test_missing_to,
|
2016-09-23 11:30:33 +02:00
|
|
|
test_invalid_from,
|
|
|
|
test_component_send,
|
|
|
|
bad_nonza,
|
|
|
|
codec_failure]}].
|
|
|
|
|
|
|
|
s2s_tests() ->
|
|
|
|
[{s2s_connect, [parallel],
|
|
|
|
[test_connect_bad_xml,
|
|
|
|
test_connect_unexpected_xml,
|
|
|
|
test_connect_unknown_ns,
|
|
|
|
test_connect_bad_xmlns,
|
|
|
|
test_connect_bad_ns_stream,
|
|
|
|
test_connect,
|
|
|
|
test_connect_s2s_starttls_required,
|
|
|
|
test_starttls,
|
|
|
|
test_connect_s2s_unauthenticated_iq,
|
|
|
|
test_auth_starttls]},
|
|
|
|
{s2s_tests, [sequence],
|
2017-01-23 11:51:05 +01:00
|
|
|
[test_missing_from,
|
|
|
|
test_missing_to,
|
2016-09-23 11:30:33 +02:00
|
|
|
test_invalid_from,
|
2016-09-21 09:45:11 +02:00
|
|
|
bad_nonza,
|
|
|
|
codec_failure]}].
|
|
|
|
|
2013-06-19 12:11:20 +02:00
|
|
|
groups() ->
|
2013-06-21 19:23:56 +02:00
|
|
|
[{ldap, [sequence], ldap_tests()},
|
2013-06-26 04:29:50 +02:00
|
|
|
{extauth, [sequence], extauth_tests()},
|
2013-06-21 19:23:56 +02:00
|
|
|
{no_db, [sequence], no_db_tests()},
|
2016-09-21 09:45:11 +02:00
|
|
|
{component, [sequence], component_tests()},
|
2016-09-23 11:30:33 +02:00
|
|
|
{s2s, [sequence], s2s_tests()},
|
2014-07-09 14:38:45 +02:00
|
|
|
{mnesia, [sequence], db_tests(mnesia)},
|
2016-02-19 15:06:41 +01:00
|
|
|
{redis, [sequence], db_tests(redis)},
|
2014-07-09 14:38:45 +02:00
|
|
|
{mysql, [sequence], db_tests(mysql)},
|
|
|
|
{pgsql, [sequence], db_tests(pgsql)},
|
2015-03-16 19:53:19 +01:00
|
|
|
{sqlite, [sequence], db_tests(sqlite)},
|
2014-07-09 14:38:45 +02:00
|
|
|
{riak, [sequence], db_tests(riak)}].
|
2013-06-19 12:11:20 +02:00
|
|
|
|
2013-04-08 11:12:54 +02:00
|
|
|
all() ->
|
2016-10-07 09:31:03 +02:00
|
|
|
[{group, ldap},
|
2013-06-21 19:23:56 +02:00
|
|
|
{group, no_db},
|
2016-10-07 09:31:03 +02:00
|
|
|
{group, mnesia},
|
|
|
|
{group, redis},
|
|
|
|
{group, mysql},
|
|
|
|
{group, pgsql},
|
|
|
|
{group, sqlite},
|
|
|
|
{group, extauth},
|
|
|
|
{group, riak},
|
|
|
|
{group, component},
|
|
|
|
{group, s2s},
|
2013-06-15 18:45:18 +02:00
|
|
|
stop_ejabberd].
|
2013-04-08 11:12:54 +02:00
|
|
|
|
|
|
|
stop_ejabberd(Config) ->
|
|
|
|
ok = application:stop(ejabberd),
|
2015-04-09 16:39:52 +02:00
|
|
|
?recv1(#stream_error{reason = 'system-shutdown'}),
|
|
|
|
?recv1({xmlstreamend, <<"stream:stream">>}),
|
2013-04-08 11:12:54 +02:00
|
|
|
Config.
|
|
|
|
|
2016-09-20 13:04:07 +02:00
|
|
|
test_connect_bad_xml(Config) ->
|
2016-09-23 11:30:33 +02:00
|
|
|
Config0 = tcp_connect(Config),
|
|
|
|
send_text(Config0, <<"<'/>">>),
|
|
|
|
Version = ?config(stream_version, Config0),
|
|
|
|
?recv1(#stream_start{version = Version}),
|
2016-09-20 13:04:07 +02:00
|
|
|
?recv1(#stream_error{reason = 'not-well-formed'}),
|
|
|
|
?recv1({xmlstreamend, <<"stream:stream">>}),
|
|
|
|
close_socket(Config0).
|
|
|
|
|
2016-09-23 11:30:33 +02:00
|
|
|
test_connect_unexpected_xml(Config) ->
|
|
|
|
Config0 = tcp_connect(Config),
|
|
|
|
send(Config0, #caps{}),
|
|
|
|
Version = ?config(stream_version, Config0),
|
|
|
|
?recv1(#stream_start{version = Version}),
|
|
|
|
?recv1(#stream_error{reason = 'invalid-xml'}),
|
|
|
|
?recv1({xmlstreamend, <<"stream:stream">>}),
|
|
|
|
close_socket(Config0).
|
|
|
|
|
2016-09-20 13:04:07 +02:00
|
|
|
test_connect_unknown_ns(Config) ->
|
2016-09-21 09:45:11 +02:00
|
|
|
Config0 = init_stream(set_opt(xmlns, <<"wrong">>, Config)),
|
|
|
|
?recv1(#stream_error{reason = 'invalid-xml'}),
|
2016-09-20 13:04:07 +02:00
|
|
|
?recv1({xmlstreamend, <<"stream:stream">>}),
|
|
|
|
close_socket(Config0).
|
|
|
|
|
2016-09-21 09:45:11 +02:00
|
|
|
test_connect_bad_xmlns(Config) ->
|
2016-09-23 11:30:33 +02:00
|
|
|
NS = case ?config(type, Config) of
|
|
|
|
client -> ?NS_SERVER;
|
|
|
|
_ -> ?NS_CLIENT
|
|
|
|
end,
|
|
|
|
Config0 = init_stream(set_opt(xmlns, NS, Config)),
|
2016-09-20 13:04:07 +02:00
|
|
|
?recv1(#stream_error{reason = 'invalid-namespace'}),
|
|
|
|
?recv1({xmlstreamend, <<"stream:stream">>}),
|
|
|
|
close_socket(Config0).
|
|
|
|
|
|
|
|
test_connect_bad_ns_stream(Config) ->
|
|
|
|
Config0 = init_stream(set_opt(ns_stream, <<"wrong">>, Config)),
|
|
|
|
?recv1(#stream_error{reason = 'invalid-namespace'}),
|
|
|
|
?recv1({xmlstreamend, <<"stream:stream">>}),
|
|
|
|
close_socket(Config0).
|
|
|
|
|
|
|
|
test_connect_bad_lang(Config) ->
|
2016-10-17 12:37:23 +02:00
|
|
|
Lang = iolist_to_binary(lists:duplicate(36, $x)),
|
|
|
|
Config0 = init_stream(set_opt(lang, Lang, Config)),
|
2016-09-20 13:04:07 +02:00
|
|
|
?recv1(#stream_error{reason = 'policy-violation'}),
|
|
|
|
?recv1({xmlstreamend, <<"stream:stream">>}),
|
|
|
|
close_socket(Config0).
|
|
|
|
|
|
|
|
test_connect_bad_to(Config) ->
|
|
|
|
Config0 = init_stream(set_opt(server, <<"wrong.com">>, Config)),
|
|
|
|
?recv1(#stream_error{reason = 'host-unknown'}),
|
|
|
|
?recv1({xmlstreamend, <<"stream:stream">>}),
|
|
|
|
close_socket(Config0).
|
|
|
|
|
|
|
|
test_connect_missing_to(Config) ->
|
|
|
|
Config0 = init_stream(set_opt(server, <<"">>, Config)),
|
|
|
|
?recv1(#stream_error{reason = 'improper-addressing'}),
|
|
|
|
?recv1({xmlstreamend, <<"stream:stream">>}),
|
|
|
|
close_socket(Config0).
|
|
|
|
|
2013-04-08 11:12:54 +02:00
|
|
|
test_connect(Config) ->
|
|
|
|
disconnect(connect(Config)).
|
|
|
|
|
2016-09-23 11:30:33 +02:00
|
|
|
test_connect_s2s_starttls_required(Config) ->
|
|
|
|
Config1 = connect(Config),
|
2017-01-23 11:51:05 +01:00
|
|
|
send(Config1, #presence{}),
|
2016-09-23 11:30:33 +02:00
|
|
|
?recv1(#stream_error{reason = 'policy-violation'}),
|
|
|
|
?recv1({xmlstreamend, <<"stream:stream">>}),
|
|
|
|
close_socket(Config1).
|
2016-09-21 09:45:11 +02:00
|
|
|
|
2016-09-23 11:30:33 +02:00
|
|
|
test_connect_s2s_unauthenticated_iq(Config) ->
|
|
|
|
Config1 = connect(starttls(connect(Config))),
|
|
|
|
unauthenticated_iq(Config1).
|
2016-09-21 09:45:11 +02:00
|
|
|
|
2013-06-14 16:16:32 +02:00
|
|
|
test_starttls(Config) ->
|
|
|
|
case ?config(starttls, Config) of
|
|
|
|
true ->
|
2016-09-23 11:30:33 +02:00
|
|
|
disconnect(connect(starttls(Config)));
|
2013-06-14 16:16:32 +02:00
|
|
|
_ ->
|
|
|
|
{skipped, 'starttls_not_available'}
|
|
|
|
end.
|
|
|
|
|
2013-06-14 16:45:04 +02:00
|
|
|
test_zlib(Config) ->
|
|
|
|
case ?config(compression, Config) of
|
|
|
|
[_|_] = Ms ->
|
|
|
|
case lists:member(<<"zlib">>, Ms) of
|
|
|
|
true ->
|
2013-06-14 18:35:14 +02:00
|
|
|
disconnect(zlib(Config));
|
2013-06-14 16:45:04 +02:00
|
|
|
false ->
|
|
|
|
{skipped, 'zlib_not_available'}
|
|
|
|
end;
|
|
|
|
_ ->
|
|
|
|
{skipped, 'compression_not_available'}
|
|
|
|
end.
|
|
|
|
|
2013-06-14 16:16:32 +02:00
|
|
|
test_register(Config) ->
|
2013-06-14 10:47:50 +02:00
|
|
|
case ?config(register, Config) of
|
|
|
|
true ->
|
2013-06-14 18:35:14 +02:00
|
|
|
disconnect(register(Config));
|
2013-06-14 16:16:32 +02:00
|
|
|
_ ->
|
|
|
|
{skipped, 'registration_not_available'}
|
2013-06-14 10:47:50 +02:00
|
|
|
end.
|
|
|
|
|
2013-06-14 16:16:32 +02:00
|
|
|
register(Config) ->
|
2013-06-16 20:00:19 +02:00
|
|
|
#iq{type = result,
|
2016-09-13 11:30:05 +02:00
|
|
|
sub_els = [#register{username = <<>>,
|
|
|
|
password = <<>>}]} =
|
2013-06-16 20:00:19 +02:00
|
|
|
send_recv(Config, #iq{type = get, to = server_jid(Config),
|
|
|
|
sub_els = [#register{}]}),
|
|
|
|
#iq{type = result, sub_els = []} =
|
|
|
|
send_recv(
|
|
|
|
Config,
|
|
|
|
#iq{type = set,
|
|
|
|
sub_els = [#register{username = ?config(user, Config),
|
|
|
|
password = ?config(password, Config)}]}),
|
2013-06-14 18:35:14 +02:00
|
|
|
Config.
|
2013-06-14 10:47:50 +02:00
|
|
|
|
2013-06-14 18:58:26 +02:00
|
|
|
test_unregister(Config) ->
|
|
|
|
case ?config(register, Config) of
|
|
|
|
true ->
|
2013-06-14 19:22:36 +02:00
|
|
|
try_unregister(Config);
|
2013-06-14 18:58:26 +02:00
|
|
|
_ ->
|
|
|
|
{skipped, 'registration_not_available'}
|
|
|
|
end.
|
|
|
|
|
|
|
|
try_unregister(Config) ->
|
2013-06-14 19:22:36 +02:00
|
|
|
true = is_feature_advertised(Config, ?NS_REGISTER),
|
2013-06-16 20:00:19 +02:00
|
|
|
#iq{type = result, sub_els = []} =
|
|
|
|
send_recv(
|
|
|
|
Config,
|
|
|
|
#iq{type = set,
|
|
|
|
sub_els = [#register{remove = true}]}),
|
2015-04-09 16:39:52 +02:00
|
|
|
?recv1(#stream_error{reason = conflict}),
|
2013-06-14 18:58:26 +02:00
|
|
|
Config.
|
|
|
|
|
2017-01-23 11:51:05 +01:00
|
|
|
unauthenticated_presence(Config) ->
|
|
|
|
unauthenticated_packet(Config, #presence{}).
|
|
|
|
|
|
|
|
unauthenticated_message(Config) ->
|
|
|
|
unauthenticated_packet(Config, #message{}).
|
2016-09-20 13:04:07 +02:00
|
|
|
|
|
|
|
unauthenticated_iq(Config) ->
|
2017-01-23 11:51:05 +01:00
|
|
|
IQ = #iq{type = get, sub_els = [#disco_info{}]},
|
|
|
|
unauthenticated_packet(Config, IQ).
|
|
|
|
|
|
|
|
unauthenticated_packet(Config, Pkt) ->
|
2016-09-23 11:30:33 +02:00
|
|
|
From = my_jid(Config),
|
|
|
|
To = server_jid(Config),
|
2017-01-23 11:51:05 +01:00
|
|
|
send(Config, xmpp:set_from_to(Pkt, From, To)),
|
|
|
|
#stream_error{reason = 'not-authorized'} = recv(Config),
|
|
|
|
{xmlstreamend, <<"stream:stream">>} = recv(Config),
|
|
|
|
close_socket(Config).
|
2016-09-20 13:04:07 +02:00
|
|
|
|
|
|
|
bad_nonza(Config) ->
|
|
|
|
%% Unsupported and invalid nonza should be silently dropped.
|
|
|
|
send(Config, #caps{}),
|
|
|
|
send(Config, #stanza_error{type = wrong}),
|
|
|
|
disconnect(Config).
|
|
|
|
|
|
|
|
invalid_from(Config) ->
|
|
|
|
send(Config, #message{from = jid:make(randoms:get_string())}),
|
|
|
|
?recv1(#stream_error{reason = 'invalid-from'}),
|
|
|
|
?recv1({xmlstreamend, <<"stream:stream">>}),
|
|
|
|
close_socket(Config).
|
|
|
|
|
2017-01-23 11:51:05 +01:00
|
|
|
test_missing_from(Config) ->
|
2016-09-21 09:45:11 +02:00
|
|
|
Server = server_jid(Config),
|
2017-01-23 11:51:05 +01:00
|
|
|
send(Config, #message{to = Server}),
|
|
|
|
?recv1(#stream_error{reason = 'improper-addressing'}),
|
|
|
|
?recv1({xmlstreamend, <<"stream:stream">>}),
|
|
|
|
close_socket(Config).
|
|
|
|
|
|
|
|
test_missing_to(Config) ->
|
|
|
|
Server = server_jid(Config),
|
|
|
|
send(Config, #message{from = Server}),
|
|
|
|
?recv1(#stream_error{reason = 'improper-addressing'}),
|
|
|
|
?recv1({xmlstreamend, <<"stream:stream">>}),
|
|
|
|
close_socket(Config).
|
2016-09-21 09:45:11 +02:00
|
|
|
|
2016-09-23 11:30:33 +02:00
|
|
|
test_invalid_from(Config) ->
|
2016-09-21 09:45:11 +02:00
|
|
|
From = jid:make(randoms:get_string()),
|
|
|
|
To = jid:make(randoms:get_string()),
|
2017-01-23 11:51:05 +01:00
|
|
|
send(Config, #message{from = From, to = To}),
|
|
|
|
?recv1(#stream_error{reason = 'invalid-from'}),
|
|
|
|
?recv1({xmlstreamend, <<"stream:stream">>}),
|
|
|
|
close_socket(Config).
|
2016-09-21 09:45:11 +02:00
|
|
|
|
2016-09-23 11:30:33 +02:00
|
|
|
test_component_send(Config) ->
|
|
|
|
To = jid:make(?COMMON_VHOST),
|
|
|
|
From = server_jid(Config),
|
|
|
|
#iq{type = result, from = To, to = From} =
|
|
|
|
send_recv(Config, #iq{type = get, to = To, from = From,
|
|
|
|
sub_els = [#ping{}]}),
|
|
|
|
disconnect(Config).
|
|
|
|
|
|
|
|
s2s_dialback(Config) ->
|
2017-08-07 15:38:17 +02:00
|
|
|
ejabberd_s2s:stop_s2s_connections(),
|
2016-09-23 11:30:33 +02:00
|
|
|
ejabberd_config:add_option(s2s_use_starttls, false),
|
|
|
|
ejabberd_config:add_option(domain_certfile, "self-signed-cert.pem"),
|
|
|
|
s2s_ping(Config).
|
|
|
|
|
|
|
|
s2s_optional(Config) ->
|
2017-08-07 15:38:17 +02:00
|
|
|
ejabberd_s2s:stop_s2s_connections(),
|
2016-09-23 11:30:33 +02:00
|
|
|
ejabberd_config:add_option(s2s_use_starttls, optional),
|
|
|
|
ejabberd_config:add_option(domain_certfile, "self-signed-cert.pem"),
|
|
|
|
s2s_ping(Config).
|
|
|
|
|
|
|
|
s2s_required(Config) ->
|
2017-08-07 15:38:17 +02:00
|
|
|
ejabberd_s2s:stop_s2s_connections(),
|
2016-09-23 11:30:33 +02:00
|
|
|
ejabberd_config:add_option(s2s_use_starttls, required),
|
|
|
|
ejabberd_config:add_option(domain_certfile, "self-signed-cert.pem"),
|
|
|
|
s2s_ping(Config).
|
|
|
|
|
|
|
|
s2s_required_trusted(Config) ->
|
2017-08-07 15:38:17 +02:00
|
|
|
ejabberd_s2s:stop_s2s_connections(),
|
2016-09-23 11:30:33 +02:00
|
|
|
ejabberd_config:add_option(s2s_use_starttls, required),
|
|
|
|
ejabberd_config:add_option(domain_certfile, "cert.pem"),
|
|
|
|
s2s_ping(Config).
|
|
|
|
|
|
|
|
s2s_ping(Config) ->
|
|
|
|
From = my_jid(Config),
|
|
|
|
To = jid:make(?MNESIA_VHOST),
|
|
|
|
ID = randoms:get_string(),
|
2017-02-16 09:00:26 +01:00
|
|
|
ejabberd_s2s:route(#iq{from = From, to = To, id = ID,
|
|
|
|
type = get, sub_els = [#ping{}]}),
|
2016-10-22 12:01:45 +02:00
|
|
|
#iq{type = result, id = ID, sub_els = []} = recv_iq(Config),
|
2016-09-21 09:45:11 +02:00
|
|
|
disconnect(Config).
|
|
|
|
|
2013-06-26 19:55:29 +02:00
|
|
|
auth_md5(Config) ->
|
|
|
|
Mechs = ?config(mechs, Config),
|
|
|
|
case lists:member(<<"DIGEST-MD5">>, Mechs) of
|
|
|
|
true ->
|
|
|
|
disconnect(auth_SASL(<<"DIGEST-MD5">>, Config));
|
|
|
|
false ->
|
|
|
|
disconnect(Config),
|
|
|
|
{skipped, 'DIGEST-MD5_not_available'}
|
|
|
|
end.
|
2013-04-08 11:12:54 +02:00
|
|
|
|
2013-06-26 19:55:29 +02:00
|
|
|
auth_plain(Config) ->
|
2013-04-08 11:12:54 +02:00
|
|
|
Mechs = ?config(mechs, Config),
|
2013-06-26 19:55:29 +02:00
|
|
|
case lists:member(<<"PLAIN">>, Mechs) of
|
|
|
|
true ->
|
|
|
|
disconnect(auth_SASL(<<"PLAIN">>, Config));
|
|
|
|
false ->
|
|
|
|
disconnect(Config),
|
|
|
|
{skipped, 'PLAIN_not_available'}
|
2013-04-08 11:12:54 +02:00
|
|
|
end.
|
|
|
|
|
2017-03-07 12:20:50 +01:00
|
|
|
auth_external(Config0) ->
|
|
|
|
Config = connect(starttls(Config0)),
|
|
|
|
disconnect(auth_SASL(<<"EXTERNAL">>, Config)).
|
|
|
|
|
|
|
|
auth_external_no_jid(Config0) ->
|
|
|
|
Config = connect(starttls(Config0)),
|
|
|
|
disconnect(auth_SASL(<<"EXTERNAL">>, Config, _ShoudFail = false,
|
|
|
|
{<<"">>, <<"">>, <<"">>})).
|
|
|
|
|
|
|
|
auth_external_no_user(Config0) ->
|
|
|
|
Config = set_opt(user, <<"">>, connect(starttls(Config0))),
|
|
|
|
disconnect(auth_SASL(<<"EXTERNAL">>, Config)).
|
|
|
|
|
|
|
|
auth_external_malformed_jid(Config0) ->
|
|
|
|
Config = connect(starttls(Config0)),
|
|
|
|
disconnect(auth_SASL(<<"EXTERNAL">>, Config, _ShouldFail = true,
|
|
|
|
{<<"">>, <<"@">>, <<"">>})).
|
|
|
|
|
|
|
|
auth_external_wrong_jid(Config0) ->
|
|
|
|
Config = set_opt(user, <<"wrong">>,
|
|
|
|
connect(starttls(Config0))),
|
|
|
|
disconnect(auth_SASL(<<"EXTERNAL">>, Config, _ShouldFail = true)).
|
|
|
|
|
|
|
|
auth_external_wrong_server(Config0) ->
|
|
|
|
Config = connect(starttls(Config0)),
|
|
|
|
disconnect(auth_SASL(<<"EXTERNAL">>, Config, _ShouldFail = true,
|
|
|
|
{<<"">>, <<"wrong.com">>, <<"">>})).
|
|
|
|
|
|
|
|
auth_external_invalid_cert(Config0) ->
|
|
|
|
Config = connect(starttls(
|
|
|
|
set_opt(certfile, "self-signed-cert.pem", Config0))),
|
|
|
|
disconnect(auth_SASL(<<"EXTERNAL">>, Config, _ShouldFail = true)).
|
|
|
|
|
2017-01-23 11:51:05 +01:00
|
|
|
test_legacy_auth_feature(Config) ->
|
|
|
|
true = ?config(legacy_auth, Config),
|
|
|
|
disconnect(Config).
|
|
|
|
|
2016-09-20 13:04:07 +02:00
|
|
|
test_legacy_auth(Config) ->
|
|
|
|
disconnect(auth_legacy(Config, _Digest = false)).
|
|
|
|
|
|
|
|
test_legacy_auth_digest(Config) ->
|
|
|
|
disconnect(auth_legacy(Config, _Digest = true)).
|
|
|
|
|
|
|
|
test_legacy_auth_no_resource(Config0) ->
|
|
|
|
Config = set_opt(resource, <<"">>, Config0),
|
|
|
|
disconnect(auth_legacy(Config, _Digest = false, _ShouldFail = true)).
|
|
|
|
|
|
|
|
test_legacy_auth_bad_jid(Config0) ->
|
|
|
|
Config = set_opt(user, <<"@">>, Config0),
|
|
|
|
disconnect(auth_legacy(Config, _Digest = false, _ShouldFail = true)).
|
|
|
|
|
|
|
|
test_legacy_auth_fail(Config0) ->
|
|
|
|
Config = set_opt(user, <<"wrong">>, Config0),
|
|
|
|
disconnect(auth_legacy(Config, _Digest = false, _ShouldFail = true)).
|
|
|
|
|
2013-06-26 19:55:29 +02:00
|
|
|
test_auth(Config) ->
|
|
|
|
disconnect(auth(Config)).
|
|
|
|
|
2016-09-23 11:30:33 +02:00
|
|
|
test_auth_starttls(Config) ->
|
|
|
|
disconnect(auth(connect(starttls(Config)))).
|
|
|
|
|
2016-09-20 13:04:07 +02:00
|
|
|
test_auth_fail(Config0) ->
|
2016-09-21 09:45:11 +02:00
|
|
|
Config = set_opt(user, <<"wrong">>,
|
|
|
|
set_opt(password, <<"wrong">>, Config0)),
|
2016-09-20 13:04:07 +02:00
|
|
|
disconnect(auth(Config, _ShouldFail = true)).
|
|
|
|
|
2013-04-08 11:12:54 +02:00
|
|
|
test_bind(Config) ->
|
|
|
|
disconnect(bind(Config)).
|
|
|
|
|
|
|
|
test_open_session(Config) ->
|
2016-09-20 13:04:07 +02:00
|
|
|
disconnect(open_session(Config, true)).
|
2013-04-08 11:12:54 +02:00
|
|
|
|
2016-09-20 13:04:07 +02:00
|
|
|
codec_failure(Config) ->
|
2016-09-21 09:45:11 +02:00
|
|
|
JID = my_jid(Config),
|
|
|
|
#iq{type = error} =
|
|
|
|
send_recv(Config, #iq{type = wrong, from = JID, to = JID}),
|
2016-09-20 13:04:07 +02:00
|
|
|
disconnect(Config).
|
|
|
|
|
|
|
|
unsupported_query(Config) ->
|
|
|
|
ServerJID = server_jid(Config),
|
|
|
|
#iq{type = error} = send_recv(Config, #iq{type = get, to = ServerJID}),
|
|
|
|
#iq{type = error} = send_recv(Config, #iq{type = get, to = ServerJID,
|
|
|
|
sub_els = [#caps{}]}),
|
|
|
|
#iq{type = error} = send_recv(Config, #iq{type = get, to = ServerJID,
|
|
|
|
sub_els = [#roster_query{},
|
|
|
|
#disco_info{},
|
|
|
|
#privacy_query{}]}),
|
|
|
|
disconnect(Config).
|
|
|
|
|
2013-06-19 12:11:20 +02:00
|
|
|
presence(Config) ->
|
|
|
|
JID = my_jid(Config),
|
2016-10-22 12:01:45 +02:00
|
|
|
#presence{from = JID, to = JID} = send_recv(Config, #presence{}),
|
2013-06-19 12:11:20 +02:00
|
|
|
disconnect(Config).
|
|
|
|
|
2013-04-08 11:12:54 +02:00
|
|
|
presence_broadcast(Config) ->
|
2014-07-15 09:53:40 +02:00
|
|
|
Feature = <<"p1:tmp:", (randoms:get_string())/binary>>,
|
2015-07-30 17:47:15 +02:00
|
|
|
Ver = crypto:hash(sha, ["client", $/, "bot", $/, "en", $/,
|
|
|
|
"ejabberd_ct", $<, Feature, $<]),
|
2014-07-15 09:53:40 +02:00
|
|
|
B64Ver = base64:encode(Ver),
|
|
|
|
Node = <<(?EJABBERD_CT_URI)/binary, $#, B64Ver/binary>>,
|
|
|
|
Server = ?config(server, Config),
|
|
|
|
ServerJID = server_jid(Config),
|
|
|
|
Info = #disco_info{identities =
|
|
|
|
[#identity{category = <<"client">>,
|
|
|
|
type = <<"bot">>,
|
|
|
|
lang = <<"en">>,
|
|
|
|
name = <<"ejabberd_ct">>}],
|
|
|
|
node = Node, features = [Feature]},
|
2016-09-13 11:30:05 +02:00
|
|
|
Caps = #caps{hash = <<"sha-1">>, node = ?EJABBERD_CT_URI, version = B64Ver},
|
2014-07-15 09:53:40 +02:00
|
|
|
send(Config, #presence{sub_els = [Caps]}),
|
2013-04-08 11:12:54 +02:00
|
|
|
JID = my_jid(Config),
|
2014-07-15 09:53:40 +02:00
|
|
|
%% We receive:
|
|
|
|
%% 1) disco#info iq request for CAPS
|
|
|
|
%% 2) welcome message
|
|
|
|
%% 3) presence broadcast
|
2016-10-22 12:01:45 +02:00
|
|
|
IQ = #iq{type = get,
|
|
|
|
from = ServerJID,
|
|
|
|
sub_els = [#disco_info{node = Node}]} = recv_iq(Config),
|
|
|
|
#message{type = normal} = recv_message(Config),
|
|
|
|
#presence{from = JID, to = JID} = recv_presence(Config),
|
2014-07-15 09:53:40 +02:00
|
|
|
send(Config, #iq{type = result, id = IQ#iq.id,
|
|
|
|
to = ServerJID, sub_els = [Info]}),
|
|
|
|
%% We're trying to read our feature from ejabberd database
|
|
|
|
%% with exponential back-off as our IQ response may be delayed.
|
|
|
|
[Feature] =
|
|
|
|
lists:foldl(
|
|
|
|
fun(Time, []) ->
|
|
|
|
timer:sleep(Time),
|
2016-09-13 11:30:05 +02:00
|
|
|
mod_caps:get_features(Server, Caps);
|
2014-07-15 09:53:40 +02:00
|
|
|
(_, Acc) ->
|
|
|
|
Acc
|
|
|
|
end, [], [0, 100, 200, 2000, 5000, 10000]),
|
2013-04-08 11:12:54 +02:00
|
|
|
disconnect(Config).
|
|
|
|
|
2016-09-25 09:17:03 +02:00
|
|
|
legacy_iq(Config) ->
|
|
|
|
true = is_feature_advertised(Config, ?NS_EVENT),
|
|
|
|
ServerJID = server_jid(Config),
|
|
|
|
#iq{type = result, sub_els = []} =
|
|
|
|
send_recv(Config, #iq{to = ServerJID, type = get,
|
|
|
|
sub_els = [#xevent{}]}),
|
|
|
|
disconnect(Config).
|
|
|
|
|
2013-04-08 11:12:54 +02:00
|
|
|
ping(Config) ->
|
|
|
|
true = is_feature_advertised(Config, ?NS_PING),
|
2013-06-16 20:00:19 +02:00
|
|
|
#iq{type = result, sub_els = []} =
|
|
|
|
send_recv(
|
|
|
|
Config,
|
|
|
|
#iq{type = get, sub_els = [#ping{}], to = server_jid(Config)}),
|
2013-04-08 11:12:54 +02:00
|
|
|
disconnect(Config).
|
|
|
|
|
|
|
|
version(Config) ->
|
|
|
|
true = is_feature_advertised(Config, ?NS_VERSION),
|
2013-06-16 20:00:19 +02:00
|
|
|
#iq{type = result, sub_els = [#version{}]} =
|
|
|
|
send_recv(
|
|
|
|
Config, #iq{type = get, sub_els = [#version{}],
|
|
|
|
to = server_jid(Config)}),
|
2013-04-08 11:12:54 +02:00
|
|
|
disconnect(Config).
|
|
|
|
|
|
|
|
time(Config) ->
|
|
|
|
true = is_feature_advertised(Config, ?NS_TIME),
|
2013-06-16 20:00:19 +02:00
|
|
|
#iq{type = result, sub_els = [#time{}]} =
|
|
|
|
send_recv(Config, #iq{type = get, sub_els = [#time{}],
|
|
|
|
to = server_jid(Config)}),
|
2013-04-08 11:12:54 +02:00
|
|
|
disconnect(Config).
|
|
|
|
|
|
|
|
disco(Config) ->
|
|
|
|
true = is_feature_advertised(Config, ?NS_DISCO_INFO),
|
|
|
|
true = is_feature_advertised(Config, ?NS_DISCO_ITEMS),
|
2013-06-16 20:00:19 +02:00
|
|
|
#iq{type = result, sub_els = [#disco_items{items = Items}]} =
|
|
|
|
send_recv(
|
|
|
|
Config, #iq{type = get, sub_els = [#disco_items{}],
|
|
|
|
to = server_jid(Config)}),
|
2013-04-08 11:12:54 +02:00
|
|
|
lists:foreach(
|
|
|
|
fun(#disco_item{jid = JID, node = Node}) ->
|
2013-06-16 20:00:19 +02:00
|
|
|
#iq{type = result} =
|
|
|
|
send_recv(Config,
|
|
|
|
#iq{type = get, to = JID,
|
|
|
|
sub_els = [#disco_info{node = Node}]})
|
2013-04-08 11:12:54 +02:00
|
|
|
end, Items),
|
|
|
|
disconnect(Config).
|
|
|
|
|
|
|
|
private(Config) ->
|
|
|
|
Conference = #bookmark_conference{name = <<"Some name">>,
|
|
|
|
autojoin = true,
|
2016-02-11 10:19:23 +01:00
|
|
|
jid = jid:make(
|
2013-04-08 11:12:54 +02:00
|
|
|
<<"some">>,
|
|
|
|
<<"some.conference.org">>,
|
|
|
|
<<>>)},
|
|
|
|
Storage = #bookmark_storage{conference = [Conference]},
|
2016-09-24 13:17:21 +02:00
|
|
|
StorageXMLOut = xmpp:encode(Storage),
|
2016-09-21 09:45:11 +02:00
|
|
|
WrongEl = #xmlel{name = <<"wrong">>},
|
2013-06-16 20:00:19 +02:00
|
|
|
#iq{type = error} =
|
2016-09-21 09:45:11 +02:00
|
|
|
send_recv(Config, #iq{type = get,
|
|
|
|
sub_els = [#private{xml_els = [WrongEl]}]}),
|
2013-06-16 20:00:19 +02:00
|
|
|
#iq{type = result, sub_els = []} =
|
|
|
|
send_recv(
|
|
|
|
Config, #iq{type = set,
|
2016-09-21 09:45:11 +02:00
|
|
|
sub_els = [#private{xml_els = [WrongEl, StorageXMLOut]}]}),
|
2013-06-16 20:00:19 +02:00
|
|
|
#iq{type = result,
|
2013-07-03 15:33:19 +02:00
|
|
|
sub_els = [#private{xml_els = [StorageXMLIn]}]} =
|
2013-06-16 20:00:19 +02:00
|
|
|
send_recv(
|
|
|
|
Config,
|
|
|
|
#iq{type = get,
|
2016-09-24 13:17:21 +02:00
|
|
|
sub_els = [#private{xml_els = [xmpp:encode(
|
2013-07-03 15:33:19 +02:00
|
|
|
#bookmark_storage{})]}]}),
|
2016-09-24 13:17:21 +02:00
|
|
|
Storage = xmpp:decode(StorageXMLIn),
|
2013-04-08 11:12:54 +02:00
|
|
|
disconnect(Config).
|
|
|
|
|
|
|
|
last(Config) ->
|
|
|
|
true = is_feature_advertised(Config, ?NS_LAST),
|
2013-06-16 20:00:19 +02:00
|
|
|
#iq{type = result, sub_els = [#last{}]} =
|
|
|
|
send_recv(Config, #iq{type = get, sub_els = [#last{}],
|
|
|
|
to = server_jid(Config)}),
|
2013-04-08 11:12:54 +02:00
|
|
|
disconnect(Config).
|
|
|
|
|
2013-06-21 19:23:56 +02:00
|
|
|
vcard_get(Config) ->
|
|
|
|
true = is_feature_advertised(Config, ?NS_VCARD),
|
|
|
|
%% TODO: check if VCard corresponds to LDIF data from ejabberd.ldif
|
|
|
|
#iq{type = result, sub_els = [_VCard]} =
|
2016-09-13 11:30:05 +02:00
|
|
|
send_recv(Config, #iq{type = get, sub_els = [#vcard_temp{}]}),
|
2013-06-21 19:23:56 +02:00
|
|
|
disconnect(Config).
|
|
|
|
|
2016-03-25 17:42:58 +01:00
|
|
|
ldap_shared_roster_get(Config) ->
|
2017-03-07 16:11:28 +01:00
|
|
|
Item = #roster_item{jid = jid:decode(<<"user2@ldap.localhost">>), name = <<"Test User 2">>,
|
2016-03-25 17:30:12 +01:00
|
|
|
groups = [<<"group1">>], subscription = both},
|
2016-09-13 11:30:05 +02:00
|
|
|
#iq{type = result, sub_els = [#roster_query{items = [Item]}]} =
|
|
|
|
send_recv(Config, #iq{type = get, sub_els = [#roster_query{}]}),
|
2016-03-25 17:30:12 +01:00
|
|
|
disconnect(Config).
|
|
|
|
|
2013-04-08 11:12:54 +02:00
|
|
|
stats(Config) ->
|
2016-09-13 11:30:05 +02:00
|
|
|
#iq{type = result, sub_els = [#stats{list = Stats}]} =
|
2013-06-16 20:00:19 +02:00
|
|
|
send_recv(Config, #iq{type = get, sub_els = [#stats{}],
|
|
|
|
to = server_jid(Config)}),
|
2013-04-08 11:12:54 +02:00
|
|
|
lists:foreach(
|
2013-06-15 15:28:14 +02:00
|
|
|
fun(#stat{} = Stat) ->
|
2013-06-16 20:00:19 +02:00
|
|
|
#iq{type = result, sub_els = [_|_]} =
|
|
|
|
send_recv(Config, #iq{type = get,
|
2016-09-13 11:30:05 +02:00
|
|
|
sub_els = [#stats{list = [Stat]}],
|
2013-06-16 20:00:19 +02:00
|
|
|
to = server_jid(Config)})
|
2013-04-08 11:12:54 +02:00
|
|
|
end, Stats),
|
|
|
|
disconnect(Config).
|
|
|
|
|
|
|
|
%%%===================================================================
|
|
|
|
%%% Aux functions
|
|
|
|
%%%===================================================================
|
|
|
|
bookmark_conference() ->
|
|
|
|
#bookmark_conference{name = <<"Some name">>,
|
|
|
|
autojoin = true,
|
2016-02-11 10:19:23 +01:00
|
|
|
jid = jid:make(
|
2013-04-08 11:12:54 +02:00
|
|
|
<<"some">>,
|
|
|
|
<<"some.conference.org">>,
|
|
|
|
<<>>)}.
|
2013-06-14 16:45:04 +02:00
|
|
|
|
2016-11-18 11:38:08 +01:00
|
|
|
'$handle_undefined_function'(F, [Config]) when is_list(Config) ->
|
|
|
|
case re:split(atom_to_list(F), "_", [{return, list}, {parts, 2}]) of
|
|
|
|
[M, T] ->
|
|
|
|
Module = list_to_atom(M ++ "_tests"),
|
|
|
|
Function = list_to_atom(T),
|
|
|
|
case erlang:function_exported(Module, Function, 1) of
|
|
|
|
true ->
|
|
|
|
Module:Function(Config);
|
|
|
|
false ->
|
|
|
|
erlang:error({undef, F})
|
|
|
|
end;
|
|
|
|
_ ->
|
|
|
|
erlang:error({undef, F})
|
|
|
|
end;
|
|
|
|
'$handle_undefined_function'(_, _) ->
|
|
|
|
erlang:error(undef).
|
2016-10-07 09:31:03 +02:00
|
|
|
|
2013-06-19 12:11:20 +02:00
|
|
|
%%%===================================================================
|
|
|
|
%%% SQL stuff
|
|
|
|
%%%===================================================================
|
2015-03-16 19:53:19 +01:00
|
|
|
create_sql_tables(sqlite, _BaseDir) ->
|
|
|
|
ok;
|
2013-06-19 12:11:20 +02:00
|
|
|
create_sql_tables(Type, BaseDir) ->
|
|
|
|
{VHost, File} = case Type of
|
|
|
|
mysql ->
|
|
|
|
{?MYSQL_VHOST, "mysql.sql"};
|
|
|
|
pgsql ->
|
|
|
|
{?PGSQL_VHOST, "pg.sql"}
|
|
|
|
end,
|
|
|
|
SQLFile = filename:join([BaseDir, "sql", File]),
|
|
|
|
CreationQueries = read_sql_queries(SQLFile),
|
|
|
|
DropTableQueries = drop_table_queries(CreationQueries),
|
2016-04-20 11:27:32 +02:00
|
|
|
case ejabberd_sql:sql_transaction(
|
2013-06-19 12:11:20 +02:00
|
|
|
VHost, DropTableQueries ++ CreationQueries) of
|
|
|
|
{atomic, ok} ->
|
|
|
|
ok;
|
|
|
|
Err ->
|
|
|
|
ct:fail({failed_to_create_sql_tables, Type, Err})
|
|
|
|
end.
|
|
|
|
|
|
|
|
read_sql_queries(File) ->
|
|
|
|
case file:open(File, [read, binary]) of
|
|
|
|
{ok, Fd} ->
|
|
|
|
read_lines(Fd, File, []);
|
|
|
|
Err ->
|
|
|
|
ct:fail({open_file_failed, File, Err})
|
|
|
|
end.
|
|
|
|
|
|
|
|
drop_table_queries(Queries) ->
|
|
|
|
lists:foldl(
|
|
|
|
fun(Query, Acc) ->
|
|
|
|
case split(str:to_lower(Query)) of
|
|
|
|
[<<"create">>, <<"table">>, Table|_] ->
|
|
|
|
[<<"DROP TABLE IF EXISTS ", Table/binary, ";">>|Acc];
|
|
|
|
_ ->
|
|
|
|
Acc
|
|
|
|
end
|
|
|
|
end, [], Queries).
|
|
|
|
|
|
|
|
read_lines(Fd, File, Acc) ->
|
|
|
|
case file:read_line(Fd) of
|
|
|
|
{ok, Line} ->
|
|
|
|
NewAcc = case str:strip(str:strip(Line, both, $\r), both, $\n) of
|
|
|
|
<<"--", _/binary>> ->
|
|
|
|
Acc;
|
|
|
|
<<>> ->
|
|
|
|
Acc;
|
|
|
|
_ ->
|
|
|
|
[Line|Acc]
|
|
|
|
end,
|
|
|
|
read_lines(Fd, File, NewAcc);
|
|
|
|
eof ->
|
|
|
|
QueryList = str:tokens(list_to_binary(lists:reverse(Acc)), <<";">>),
|
|
|
|
lists:flatmap(
|
|
|
|
fun(Query) ->
|
|
|
|
case str:strip(str:strip(Query, both, $\r), both, $\n) of
|
|
|
|
<<>> ->
|
|
|
|
[];
|
|
|
|
Q ->
|
|
|
|
[<<Q/binary, $;>>]
|
|
|
|
end
|
|
|
|
end, QueryList);
|
|
|
|
{error, _} = Err ->
|
|
|
|
ct:fail({read_file_failed, File, Err})
|
|
|
|
end.
|
|
|
|
|
|
|
|
split(Data) ->
|
|
|
|
lists:filter(
|
|
|
|
fun(<<>>) ->
|
|
|
|
false;
|
|
|
|
(_) ->
|
|
|
|
true
|
|
|
|
end, re:split(Data, <<"\s">>)).
|
2014-07-09 16:44:48 +02:00
|
|
|
|
|
|
|
clear_riak_tables(Config) ->
|
|
|
|
User = ?config(user, Config),
|
|
|
|
Server = ?config(server, Config),
|
2016-11-18 11:38:08 +01:00
|
|
|
Master = <<"test_master!#$%^*()`~+-;_=[]{}|\\">>,
|
|
|
|
Slave = <<"test_slave!#$%^*()`~+-;_=[]{}|\\">>,
|
2014-08-12 12:13:44 +02:00
|
|
|
ejabberd_auth:remove_user(User, Server),
|
2016-11-18 11:38:08 +01:00
|
|
|
ejabberd_auth:remove_user(Master, Server),
|
|
|
|
ejabberd_auth:remove_user(Slave, Server),
|
|
|
|
ejabberd_riak:delete(muc_room),
|
|
|
|
ejabberd_riak:delete(muc_registered),
|
|
|
|
timer:sleep(timer:seconds(5)),
|
2014-07-09 16:44:48 +02:00
|
|
|
Config.
|