]> granicus.if.org Git - ejabberd/commitdiff
Test anonymous auth
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>
Sun, 25 Sep 2016 06:57:56 +0000 (09:57 +0300)
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>
Sun, 25 Sep 2016 06:57:56 +0000 (09:57 +0300)
include/xmpp_codec.hrl
src/ejabberd_c2s.erl
src/xmpp_codec.erl
test/ejabberd_SUITE.erl
test/ejabberd_SUITE_data/ejabberd.yml
test/suite.erl
tools/xmpp_codec.spec

index 5428aad1176c68100c6210f130e698d2c71a08be..8ffb3780805fc26f49310fcea8279f4b4b7ebf56 100644 (file)
 -type version() :: #version{}.
 
 -record(bind, {jid :: jid:jid(),
-               resource :: binary()}).
+               resource = <<>> :: binary()}).
 -type bind() :: #bind{}.
 
 -record(rosterver_feature, {}).
index 02540259a269a37cc09918d81ecea8afd7a08587..f7d8e9dbb579b566c139f6b4c54788f80a0bf5c6 100644 (file)
@@ -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()),
index a0181e1e6805e47fe429ea915c83c75e7dd9fa4c..f8f8b205f198a86b2989cec81e6a070397d62c50 100644 (file)
@@ -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].
 
index b5aa50bdbe6326890fed4304d93c3ce02993e495..4e02389d4886da36e45d15dea9769ab56448e2ab 100644 (file)
@@ -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) ->
index 128be2aed14a89b28a2c749f7f0ee2f7049e9bfd..c9ea5fd7abca26632f20db6ba66a45305d4bff12 100644 (file)
@@ -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"
index e10c7e0c47d4ff73a68d0c5c1b34206c165fdee2..42c5dcfbe1e691e5b4e6ec9794a6c55e1fdf2e28 100644 (file)
@@ -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) ->
index 6824cf3877c4de863273a05f4d916477aaad6f1c..1f9b50066137d820c9880aeb5d0e565b687b7fe3 100644 (file)
                               min = 0, max = 1},
                          #ref{name = bind_resource,
                               min = 0, max = 1,
+                             default = <<"">>,
                               label = '$resource'}]}).
 
 -xml(legacy_auth_username,