25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-28 16:34:13 +01:00

Make test suite working again

This commit is contained in:
Evgeniy Khramtsov 2017-01-23 13:51:05 +03:00
parent e564f9ae31
commit 435e5e6263
19 changed files with 142 additions and 84 deletions

View File

@ -122,7 +122,7 @@ register_connection(_SID,
case proplists:get_value(auth_module, Info) of case proplists:get_value(auth_module, Info) of
?MODULE -> ?MODULE ->
ejabberd_hooks:run(register_user, LServer, [LUser, LServer]); ejabberd_hooks:run(register_user, LServer, [LUser, LServer]);
false -> _ ->
ok ok
end. end.

View File

@ -368,11 +368,15 @@ bind(R, #{user := U, server := S, access := Access, lang := Lang,
allow -> allow ->
State1 = open_session(State#{resource => Resource, State1 = open_session(State#{resource => Resource,
sid => ejabberd_sm:make_sid()}), sid => ejabberd_sm:make_sid()}),
State2 = ejabberd_hooks:run_fold( LBJID = jid:remove_resource(jid:tolower(JID)),
c2s_session_opened, LServer, State1, []), PresF = ?SETS:add_element(LBJID, maps:get(pres_f, State1)),
PresT = ?SETS:add_element(LBJID, maps:get(pres_t, State1)),
State2 = State1#{pres_f => PresF, pres_t => PresT},
State3 = ejabberd_hooks:run_fold(
c2s_session_opened, LServer, State2, []),
?INFO_MSG("(~s) Opened c2s session for ~s", ?INFO_MSG("(~s) Opened c2s session for ~s",
[SockMod:pp(Socket), jid:to_string(JID)]), [SockMod:pp(Socket), jid:to_string(JID)]),
{ok, State2}; {ok, State3};
deny -> deny ->
ejabberd_hooks:run(forbidden_session_hook, LServer, [JID]), ejabberd_hooks:run(forbidden_session_hook, LServer, [JID]),
?INFO_MSG("(~s) Forbidden c2s session for ~s", ?INFO_MSG("(~s) Forbidden c2s session for ~s",

View File

@ -33,7 +33,7 @@
-export([start/0, start_link/0]). -export([start/0, start_link/0]).
-export([route/3, route_iq/4, route_iq/5, process_iq/3, -export([route/3, route_iq/4, route_iq/5, process_iq/3,
process_iq_reply/3, register_iq_handler/4, process_iq_reply/3, register_iq_handler/4, get_features/1,
register_iq_handler/5, register_iq_response_handler/4, register_iq_handler/5, register_iq_response_handler/4,
register_iq_response_handler/5, unregister_iq_handler/2, register_iq_response_handler/5, unregister_iq_handler/2,
unregister_iq_response_handler/2, bounce_resource_packet/3]). unregister_iq_response_handler/2, bounce_resource_packet/3]).
@ -44,7 +44,7 @@
-include("ejabberd.hrl"). -include("ejabberd.hrl").
-include("logger.hrl"). -include("logger.hrl").
-include_lib("stdlib/include/ms_transform.hrl").
-include("xmpp.hrl"). -include("xmpp.hrl").
-record(state, {}). -record(state, {}).
@ -193,6 +193,14 @@ bounce_resource_packet(From, To, Packet) ->
ejabberd_router:route_error(To, From, Packet, Err), ejabberd_router:route_error(To, From, Packet, Err),
stop. stop.
-spec get_features(binary()) -> [binary()].
get_features(Host) ->
ets:select(
?IQTABLE,
ets:fun2ms(fun({{XMLNS, H}, _, _, _}) when H == Host ->
XMLNS
end)).
%%==================================================================== %%====================================================================
%% gen_server callbacks %% gen_server callbacks
%%==================================================================== %%====================================================================

View File

@ -176,6 +176,8 @@ handle_info({mnesia_table_event,
{write, #route{pid = Pid}, _ActivityId}}, State) -> {write, #route{pid = Pid}, _ActivityId}}, State) ->
erlang:monitor(process, Pid), erlang:monitor(process, Pid),
{noreply, State}; {noreply, State};
handle_info({mnesia_table_event, _}, State) ->
{noreply, State};
handle_info({'DOWN', _Ref, _Type, Pid, _Info}, State) -> handle_info({'DOWN', _Ref, _Type, Pid, _Info}, State) ->
F = fun () -> F = fun () ->
Es = mnesia:select(route, Es = mnesia:select(route,

View File

@ -698,6 +698,7 @@ opt_type(domain_certfile) -> fun iolist_to_binary/1;
opt_type(s2s_certfile) -> fun iolist_to_binary/1; opt_type(s2s_certfile) -> fun iolist_to_binary/1;
opt_type(s2s_ciphers) -> fun iolist_to_binary/1; opt_type(s2s_ciphers) -> fun iolist_to_binary/1;
opt_type(s2s_dhfile) -> fun iolist_to_binary/1; opt_type(s2s_dhfile) -> fun iolist_to_binary/1;
opt_type(s2s_cafile) -> fun iolist_to_binary/1;
opt_type(s2s_protocol_options) -> opt_type(s2s_protocol_options) ->
fun (Options) -> str:join(Options, <<"|">>) end; fun (Options) -> str:join(Options, <<"|">>) end;
opt_type(s2s_tls_compression) -> opt_type(s2s_tls_compression) ->
@ -717,5 +718,5 @@ opt_type(s2s_timeout) ->
end; end;
opt_type(_) -> opt_type(_) ->
[route_subdomains, s2s_access, s2s_certfile, [route_subdomains, s2s_access, s2s_certfile,
s2s_ciphers, s2s_dhfile, s2s_protocol_options, s2s_ciphers, s2s_dhfile, s2s_cafile, s2s_protocol_options,
s2s_tls_compression, s2s_use_starttls, s2s_timeout]. s2s_tls_compression, s2s_use_starttls, s2s_timeout].

View File

@ -93,6 +93,7 @@ init([State, Opts]) ->
lang => ?MYLANG, lang => ?MYLANG,
server => ?MYNAME, server => ?MYNAME,
host_opts => HostOpts, host_opts => HostOpts,
stream_version => undefined,
check_from => CheckFrom}, check_from => CheckFrom},
ejabberd_hooks:run_fold(component_init, {ok, State1}, [Opts]). ejabberd_hooks:run_fold(component_init, {ok, State1}, [Opts]).
@ -128,7 +129,7 @@ get_password_fun(#{remote_server := RemoteServer,
{ok, Password} -> {ok, Password} ->
{Password, undefined}; {Password, undefined};
error -> error ->
?ERROR_MSG("(~s) Domain ~s is unconfigured for " ?INFO_MSG("(~s) Domain ~s is unconfigured for "
"external component from ~s", "external component from ~s",
[SockMod:pp(Socket), RemoteServer, [SockMod:pp(Socket), RemoteServer,
ejabberd_config:may_hide_data(jlib:ip_to_list(IP))]), ejabberd_config:may_hide_data(jlib:ip_to_list(IP))]),
@ -155,14 +156,14 @@ handle_auth_failure(_, Mech, Reason,
#{remote_server := RemoteServer, #{remote_server := RemoteServer,
sockmod := SockMod, sockmod := SockMod,
socket := Socket, ip := IP} = State) -> socket := Socket, ip := IP} = State) ->
?ERROR_MSG("(~s) Failed external component ~s authentication " ?INFO_MSG("(~s) Failed external component ~s authentication "
"for ~s from ~s: ~s", "for ~s from ~s: ~s",
[SockMod:pp(Socket), Mech, RemoteServer, [SockMod:pp(Socket), Mech, RemoteServer,
ejabberd_config:may_hide_data(jlib:ip_to_list(IP)), ejabberd_config:may_hide_data(jlib:ip_to_list(IP)),
Reason]), Reason]),
State. State.
handle_authenticated_packet(Pkt, #{lang := Lang} = State) -> handle_authenticated_packet(Pkt, #{lang := Lang} = State) when ?is_stanza(Pkt) ->
From = xmpp:get_from(Pkt), From = xmpp:get_from(Pkt),
case check_from(From, State) of case check_from(From, State) of
true -> true ->
@ -173,7 +174,9 @@ handle_authenticated_packet(Pkt, #{lang := Lang} = State) ->
Txt = <<"Improper domain part of 'from' attribute">>, Txt = <<"Improper domain part of 'from' attribute">>,
Err = xmpp:serr_invalid_from(Txt, Lang), Err = xmpp:serr_invalid_from(Txt, Lang),
xmpp_stream_in:send(State, Err) xmpp_stream_in:send(State, Err)
end. end;
handle_authenticated_packet(_Pkt, State) ->
State.
handle_info({route, From, To, Packet}, #{access := Access} = State) -> handle_info({route, From, To, Packet}, #{access := Access} = State) ->
case acl:match_rule(global, Access, From) of case acl:match_rule(global, Access, From) of

View File

@ -160,7 +160,7 @@ process_block(#iq{from = #jid{luser = LUser, lserver = LServer},
broadcast_list_update(LUser, LServer, UserList, Default), broadcast_list_update(LUser, LServer, UserList, Default),
broadcast_event(LUser, LServer, broadcast_event(LUser, LServer,
#block{items = [jid:make(J) || J <- JIDs]}), #block{items = [jid:make(J) || J <- JIDs]}),
xmpp:make_iq_result(IQ); xmpp:make_iq_result(xmpp:put_meta(IQ, privacy_list, UserList));
_Err -> _Err ->
?ERROR_MSG("Error processing ~p: ~p", [{LUser, LServer, JIDs}, _Err]), ?ERROR_MSG("Error processing ~p: ~p", [{LUser, LServer, JIDs}, _Err]),
Err = xmpp:err_internal_server_error(<<"Database failure">>, Lang), Err = xmpp:err_internal_server_error(<<"Database failure">>, Lang),
@ -183,7 +183,7 @@ process_unblock_all(#iq{from = #jid{luser = LUser, lserver = LServer},
UserList = make_userlist(Default, List), UserList = make_userlist(Default, List),
broadcast_list_update(LUser, LServer, UserList, Default), broadcast_list_update(LUser, LServer, UserList, Default),
broadcast_event(LUser, LServer, #unblock{}), broadcast_event(LUser, LServer, #unblock{}),
xmpp:make_iq_result(IQ); xmpp:make_iq_result(xmpp:put_meta(IQ, privacy_list, UserList));
_Err -> _Err ->
?ERROR_MSG("Error processing ~p: ~p", [{LUser, LServer}, _Err]), ?ERROR_MSG("Error processing ~p: ~p", [{LUser, LServer}, _Err]),
Err = xmpp:err_internal_server_error(<<"Database failure">>, Lang), Err = xmpp:err_internal_server_error(<<"Database failure">>, Lang),
@ -210,7 +210,7 @@ process_unblock(#iq{from = #jid{luser = LUser, lserver = LServer},
broadcast_list_update(LUser, LServer, UserList, Default), broadcast_list_update(LUser, LServer, UserList, Default),
broadcast_event(LUser, LServer, broadcast_event(LUser, LServer,
#unblock{items = [jid:make(J) || J <- JIDs]}), #unblock{items = [jid:make(J) || J <- JIDs]}),
xmpp:make_iq_result(IQ); xmpp:make_iq_result(xmpp:put_meta(IQ, privacy_list, UserList));
_Err -> _Err ->
?ERROR_MSG("Error processing ~p: ~p", [{LUser, LServer, JIDs}, _Err]), ?ERROR_MSG("Error processing ~p: ~p", [{LUser, LServer, JIDs}, _Err]),
Err = xmpp:err_internal_server_error(<<"Database failure">>, Lang), Err = xmpp:err_internal_server_error(<<"Database failure">>, Lang),

View File

@ -175,13 +175,16 @@ get_local_identity(Acc, _From, _To, _Node, _Lang) ->
get_local_features({error, _Error} = Acc, _From, _To, get_local_features({error, _Error} = Acc, _From, _To,
_Node, _Lang) -> _Node, _Lang) ->
Acc; Acc;
get_local_features(Acc, _From, _To, <<"">>, _Lang) -> get_local_features(Acc, _From, To, <<"">>, _Lang) ->
Feats = case Acc of Feats = case Acc of
{result, Features} -> Features; {result, Features} -> Features;
empty -> [] empty -> []
end, end,
{result, [<<"iq">>, <<"presence">>, {result, lists:usort(
?NS_DISCO_INFO, ?NS_DISCO_ITEMS |Feats]}; lists:flatten(
[<<"iq">>, <<"presence">>,
?NS_DISCO_INFO, ?NS_DISCO_ITEMS, Feats,
ejabberd_local:get_features(To#jid.lserver)]))};
get_local_features(Acc, _From, _To, _Node, Lang) -> get_local_features(Acc, _From, _To, _Node, Lang) ->
case Acc of case Acc of
{result, _Features} -> Acc; {result, _Features} -> Acc;

View File

@ -135,12 +135,12 @@ shutdown_rooms(Host) ->
MyHost = gen_mod:get_module_opt_host(Host, mod_muc, MyHost = gen_mod:get_module_opt_host(Host, mod_muc,
<<"conference.@HOST@">>), <<"conference.@HOST@">>),
Rooms = RMod:get_online_rooms(MyHost, undefined), Rooms = RMod:get_online_rooms(MyHost, undefined),
lists:filter( lists:flatmap(
fun({_, _, Pid}) when node(Pid) == node() -> fun({_, _, Pid}) when node(Pid) == node() ->
Pid ! shutdown, Pid ! shutdown,
true; [Pid];
(_) -> (_) ->
false []
end, Rooms). end, Rooms).
%% This function is called by a room in three situations: %% This function is called by a room in three situations:

View File

@ -561,6 +561,8 @@ resend_offline_messages(User, Server) ->
_ -> ok _ -> ok
end. end.
c2s_self_presence({_Pres, #{resend_offline := false}} = Acc) ->
Acc;
c2s_self_presence({#presence{type = available} = NewPres, State} = Acc) -> c2s_self_presence({#presence{type = available} = NewPres, State} = Acc) ->
NewPrio = get_priority_from_presence(NewPres), NewPrio = get_priority_from_presence(NewPres),
LastPrio = try maps:get(pres_last, State) of LastPrio = try maps:get(pres_last, State) of

View File

@ -79,7 +79,7 @@ stream_feature_register(Acc, Host) ->
AF = gen_mod:get_module_opt(Host, ?MODULE, access_from, AF = gen_mod:get_module_opt(Host, ?MODULE, access_from,
fun(A) -> A end, fun(A) -> A end,
all), all),
case (AF /= none) and lists:keymember(sasl_mechanisms, 1, Acc) of case (AF /= none) of
true -> true ->
[#feature_register{}|Acc]; [#feature_register{}|Acc];
false -> false ->
@ -90,10 +90,11 @@ c2s_unauthenticated_packet(#{ip := IP, server := Server} = State,
#iq{type = T, sub_els = [_]} = IQ) #iq{type = T, sub_els = [_]} = IQ)
when T == set; T == get -> when T == set; T == get ->
case xmpp:get_subtag(IQ, #register{}) of case xmpp:get_subtag(IQ, #register{}) of
#register{} -> #register{} = Register ->
{Address, _} = IP, {Address, _} = IP,
IQ1 = xmpp:set_from_to(IQ, jid:make(<<>>), jid:make(Server)), IQ1 = xmpp:set_els(IQ, [Register]),
ResIQ = process_iq(IQ1, Address), IQ2 = xmpp:set_from_to(IQ1, jid:make(<<>>), jid:make(Server)),
ResIQ = process_iq(IQ2, Address),
ResIQ1 = xmpp:set_from_to(ResIQ, jid:make(Server), undefined), ResIQ1 = xmpp:set_from_to(ResIQ, jid:make(Server), undefined),
{stop, ejabberd_c2s:send(State, ResIQ1)}; {stop, ejabberd_c2s:send(State, ResIQ1)};
false -> false ->

View File

@ -521,13 +521,12 @@ roster_change(#{user := U, server := S, resource := R,
end. end.
-spec c2s_session_opened(ejabberd_c2s:state()) -> ejabberd_c2s:state(). -spec c2s_session_opened(ejabberd_c2s:state()) -> ejabberd_c2s:state().
c2s_session_opened(#{jid := #jid{luser = LUser, lserver = LServer} = JID, c2s_session_opened(#{jid := #jid{luser = LUser, lserver = LServer},
pres_f := PresF, pres_t := PresT} = State) -> pres_f := PresF, pres_t := PresT} = State) ->
Mod = gen_mod:db_mod(LServer, ?MODULE), Mod = gen_mod:db_mod(LServer, ?MODULE),
Items = Mod:get_only_items(LUser, LServer), Items = Mod:get_only_items(LUser, LServer),
{F, T} = fill_subscription_lists(Items, PresF, PresT), {F, T} = fill_subscription_lists(Items, PresF, PresT),
LJID = jid:tolower(jid:remove_resource(JID)), State#{pres_f => F, pres_t => T}.
State#{pres_f => ?SETS:add(LJID, F), pres_t => ?SETS:add(LJID, T)}.
fill_subscription_lists([I | Is], F, T) -> fill_subscription_lists([I | Is], F, T) ->
J = element(3, I#roster.usj), J = element(3, I#roster.usj),

View File

@ -175,11 +175,12 @@ s2s_in_packet(#{stream_id := StreamID} = State,
{ok, Pid} = ejabberd_s2s_out:start( {ok, Pid} = ejabberd_s2s_out:start(
To, From, [{db_verify, {StreamID, Key, self()}}]), To, From, [{db_verify, {StreamID, Key, self()}}]),
ejabberd_s2s_out:connect(Pid), ejabberd_s2s_out:connect(Pid),
State {stop, State}
catch _:{badmatch, {error, Reason}} -> catch _:{badmatch, {error, Reason}} ->
{stop,
send_db_result(State, send_db_result(State,
#db_verify{from = From, to = To, type = error, #db_verify{from = From, to = To, type = error,
sub_els = [mk_error(Reason)]}) sub_els = [mk_error(Reason)]})}
end; end;
s2s_in_packet(State, #db_verify{to = To, from = From, key = Key, s2s_in_packet(State, #db_verify{to = To, from = From, key = Key,
id = StreamID, type = undefined}) -> id = StreamID, type = undefined}) ->
@ -189,7 +190,7 @@ s2s_in_packet(State, #db_verify{to = To, from = From, key = Key,
_ -> invalid _ -> invalid
end, end,
Response = #db_verify{from = To, to = From, id = StreamID, type = Type}, Response = #db_verify{from = To, to = From, id = StreamID, type = Type},
ejabberd_s2s_in:send(State, Response); {stop, ejabberd_s2s_in:send(State, Response)};
s2s_in_packet(State, Pkt) when is_record(Pkt, db_result); s2s_in_packet(State, Pkt) when is_record(Pkt, db_result);
is_record(Pkt, db_verify) -> is_record(Pkt, db_verify) ->
?WARNING_MSG("Got stray dialback packet:~n~s", [xmpp:pp(Pkt)]), ?WARNING_MSG("Got stray dialback packet:~n~s", [xmpp:pp(Pkt)]),

View File

@ -292,7 +292,7 @@ set_item(User, Server, Resource, Item) ->
jid:make(Server), jid:make(Server),
ResIQ). ResIQ).
c2s_session_opened(#{jid := #jid{luser = LUser, lserver = LServer} = JID, c2s_session_opened(#{jid := #jid{luser = LUser, lserver = LServer},
pres_f := PresF, pres_t := PresT} = State) -> pres_f := PresF, pres_t := PresT} = State) ->
US = {LUser, LServer}, US = {LUser, LServer},
DisplayedGroups = get_user_displayed_groups(US), DisplayedGroups = get_user_displayed_groups(US),
@ -300,11 +300,12 @@ c2s_session_opened(#{jid := #jid{luser = LUser, lserver = LServer} = JID,
get_group_users(LServer, Group) get_group_users(LServer, Group)
end, end,
DisplayedGroups), DisplayedGroups),
BareLJID = jid:tolower(jid:remove_resource(JID)),
PresBoth = lists:foldl( PresBoth = lists:foldl(
fun({U, S}, Acc) -> fun({U, S, _}, Acc) ->
?SETS:add_element({U, S, <<"">>}, Acc);
({U, S}, Acc) ->
?SETS:add_element({U, S, <<"">>}, Acc) ?SETS:add_element({U, S, <<"">>}, Acc)
end, ?SETS:new(), [BareLJID|SRUsers]), end, ?SETS:new(), SRUsers),
State#{pres_f => ?SETS:union(PresBoth, PresF), State#{pres_f => ?SETS:union(PresBoth, PresF),
pres_t => ?SETS:union(PresBoth, PresT)}. pres_t => ?SETS:union(PresBoth, PresT)}.

View File

@ -161,7 +161,7 @@ process_item(RosterItem, _Host) ->
_ -> RosterItem#roster{subscription = both, ask = none} _ -> RosterItem#roster{subscription = both, ask = none}
end. end.
c2s_session_opened(#{jid := #jid{luser = LUser, lserver = LServer} = JID, c2s_session_opened(#{jid := #jid{luser = LUser, lserver = LServer},
pres_f := PresF, pres_t := PresT} = State) -> pres_f := PresF, pres_t := PresT} = State) ->
US = {LUser, LServer}, US = {LUser, LServer},
DisplayedGroups = get_user_displayed_groups(US), DisplayedGroups = get_user_displayed_groups(US),
@ -169,11 +169,12 @@ c2s_session_opened(#{jid := #jid{luser = LUser, lserver = LServer} = JID,
get_group_users(LServer, Group) get_group_users(LServer, Group)
end, end,
DisplayedGroups), DisplayedGroups),
BareLJID = jid:tolower(jid:remove_resource(JID)),
PresBoth = lists:foldl( PresBoth = lists:foldl(
fun({U, S}, Acc) -> fun({U, S, _}, Acc) ->
?SETS:add_element({U, S, <<"">>}, Acc);
({U, S}, Acc) ->
?SETS:add_element({U, S, <<"">>}, Acc) ?SETS:add_element({U, S, <<"">>}, Acc)
end, ?SETS:new(), [BareLJID|SRUsers]), end, ?SETS:new(), SRUsers),
State#{pres_f => ?SETS:union(PresBoth, PresF), State#{pres_f => ?SETS:union(PresBoth, PresF),
pres_t => ?SETS:union(PresBoth, PresT)}. pres_t => ?SETS:union(PresBoth, PresT)}.

View File

@ -559,8 +559,8 @@ process_element(Pkt, #{stream_state := StateName, lang := Lang} = State) ->
process_unauthenticated_packet(Pkt, State); process_unauthenticated_packet(Pkt, State);
_ when StateName == wait_for_starttls -> _ when StateName == wait_for_starttls ->
Txt = <<"Use of STARTTLS required">>, Txt = <<"Use of STARTTLS required">>,
Err = xmpp:err_policy_violation(Txt, Lang), Err = xmpp:serr_policy_violation(Txt, Lang),
send_error(State, Pkt, Err); send_pkt(State, Err);
_ when StateName == wait_for_bind -> _ when StateName == wait_for_bind ->
process_bind(Pkt, State); process_bind(Pkt, State);
_ when StateName == established -> _ when StateName == established ->

View File

@ -285,6 +285,8 @@ init_per_testcase(TestCase, OrigConfig) ->
case Test of case Test of
"test_connect" ++ _ -> "test_connect" ++ _ ->
Config; Config;
"test_legacy_auth_feature" ->
connect(Config);
"test_legacy_auth" ++ _ -> "test_legacy_auth" ++ _ ->
init_stream(set_opt(stream_version, undefined, Config)); init_stream(set_opt(stream_version, undefined, Config));
"test_auth" ++ _ -> "test_auth" ++ _ ->
@ -326,7 +328,8 @@ end_per_testcase(_TestCase, _Config) ->
legacy_auth_tests() -> legacy_auth_tests() ->
{legacy_auth, [parallel], {legacy_auth, [parallel],
[test_legacy_auth, [test_legacy_auth_feature,
test_legacy_auth,
test_legacy_auth_digest, test_legacy_auth_digest,
test_legacy_auth_no_resource, test_legacy_auth_no_resource,
test_legacy_auth_bad_jid, test_legacy_auth_bad_jid,
@ -344,7 +347,8 @@ no_db_tests() ->
test_connect_missing_to, test_connect_missing_to,
test_connect, test_connect,
unauthenticated_iq, unauthenticated_iq,
unauthenticated_stanza, unauthenticated_message,
unauthenticated_presence,
test_starttls, test_starttls,
test_zlib, test_zlib,
test_auth, test_auth,
@ -481,7 +485,8 @@ component_tests() ->
test_auth, test_auth,
test_auth_fail]}, test_auth_fail]},
{component_tests, [sequence], {component_tests, [sequence],
[test_missing_address, [test_missing_from,
test_missing_to,
test_invalid_from, test_invalid_from,
test_component_send, test_component_send,
bad_nonza, bad_nonza,
@ -497,11 +502,11 @@ s2s_tests() ->
test_connect, test_connect,
test_connect_s2s_starttls_required, test_connect_s2s_starttls_required,
test_starttls, test_starttls,
test_connect_missing_from,
test_connect_s2s_unauthenticated_iq, test_connect_s2s_unauthenticated_iq,
test_auth_starttls]}, test_auth_starttls]},
{s2s_tests, [sequence], {s2s_tests, [sequence],
[test_missing_address, [test_missing_from,
test_missing_to,
test_invalid_from, test_invalid_from,
bad_nonza, bad_nonza,
codec_failure]}]. codec_failure]}].
@ -598,20 +603,12 @@ test_connect_missing_to(Config) ->
?recv1({xmlstreamend, <<"stream:stream">>}), ?recv1({xmlstreamend, <<"stream:stream">>}),
close_socket(Config0). close_socket(Config0).
test_connect_missing_from(Config) ->
Config1 = starttls(connect(Config)),
Config2 = set_opt(stream_from, <<"">>, Config1),
Config3 = init_stream(Config2),
?recv1(#stream_error{reason = 'policy-violation'}),
?recv1({xmlstreamend, <<"stream:stream">>}),
close_socket(Config3).
test_connect(Config) -> test_connect(Config) ->
disconnect(connect(Config)). disconnect(connect(Config)).
test_connect_s2s_starttls_required(Config) -> test_connect_s2s_starttls_required(Config) ->
Config1 = connect(Config), Config1 = connect(Config),
send(Config1, #caps{}), send(Config1, #presence{}),
?recv1(#stream_error{reason = 'policy-violation'}), ?recv1(#stream_error{reason = 'policy-violation'}),
?recv1({xmlstreamend, <<"stream:stream">>}), ?recv1({xmlstreamend, <<"stream:stream">>}),
close_socket(Config1). close_socket(Config1).
@ -681,18 +678,23 @@ try_unregister(Config) ->
?recv1(#stream_error{reason = conflict}), ?recv1(#stream_error{reason = conflict}),
Config. Config.
unauthenticated_stanza(Config) -> unauthenticated_presence(Config) ->
%% Unauthenticated stanza should be silently dropped. unauthenticated_packet(Config, #presence{}).
send(Config, #message{to = server_jid(Config)}),
disconnect(Config). unauthenticated_message(Config) ->
unauthenticated_packet(Config, #message{}).
unauthenticated_iq(Config) -> unauthenticated_iq(Config) ->
IQ = #iq{type = get, sub_els = [#disco_info{}]},
unauthenticated_packet(Config, IQ).
unauthenticated_packet(Config, Pkt) ->
From = my_jid(Config), From = my_jid(Config),
To = server_jid(Config), To = server_jid(Config),
#iq{type = error} = send(Config, xmpp:set_from_to(Pkt, From, To)),
send_recv(Config, #iq{type = get, from = From, to = To, #stream_error{reason = 'not-authorized'} = recv(Config),
sub_els = [#disco_info{}]}), {xmlstreamend, <<"stream:stream">>} = recv(Config),
disconnect(Config). close_socket(Config).
bad_nonza(Config) -> bad_nonza(Config) ->
%% Unsupported and invalid nonza should be silently dropped. %% Unsupported and invalid nonza should be silently dropped.
@ -706,18 +708,27 @@ invalid_from(Config) ->
?recv1({xmlstreamend, <<"stream:stream">>}), ?recv1({xmlstreamend, <<"stream:stream">>}),
close_socket(Config). close_socket(Config).
test_missing_address(Config) -> test_missing_from(Config) ->
Server = server_jid(Config), Server = server_jid(Config),
#iq{type = error} = send_recv(Config, #iq{type = get, from = Server}), send(Config, #message{to = Server}),
#iq{type = error} = send_recv(Config, #iq{type = get, to = Server}), ?recv1(#stream_error{reason = 'improper-addressing'}),
disconnect(Config). ?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).
test_invalid_from(Config) -> test_invalid_from(Config) ->
From = jid:make(randoms:get_string()), From = jid:make(randoms:get_string()),
To = jid:make(randoms:get_string()), To = jid:make(randoms:get_string()),
#iq{type = error} = send(Config, #message{from = From, to = To}),
send_recv(Config, #iq{type = get, from = From, to = To}), ?recv1(#stream_error{reason = 'invalid-from'}),
disconnect(Config). ?recv1({xmlstreamend, <<"stream:stream">>}),
close_socket(Config).
test_component_send(Config) -> test_component_send(Config) ->
To = jid:make(?COMMON_VHOST), To = jid:make(?COMMON_VHOST),
@ -779,6 +790,10 @@ auth_plain(Config) ->
{skipped, 'PLAIN_not_available'} {skipped, 'PLAIN_not_available'}
end. end.
test_legacy_auth_feature(Config) ->
true = ?config(legacy_auth, Config),
disconnect(Config).
test_legacy_auth(Config) -> test_legacy_auth(Config) ->
disconnect(auth_legacy(Config, _Digest = false)). disconnect(auth_legacy(Config, _Digest = false)).

View File

@ -51,6 +51,8 @@ host_config:
mod_disco: [] mod_disco: []
mod_ping: [] mod_ping: []
mod_proxy65: [] mod_proxy65: []
mod_s2s_dialback: []
mod_legacy_auth: []
mod_register: mod_register:
welcome_message: welcome_message:
subject: "Welcome!" subject: "Welcome!"
@ -106,6 +108,8 @@ Welcome to this XMPP server."
mod_disco: [] mod_disco: []
mod_ping: [] mod_ping: []
mod_proxy65: [] mod_proxy65: []
mod_s2s_dialback: []
mod_legacy_auth: []
mod_register: mod_register:
welcome_message: welcome_message:
subject: "Welcome!" subject: "Welcome!"
@ -166,6 +170,8 @@ Welcome to this XMPP server."
mod_disco: [] mod_disco: []
mod_ping: [] mod_ping: []
mod_proxy65: [] mod_proxy65: []
mod_s2s_dialback: []
mod_legacy_auth: []
mod_register: mod_register:
welcome_message: welcome_message:
subject: "Welcome!" subject: "Welcome!"
@ -222,6 +228,8 @@ Welcome to this XMPP server."
mod_disco: [] mod_disco: []
mod_ping: [] mod_ping: []
mod_proxy65: [] mod_proxy65: []
mod_s2s_dialback: []
mod_legacy_auth: []
mod_register: mod_register:
welcome_message: welcome_message:
subject: "Welcome!" subject: "Welcome!"
@ -279,6 +287,8 @@ Welcome to this XMPP server."
mod_disco: [] mod_disco: []
mod_ping: [] mod_ping: []
mod_proxy65: [] mod_proxy65: []
mod_s2s_dialback: []
mod_legacy_auth: []
mod_register: mod_register:
welcome_message: welcome_message:
subject: "Welcome!" subject: "Welcome!"
@ -319,6 +329,8 @@ Welcome to this XMPP server."
mod_disco: [] mod_disco: []
mod_ping: [] mod_ping: []
mod_proxy65: [] mod_proxy65: []
mod_s2s_dialback: []
mod_legacy_auth: []
mod_register: mod_register:
welcome_message: welcome_message:
subject: "Welcome!" subject: "Welcome!"
@ -450,6 +462,9 @@ modules:
body: "Hi. body: "Hi.
Welcome to this XMPP server." Welcome to this XMPP server."
mod_stats: [] mod_stats: []
mod_s2s_dialback: []
mod_legacy_auth: []
mod_sm: []
mod_time: [] mod_time: []
mod_version: [] mod_version: []
registration_timeout: infinity registration_timeout: infinity

View File

@ -235,6 +235,8 @@ process_stream_features(Config) ->
set_opt(register, true, Acc); set_opt(register, true, Acc);
(#starttls{}, Acc) -> (#starttls{}, Acc) ->
set_opt(starttls, true, Acc); set_opt(starttls, true, Acc);
(#legacy_auth_feature{}, Acc) ->
set_opt(legacy_auth, true, Acc);
(#compression{methods = Ms}, Acc) -> (#compression{methods = Ms}, Acc) ->
set_opt(compression, Ms, Acc); set_opt(compression, Ms, Acc);
(_, Acc) -> (_, Acc) ->
@ -246,7 +248,7 @@ disconnect(Config) ->
ct:comment("Disconnecting"), ct:comment("Disconnecting"),
Socket = ?config(socket, Config), Socket = ?config(socket, Config),
try try
ok = send_text(Config, ?STREAM_TRAILER) send_text(Config, ?STREAM_TRAILER)
catch exit:normal -> catch exit:normal ->
ok ok
end, end,
@ -274,7 +276,7 @@ starttls(Config, ShouldFail) ->
#starttls_failure{} -> #starttls_failure{} ->
ct:fail(starttls_failed); ct:fail(starttls_failed);
#starttls_proceed{} -> #starttls_proceed{} ->
TLSSocket = ejabberd_socket:starttls( {ok, TLSSocket} = ejabberd_socket:starttls(
?config(socket, Config), ?config(socket, Config),
[{certfile, ?config(certfile, Config)}, [{certfile, ?config(certfile, Config)},
connect]), connect]),
@ -284,7 +286,7 @@ starttls(Config, ShouldFail) ->
zlib(Config) -> zlib(Config) ->
send(Config, #compress{methods = [<<"zlib">>]}), send(Config, #compress{methods = [<<"zlib">>]}),
receive #compressed{} -> ok end, receive #compressed{} -> ok end,
ZlibSocket = ejabberd_socket:compress(?config(socket, Config)), {ok, ZlibSocket} = ejabberd_socket:compress(?config(socket, Config)),
process_stream_features(init_stream(set_opt(socket, ZlibSocket, Config))). process_stream_features(init_stream(set_opt(socket, ZlibSocket, Config))).
auth(Config) -> auth(Config) ->