Add mod_register checks

This commit is contained in:
Evgeniy Khramtsov 2013-06-14 18:47:50 +10:00 committed by Alexey Shchepin
parent 8a5ec41279
commit 5872ce5cc3
4 changed files with 1262 additions and 12 deletions

View File

@ -65,6 +65,8 @@ init_per_testcase(TestCase, OrigConfig) ->
Config;
test_auth ->
connect(Config);
register ->
connect(Config);
auth_md5 ->
connect(Config);
auth_plain ->
@ -83,11 +85,12 @@ end_per_testcase(_TestCase, _Config) ->
groups() ->
[].
%%all() -> [start_ejabberd, vcard].
%%all() -> [start_ejabberd, register].
all() ->
[start_ejabberd,
test_connect,
register,
auth_plain,
auth_md5,
test_auth,
@ -110,7 +113,6 @@ all() ->
start_ejabberd(Config) ->
ok = application:start(ejabberd),
ok = re_register(Config),
Config.
stop_ejabberd(Config) ->
@ -140,7 +142,13 @@ connect(Config) ->
(_) ->
[]
end, Fs),
[{mechs, Mechs}|Config1].
Feats = lists:flatmap(
fun(#feature_register{}) ->
[{register, true}];
(_) ->
[]
end, Fs),
[{mechs, Mechs}|Feats ++ Config1].
disconnect(Config) ->
Socket = ?config(socket, Config),
@ -149,6 +157,31 @@ disconnect(Config) ->
ejabberd_socket:close(Socket),
Config.
register(Config) ->
case ?config(register, Config) of
false ->
{skipped, 'registration_not_available'};
true ->
try_register(Config)
end.
try_register(Config) ->
I1 = send(Config,
#iq{type = get, to = server_jid(Config),
sub_els = [#register{}]}),
#iq{type = result, id = I1,
sub_els = [#register{username = none,
password = none}]} = recv(),
I2 = send(Config,
#iq{type = set,
sub_els = [#register{username = ?config(user, Config),
password = ?config(password, Config)}]}),
%% BUG: we should receive empty sub_els
%% TODO: fix in ejabberd
%% #iq{type = result, id = I2, sub_els = []} = recv(),
#iq{type = result, id = I2, sub_els = [#register{}]} = recv(),
disconnect(Config).
test_auth(Config) ->
disconnect(auth(Config)).
@ -199,6 +232,9 @@ roster_get(Config) ->
presence_broadcast(Config) ->
send(Config, #presence{}),
JID = my_jid(Config),
%% We receive the welcome message first
#message{type = normal} = recv(),
%% Then we receive back our presence
#presence{from = JID, to = JID} = recv(),
disconnect(Config).

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,7 @@
%% Created automatically by XML generator (xml_gen.erl)
%% Source: xmpp_codec.spec
%% Date: Fri, 14 Jun 2013 08:43:04 GMT
-record(last, {seconds, text}).
-record(version,
@ -92,7 +96,12 @@
-record(caps, {hash, node, ver}).
-record(register_feature, {}).
-record(feature_register, {}).
-record(register,
{registered = false, instructions, username, nick,
password, name, first, last, email, address, city,
state, zip, phone, url, date, misc, text, key}).
-record(session, {}).
@ -176,3 +185,5 @@
{subscriptions, affiliations, publish, subscribe}).
-record(delay, {stamp, from}).
-record(legacy_delay, {stamp, from}).

View File

@ -778,10 +778,151 @@
enc = {base64, encode, []},
dec = {base64, decode, []}}]}}.
{register_feature,
{feature_register,
#elem{name = <<"register">>,
xmlns = <<"http://jabber.org/features/iq-register">>,
result = {register_feature}}}.
result = {feature_register}}}.
{register_registered,
#elem{name = <<"registered">>,
xmlns = <<"jabber:iq:register">>,
result = true}}.
{register_instructions,
#elem{name = <<"instructions">>,
xmlns = <<"jabber:iq:register">>,
result = '$cdata'}}.
{register_username,
#elem{name = <<"username">>,
xmlns = <<"jabber:iq:register">>,
cdata = #cdata{default = none},
result = '$cdata'}}.
{register_nick,
#elem{name = <<"nick">>,
xmlns = <<"jabber:iq:register">>,
cdata = #cdata{default = none},
result = '$cdata'}}.
{register_password,
#elem{name = <<"password">>,
xmlns = <<"jabber:iq:register">>,
cdata = #cdata{default = none},
result = '$cdata'}}.
{register_name,
#elem{name = <<"name">>,
xmlns = <<"jabber:iq:register">>,
cdata = #cdata{default = none},
result = '$cdata'}}.
{register_first,
#elem{name = <<"first">>,
xmlns = <<"jabber:iq:register">>,
cdata = #cdata{default = none},
result = '$cdata'}}.
{register_last,
#elem{name = <<"last">>,
xmlns = <<"jabber:iq:register">>,
cdata = #cdata{default = none},
result = '$cdata'}}.
{register_email,
#elem{name = <<"email">>,
xmlns = <<"jabber:iq:register">>,
cdata = #cdata{default = none},
result = '$cdata'}}.
{register_address,
#elem{name = <<"address">>,
xmlns = <<"jabber:iq:register">>,
cdata = #cdata{default = none},
result = '$cdata'}}.
{register_city,
#elem{name = <<"city">>,
xmlns = <<"jabber:iq:register">>,
cdata = #cdata{default = none},
result = '$cdata'}}.
{register_state,
#elem{name = <<"state">>,
xmlns = <<"jabber:iq:register">>,
cdata = #cdata{default = none},
result = '$cdata'}}.
{register_zip,
#elem{name = <<"zip">>,
xmlns = <<"jabber:iq:register">>,
cdata = #cdata{default = none},
result = '$cdata'}}.
{register_phone,
#elem{name = <<"phone">>,
xmlns = <<"jabber:iq:register">>,
cdata = #cdata{default = none},
result = '$cdata'}}.
{register_url,
#elem{name = <<"url">>,
xmlns = <<"jabber:iq:register">>,
cdata = #cdata{default = none},
result = '$cdata'}}.
{register_date,
#elem{name = <<"date">>,
xmlns = <<"jabber:iq:register">>,
cdata = #cdata{default = none},
result = '$cdata'}}.
{register_misc,
#elem{name = <<"misc">>,
xmlns = <<"jabber:iq:register">>,
cdata = #cdata{default = none},
result = '$cdata'}}.
{register_text,
#elem{name = <<"text">>,
xmlns = <<"jabber:iq:register">>,
cdata = #cdata{default = none},
result = '$cdata'}}.
{register_key,
#elem{name = <<"key">>,
xmlns = <<"jabber:iq:register">>,
cdata = #cdata{default = none},
result = '$cdata'}}.
{register,
#elem{name = <<"query">>,
xmlns = <<"jabber:iq:register">>,
result = {register, '$registered', '$instructions',
'$username', '$nick', '$password', '$name',
'$first', '$last', '$email', '$address',
'$city', '$state', '$zip', '$phone', '$url',
'$date', '$misc', '$text', '$key'},
refs = [#ref{name = register_registered, min = 0, max = 1,
default = false, label = '$registered'},
#ref{name = register_instructions, min = 0, max = 1,
label = '$instructions'},
#ref{name = register_username, min = 0, max = 1,
label = '$username'},
#ref{name = register_nick, min = 0, max = 1,
label = '$nick'},
#ref{name = register_password, min = 0, max = 1,
label = '$password'},
#ref{name = register_name, min = 0, max = 1,
label = '$name'},
#ref{name = register_first, min = 0, max = 1,
label = '$first'},
#ref{name = register_last, min = 0, max = 1,
label = '$last'},
#ref{name = register_email, min = 0, max = 1,
label = '$email'},
#ref{name = register_address, min = 0, max = 1,
label = '$address'},
#ref{name = register_city, min = 0, max = 1,
label = '$city'},
#ref{name = register_state, min = 0, max = 1,
label = '$state'},
#ref{name = register_zip, min = 0, max = 1,
label = '$zip'},
#ref{name = register_phone, min = 0, max = 1,
label = '$phone'},
#ref{name = register_url, min = 0, max = 1,
label = '$url'},
#ref{name = register_date, min = 0, max = 1,
label = '$date'},
#ref{name = register_misc, min = 0, max = 1,
label = '$misc'},
#ref{name = register_text, min = 0, max = 1,
label = '$text'},
#ref{name = register_key, min = 0, max = 1,
label = '$key'}]}}.
{session,
#elem{name = <<"session">>,
@ -1506,6 +1647,16 @@
dec = {dec_jid, []},
enc = {enc_jid, []}}]}}.
{legacy_delay,
#elem{name = <<"x">>,
xmlns = <<"jabber:x:delay">>,
result = {legacy_delay, '$stamp', '$from'},
attrs = [#attr{name = <<"stamp">>,
required = true},
#attr{name = <<"from">>,
dec = {dec_jid, []},
enc = {enc_jid, []}}]}}.
dec_tzo(Val) ->
[H1, M1] = str:tokens(Val, <<":">>),
H = erlang:binary_to_integer(H1),