Test anonymous auth

This commit is contained in:
Evgeniy Khramtsov 2016-09-25 09:57:56 +03:00
parent 7100c67be6
commit 3112a7187f
7 changed files with 56 additions and 32 deletions

View File

@ -522,7 +522,7 @@
-type version() :: #version{}. -type version() :: #version{}.
-record(bind, {jid :: jid:jid(), -record(bind, {jid :: jid:jid(),
resource :: binary()}). resource = <<>> :: binary()}).
-type bind() :: #bind{}. -type bind() :: #bind{}.
-record(rosterver_feature, {}). -record(rosterver_feature, {}).

View File

@ -907,8 +907,12 @@ wait_for_bind(#sm_resume{} = Pkt, StateData) ->
wait_for_bind(Pkt, StateData) when ?IS_STREAM_MGMT_PACKET(Pkt) -> wait_for_bind(Pkt, StateData) when ?IS_STREAM_MGMT_PACKET(Pkt) ->
fsm_next_state(wait_for_bind, dispatch_stream_mgmt(Pkt, StateData)); fsm_next_state(wait_for_bind, dispatch_stream_mgmt(Pkt, StateData));
wait_for_bind(#iq{type = set, wait_for_bind(#iq{type = set,
sub_els = [#bind{resource = R}]} = IQ, StateData) -> sub_els = [#bind{resource = R0}]} = IQ, StateData) ->
U = StateData#state.user, U = StateData#state.user,
R = case R0 of
<<>> -> new_uniq_id();
_ -> R0
end,
case resource_conflict_action(U, StateData#state.server, R) of case resource_conflict_action(U, StateData#state.server, R) of
closenew -> closenew ->
Err = xmpp:make_error(IQ, xmpp:err_conflict()), Err = xmpp:make_error(IQ, xmpp:err_conflict()),

View File

@ -29737,7 +29737,7 @@ encode_legacy_auth_username_cdata(_val, _acc) ->
decode_bind(__TopXMLNS, __IgnoreEls, decode_bind(__TopXMLNS, __IgnoreEls,
{xmlel, <<"bind">>, _attrs, _els}) -> {xmlel, <<"bind">>, _attrs, _els}) ->
{Jid, Resource} = decode_bind_els(__TopXMLNS, {Jid, Resource} = decode_bind_els(__TopXMLNS,
__IgnoreEls, _els, undefined, undefined), __IgnoreEls, _els, undefined, <<>>),
{bind, Jid, Resource}. {bind, Jid, Resource}.
decode_bind_els(__TopXMLNS, __IgnoreEls, [], Jid, decode_bind_els(__TopXMLNS, __IgnoreEls, [], Jid,
@ -29800,8 +29800,7 @@ encode_bind({bind, Jid, Resource}, __TopXMLNS) ->
'encode_bind_$jid'(Jid, __TopXMLNS, _acc) -> 'encode_bind_$jid'(Jid, __TopXMLNS, _acc) ->
[encode_bind_jid(Jid, __TopXMLNS) | _acc]. [encode_bind_jid(Jid, __TopXMLNS) | _acc].
'encode_bind_$resource'(undefined, __TopXMLNS, _acc) -> 'encode_bind_$resource'(<<>>, __TopXMLNS, _acc) -> _acc;
_acc;
'encode_bind_$resource'(Resource, __TopXMLNS, _acc) -> 'encode_bind_$resource'(Resource, __TopXMLNS, _acc) ->
[encode_bind_resource(Resource, __TopXMLNS) | _acc]. [encode_bind_resource(Resource, __TopXMLNS) | _acc].

View File

@ -148,9 +148,13 @@ do_init_per_group(component, Config) ->
set_opt(server_port, Port, set_opt(server_port, Port,
set_opt(stream_version, undefined, set_opt(stream_version, undefined,
set_opt(lang, <<"">>, Config)))))); set_opt(lang, <<"">>, Config))))));
do_init_per_group(_GroupName, Config) -> do_init_per_group(GroupName, Config) ->
Pid = start_event_relay(), Pid = start_event_relay(),
set_opt(event_relay, Pid, Config). NewConfig = set_opt(event_relay, Pid, Config),
case GroupName of
anonymous -> set_opt(anonymous, true, NewConfig);
_ -> NewConfig
end.
end_per_group(mnesia, _Config) -> end_per_group(mnesia, _Config) ->
ok; ok;
@ -176,7 +180,7 @@ end_per_group(s2s, _Config) ->
ejabberd_config:add_option(s2s_use_starttls, false); ejabberd_config:add_option(s2s_use_starttls, false);
end_per_group(_GroupName, Config) -> end_per_group(_GroupName, Config) ->
stop_event_relay(Config), stop_event_relay(Config),
ok. set_opt(anonymous, false, Config).
init_per_testcase(stop_ejabberd, Config) -> init_per_testcase(stop_ejabberd, Config) ->
open_session(bind(auth(connect(Config)))); open_session(bind(auth(connect(Config))));
@ -186,8 +190,8 @@ init_per_testcase(TestCase, OrigConfig) ->
name, ?config(tc_group_properties, OrigConfig)), name, ?config(tc_group_properties, OrigConfig)),
Server = ?config(server, OrigConfig), Server = ?config(server, OrigConfig),
Resource = case TestGroup of Resource = case TestGroup of
generic -> anonymous ->
randoms:get_string(); <<"">>;
legacy_auth -> legacy_auth ->
randoms:get_string(); randoms:get_string();
_ -> _ ->
@ -278,7 +282,7 @@ legacy_auth_tests() ->
test_legacy_auth_fail]}. test_legacy_auth_fail]}.
no_db_tests() -> no_db_tests() ->
[{generic, [parallel], [{anonymous, [parallel],
[test_connect_bad_xml, [test_connect_bad_xml,
test_connect_unexpected_xml, test_connect_unexpected_xml,
test_connect_unknown_ns, test_connect_unknown_ns,
@ -293,7 +297,6 @@ no_db_tests() ->
test_starttls, test_starttls,
test_zlib, test_zlib,
test_auth, test_auth,
test_auth_fail,
test_bind, test_bind,
test_open_session, test_open_session,
codec_failure, codec_failure,
@ -306,7 +309,8 @@ no_db_tests() ->
stats, stats,
disco]}, disco]},
{presence_and_s2s, [sequence], {presence_and_s2s, [sequence],
[presence, [test_auth_fail,
presence,
s2s_dialback, s2s_dialback,
s2s_optional, s2s_optional,
s2s_required, s2s_required,
@ -507,17 +511,17 @@ groups() ->
{riak, [sequence], db_tests(riak)}]. {riak, [sequence], db_tests(riak)}].
all() -> all() ->
[{group, ldap}, [%%{group, ldap},
{group, no_db}, {group, no_db},
{group, mnesia}, %% {group, mnesia},
{group, redis}, %% {group, redis},
{group, mysql}, %% {group, mysql},
{group, pgsql}, %% {group, pgsql},
{group, sqlite}, %% {group, sqlite},
{group, extauth}, %% {group, extauth},
{group, riak}, %% {group, riak},
{group, component}, %% {group, component},
{group, s2s}, %% {group, s2s},
stop_ejabberd]. stop_ejabberd].
stop_ejabberd(Config) -> stop_ejabberd(Config) ->

View File

@ -327,7 +327,7 @@ Welcome to this XMPP server."
mod_time: [] mod_time: []
mod_version: [] mod_version: []
"localhost": "localhost":
auth_method: internal auth_method: [internal, anonymous]
"ldap.localhost": "ldap.localhost":
ldap_servers: ldap_servers:
- "localhost" - "localhost"

View File

@ -74,6 +74,7 @@ init_config(Config) ->
{slave_nick, <<"slave_nick!@#$%^&*()'\"`~<>+-/;:_=[]{}|\\">>}, {slave_nick, <<"slave_nick!@#$%^&*()'\"`~<>+-/;:_=[]{}|\\">>},
{room_subject, <<"hello, world!@#$%^&*()'\"`~<>+-/;:_=[]{}|\\">>}, {room_subject, <<"hello, world!@#$%^&*()'\"`~<>+-/;:_=[]{}|\\">>},
{certfile, CertFile}, {certfile, CertFile},
{anonymous, false},
{type, client}, {type, client},
{xmlns, ?NS_CLIENT}, {xmlns, ?NS_CLIENT},
{ns_stream, ?NS_STREAM}, {ns_stream, ?NS_STREAM},
@ -253,11 +254,15 @@ auth(Config) ->
auth(Config, ShouldFail) -> auth(Config, ShouldFail) ->
Type = ?config(type, Config), Type = ?config(type, Config),
IsAnonymous = ?config(anonymous, Config),
Mechs = ?config(mechs, Config), Mechs = ?config(mechs, Config),
HaveMD5 = lists:member(<<"DIGEST-MD5">>, Mechs), HaveMD5 = lists:member(<<"DIGEST-MD5">>, Mechs),
HavePLAIN = lists:member(<<"PLAIN">>, Mechs), HavePLAIN = lists:member(<<"PLAIN">>, Mechs),
HaveExternal = lists:member(<<"EXTERNAL">>, Mechs), HaveExternal = lists:member(<<"EXTERNAL">>, Mechs),
if HavePLAIN -> HaveAnonymous = lists:member(<<"ANONYMOUS">>, Mechs),
if HaveAnonymous and IsAnonymous ->
auth_SASL(<<"ANONYMOUS">>, Config, ShouldFail);
HavePLAIN ->
auth_SASL(<<"PLAIN">>, Config, ShouldFail); auth_SASL(<<"PLAIN">>, Config, ShouldFail);
HaveMD5 -> HaveMD5 ->
auth_SASL(<<"DIGEST-MD5">>, Config, ShouldFail); auth_SASL(<<"DIGEST-MD5">>, Config, ShouldFail);
@ -272,17 +277,25 @@ auth(Config, ShouldFail) ->
end. end.
bind(Config) -> bind(Config) ->
U = ?config(user, Config),
S = ?config(server, Config),
R = ?config(resource, Config),
case ?config(type, Config) of case ?config(type, Config) of
client -> client ->
#iq{type = result, sub_els = [#bind{}]} = #iq{type = result, sub_els = [#bind{jid = JID}]} =
send_recv( send_recv(
Config, Config, #iq{type = set, sub_els = [#bind{resource = R}]}),
#iq{type = set, case ?config(anonymous, Config) of
sub_els = [#bind{resource = ?config(resource, Config)}]}); false ->
{U, S, R} = jid:tolower(JID),
Config;
true ->
{User, S, Resource} = jid:tolower(JID),
set_opt(user, User, set_opt(resource, Resource, Config))
end;
component -> component ->
ok Config
end, end.
Config.
open_session(Config) -> open_session(Config) ->
open_session(Config, false). open_session(Config, false).
@ -478,6 +491,9 @@ sasl_new(<<"PLAIN">>, User, Server, Password) ->
sasl_new(<<"EXTERNAL">>, _User, _Server, _Password) -> sasl_new(<<"EXTERNAL">>, _User, _Server, _Password) ->
{<<"">>, {<<"">>,
fun(_) -> ct:fail(sasl_challenge_is_not_expected) end}; fun(_) -> ct:fail(sasl_challenge_is_not_expected) end};
sasl_new(<<"ANONYMOUS">>, _User, _Server, _Password) ->
{<<"">>,
fun(_) -> ct:fail(sasl_challenge_is_not_expected) end};
sasl_new(<<"DIGEST-MD5">>, User, Server, Password) -> sasl_new(<<"DIGEST-MD5">>, User, Server, Password) ->
{<<"">>, {<<"">>,
fun (ServerIn) -> fun (ServerIn) ->

View File

@ -621,6 +621,7 @@
min = 0, max = 1}, min = 0, max = 1},
#ref{name = bind_resource, #ref{name = bind_resource,
min = 0, max = 1, min = 0, max = 1,
default = <<"">>,
label = '$resource'}]}). label = '$resource'}]}).
-xml(legacy_auth_username, -xml(legacy_auth_username,