mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-20 17:27:00 +01:00
Test anonymous auth
This commit is contained in:
parent
7100c67be6
commit
3112a7187f
@ -522,7 +522,7 @@
|
||||
-type version() :: #version{}.
|
||||
|
||||
-record(bind, {jid :: jid:jid(),
|
||||
resource :: binary()}).
|
||||
resource = <<>> :: binary()}).
|
||||
-type bind() :: #bind{}.
|
||||
|
||||
-record(rosterver_feature, {}).
|
||||
|
@ -907,8 +907,12 @@ wait_for_bind(#sm_resume{} = Pkt, StateData) ->
|
||||
wait_for_bind(Pkt, StateData) when ?IS_STREAM_MGMT_PACKET(Pkt) ->
|
||||
fsm_next_state(wait_for_bind, dispatch_stream_mgmt(Pkt, StateData));
|
||||
wait_for_bind(#iq{type = set,
|
||||
sub_els = [#bind{resource = R}]} = IQ, StateData) ->
|
||||
sub_els = [#bind{resource = R0}]} = IQ, StateData) ->
|
||||
U = StateData#state.user,
|
||||
R = case R0 of
|
||||
<<>> -> new_uniq_id();
|
||||
_ -> R0
|
||||
end,
|
||||
case resource_conflict_action(U, StateData#state.server, R) of
|
||||
closenew ->
|
||||
Err = xmpp:make_error(IQ, xmpp:err_conflict()),
|
||||
|
@ -29737,7 +29737,7 @@ encode_legacy_auth_username_cdata(_val, _acc) ->
|
||||
decode_bind(__TopXMLNS, __IgnoreEls,
|
||||
{xmlel, <<"bind">>, _attrs, _els}) ->
|
||||
{Jid, Resource} = decode_bind_els(__TopXMLNS,
|
||||
__IgnoreEls, _els, undefined, undefined),
|
||||
__IgnoreEls, _els, undefined, <<>>),
|
||||
{bind, Jid, Resource}.
|
||||
|
||||
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_$resource'(undefined, __TopXMLNS, _acc) ->
|
||||
_acc;
|
||||
'encode_bind_$resource'(<<>>, __TopXMLNS, _acc) -> _acc;
|
||||
'encode_bind_$resource'(Resource, __TopXMLNS, _acc) ->
|
||||
[encode_bind_resource(Resource, __TopXMLNS) | _acc].
|
||||
|
||||
|
@ -148,9 +148,13 @@ do_init_per_group(component, Config) ->
|
||||
set_opt(server_port, Port,
|
||||
set_opt(stream_version, undefined,
|
||||
set_opt(lang, <<"">>, Config))))));
|
||||
do_init_per_group(_GroupName, Config) ->
|
||||
do_init_per_group(GroupName, Config) ->
|
||||
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) ->
|
||||
ok;
|
||||
@ -176,7 +180,7 @@ end_per_group(s2s, _Config) ->
|
||||
ejabberd_config:add_option(s2s_use_starttls, false);
|
||||
end_per_group(_GroupName, Config) ->
|
||||
stop_event_relay(Config),
|
||||
ok.
|
||||
set_opt(anonymous, false, Config).
|
||||
|
||||
init_per_testcase(stop_ejabberd, Config) ->
|
||||
open_session(bind(auth(connect(Config))));
|
||||
@ -186,8 +190,8 @@ init_per_testcase(TestCase, OrigConfig) ->
|
||||
name, ?config(tc_group_properties, OrigConfig)),
|
||||
Server = ?config(server, OrigConfig),
|
||||
Resource = case TestGroup of
|
||||
generic ->
|
||||
randoms:get_string();
|
||||
anonymous ->
|
||||
<<"">>;
|
||||
legacy_auth ->
|
||||
randoms:get_string();
|
||||
_ ->
|
||||
@ -278,7 +282,7 @@ legacy_auth_tests() ->
|
||||
test_legacy_auth_fail]}.
|
||||
|
||||
no_db_tests() ->
|
||||
[{generic, [parallel],
|
||||
[{anonymous, [parallel],
|
||||
[test_connect_bad_xml,
|
||||
test_connect_unexpected_xml,
|
||||
test_connect_unknown_ns,
|
||||
@ -293,7 +297,6 @@ no_db_tests() ->
|
||||
test_starttls,
|
||||
test_zlib,
|
||||
test_auth,
|
||||
test_auth_fail,
|
||||
test_bind,
|
||||
test_open_session,
|
||||
codec_failure,
|
||||
@ -306,7 +309,8 @@ no_db_tests() ->
|
||||
stats,
|
||||
disco]},
|
||||
{presence_and_s2s, [sequence],
|
||||
[presence,
|
||||
[test_auth_fail,
|
||||
presence,
|
||||
s2s_dialback,
|
||||
s2s_optional,
|
||||
s2s_required,
|
||||
@ -507,17 +511,17 @@ groups() ->
|
||||
{riak, [sequence], db_tests(riak)}].
|
||||
|
||||
all() ->
|
||||
[{group, ldap},
|
||||
[%%{group, ldap},
|
||||
{group, no_db},
|
||||
{group, mnesia},
|
||||
{group, redis},
|
||||
{group, mysql},
|
||||
{group, pgsql},
|
||||
{group, sqlite},
|
||||
{group, extauth},
|
||||
{group, riak},
|
||||
{group, component},
|
||||
{group, s2s},
|
||||
%% {group, mnesia},
|
||||
%% {group, redis},
|
||||
%% {group, mysql},
|
||||
%% {group, pgsql},
|
||||
%% {group, sqlite},
|
||||
%% {group, extauth},
|
||||
%% {group, riak},
|
||||
%% {group, component},
|
||||
%% {group, s2s},
|
||||
stop_ejabberd].
|
||||
|
||||
stop_ejabberd(Config) ->
|
||||
|
@ -327,7 +327,7 @@ Welcome to this XMPP server."
|
||||
mod_time: []
|
||||
mod_version: []
|
||||
"localhost":
|
||||
auth_method: internal
|
||||
auth_method: [internal, anonymous]
|
||||
"ldap.localhost":
|
||||
ldap_servers:
|
||||
- "localhost"
|
||||
|
@ -74,6 +74,7 @@ init_config(Config) ->
|
||||
{slave_nick, <<"slave_nick!@#$%^&*()'\"`~<>+-/;:_=[]{}|\\">>},
|
||||
{room_subject, <<"hello, world!@#$%^&*()'\"`~<>+-/;:_=[]{}|\\">>},
|
||||
{certfile, CertFile},
|
||||
{anonymous, false},
|
||||
{type, client},
|
||||
{xmlns, ?NS_CLIENT},
|
||||
{ns_stream, ?NS_STREAM},
|
||||
@ -253,11 +254,15 @@ auth(Config) ->
|
||||
|
||||
auth(Config, ShouldFail) ->
|
||||
Type = ?config(type, Config),
|
||||
IsAnonymous = ?config(anonymous, Config),
|
||||
Mechs = ?config(mechs, Config),
|
||||
HaveMD5 = lists:member(<<"DIGEST-MD5">>, Mechs),
|
||||
HavePLAIN = lists:member(<<"PLAIN">>, 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);
|
||||
HaveMD5 ->
|
||||
auth_SASL(<<"DIGEST-MD5">>, Config, ShouldFail);
|
||||
@ -272,17 +277,25 @@ auth(Config, ShouldFail) ->
|
||||
end.
|
||||
|
||||
bind(Config) ->
|
||||
U = ?config(user, Config),
|
||||
S = ?config(server, Config),
|
||||
R = ?config(resource, Config),
|
||||
case ?config(type, Config) of
|
||||
client ->
|
||||
#iq{type = result, sub_els = [#bind{}]} =
|
||||
#iq{type = result, sub_els = [#bind{jid = JID}]} =
|
||||
send_recv(
|
||||
Config,
|
||||
#iq{type = set,
|
||||
sub_els = [#bind{resource = ?config(resource, Config)}]});
|
||||
Config, #iq{type = set, sub_els = [#bind{resource = R}]}),
|
||||
case ?config(anonymous, Config) of
|
||||
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 ->
|
||||
ok
|
||||
end,
|
||||
Config.
|
||||
Config
|
||||
end.
|
||||
|
||||
open_session(Config) ->
|
||||
open_session(Config, false).
|
||||
@ -478,6 +491,9 @@ sasl_new(<<"PLAIN">>, User, Server, Password) ->
|
||||
sasl_new(<<"EXTERNAL">>, _User, _Server, _Password) ->
|
||||
{<<"">>,
|
||||
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) ->
|
||||
{<<"">>,
|
||||
fun (ServerIn) ->
|
||||
|
@ -621,6 +621,7 @@
|
||||
min = 0, max = 1},
|
||||
#ref{name = bind_resource,
|
||||
min = 0, max = 1,
|
||||
default = <<"">>,
|
||||
label = '$resource'}]}).
|
||||
|
||||
-xml(legacy_auth_username,
|
||||
|
Loading…
Reference in New Issue
Block a user