Add STARTTLS test case

This commit is contained in:
Evgeniy Khramtsov 2013-06-15 00:16:32 +10:00 committed by Alexey Shchepin
parent 5872ce5cc3
commit 167dd59941
3 changed files with 101 additions and 20 deletions

View File

@ -36,6 +36,7 @@ init_per_suite(Config) ->
LogPath = filename:join([PrivDir, "ejabberd.log"]),
SASLPath = filename:join([PrivDir, "sasl.log"]),
MnesiaDir = filename:join([PrivDir, "mnesia"]),
CertFile = filename:join([DataDir, "cert.pem"]),
application:set_env(ejabberd, config, ConfigPath),
application:set_env(ejabberd, log_path, LogPath),
application:set_env(sasl, sasl_error_logger, {file, SASLPath}),
@ -43,7 +44,8 @@ init_per_suite(Config) ->
[{server, <<"localhost">>},
{port, 5222},
{user, <<"test_suite">>},
{password, <<"pass">>}
{password, <<"pass">>},
{certfile, CertFile}
|Config].
end_per_suite(_Config) ->
@ -65,7 +67,9 @@ init_per_testcase(TestCase, OrigConfig) ->
Config;
test_auth ->
connect(Config);
register ->
test_starttls ->
connect(Config);
test_register ->
connect(Config);
auth_md5 ->
connect(Config);
@ -85,12 +89,13 @@ end_per_testcase(_TestCase, _Config) ->
groups() ->
[].
%%all() -> [start_ejabberd, register].
%%all() -> [start_ejabberd, test_starttls].
all() ->
[start_ejabberd,
test_connect,
register,
test_starttls,
test_register,
auth_plain,
auth_md5,
test_auth,
@ -129,9 +134,11 @@ connect(Config) ->
binary_to_list(?config(server, Config)),
?config(port, Config),
[binary, {packet, 0}, {active, false}]),
Config1 = [{socket, Sock}|Config],
ok = send_text(Config1, io_lib:format(?STREAM_HEADER,
[?config(server, Config1)])),
init_stream([{socket, Sock}|Config]).
init_stream(Config) ->
ok = send_text(Config, io_lib:format(?STREAM_HEADER,
[?config(server, Config)])),
{xmlstreamstart, <<"stream:stream">>, Attrs} = recv(),
<<"jabber:client">> = xml:get_attr_s(<<"xmlns">>, Attrs),
<<"1.0">> = xml:get_attr_s(<<"version">>, Attrs),
@ -142,13 +149,15 @@ connect(Config) ->
(_) ->
[]
end, Fs),
Feats = lists:flatmap(
fun(#feature_register{}) ->
[{register, true}];
(_) ->
[]
end, Fs),
[{mechs, Mechs}|Feats ++ Config1].
Feats = lists:foldl(
fun(#feature_register{}, Acc) ->
[{register, true}|Acc];
(#starttls{}, Acc) ->
[{starttls, true}|Acc];
(_, Acc) ->
Acc
end, [], Fs),
[{mechs, Mechs}|Feats ++ Config].
disconnect(Config) ->
Socket = ?config(socket, Config),
@ -157,15 +166,33 @@ disconnect(Config) ->
ejabberd_socket:close(Socket),
Config.
register(Config) ->
case ?config(register, Config) of
false ->
{skipped, 'registration_not_available'};
test_starttls(Config) ->
case ?config(starttls, Config) of
true ->
try_register(Config)
starttls(Config);
_ ->
{skipped, 'starttls_not_available'}
end.
try_register(Config) ->
starttls(Config) ->
_ = send(Config, #starttls{}),
#starttls_proceed{} = recv(),
TLSSocket = ejabberd_socket:starttls(
?config(socket, Config),
[{certfile, ?config(certfile, Config)},
connect]),
NewConfig = [{socket, TLSSocket}|lists:keydelete(socket, 1, Config)],
disconnect(init_stream(NewConfig)).
test_register(Config) ->
case ?config(register, Config) of
true ->
register(Config);
_ ->
{skipped, 'registration_not_available'}
end.
register(Config) ->
I1 = send(Config,
#iq{type = get, to = server_jid(Config),
sub_els = [#register{}]}),

View File

@ -0,0 +1,51 @@
-----BEGIN CERTIFICATE-----
MIIDETCCAcmgAwIBAgIEUbsa1zANBgkqhkiG9w0BAQsFADAAMCIYDzIwMTMwNjE0
MTMzMDAwWhgPMjAyMzA2MTIxMzMwMDhaMAAwggFSMA0GCSqGSIb3DQEBAQUAA4IB
PwAwggE6AoIBMQCXdtt12OFu2j8tlF4x2Da/kbxyMxFnovJXHNzpx7CE/cGthAR5
w7Cl92pECog2/d6ryIcjqzzCyCeOVQxIaE3Qz8z6+5UjKh3V/j6CKxcK5g1ER7Qe
UgpE00ahHzvOpVANtrkYPGC0SFuTFL+PaylH4HW1xBSc1HD5/w7S1k1pDTz9x8ZC
Z7JOb6NoYsz+rnmWYY2HOG6pyAyQB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X9kjLVFiRzysYbw8RBC1g1G9ulYfbW
5b4uDTz3JTDmuCi00v+1khGoktySlG80TzjzGKayLNPC6jTZc9XleQKBmA0STUrJ
0wf5+qZMxjsPpwfHZhmde+cACrjyBlFpjJELNpSzmnPoTRpzWlWZnN/AAsWyMUQ3
AyCy2J+iOSeq5wfrITgbWjoFgF+yp0MiTlxgvjpmbg7RBlOvvM0t2ZDwUMhKvf00
9n6z/f1s1MSMgp6BY7HoHUv++FSYllCv06Qz7q9zFajN29wP046qZm9xPkegW7cy
KKylAoGYTg94GOWlUTz7Pe9PDrDSFVEAi0LcDmul0ntorvEFDvU2pCRK14gyvl9O
IJKVyYcDAqA3uvT+zMAniuf8KXNUCcYeEpfzpT+e2eznhczO8hI14M5U0X0LA8P2
vn0Y+yUWb9Ppu/dcjvaUA+qR/UTHqjAlAr3hFTKRxXFoGwwzTXCXvZGKOnzJRTpj
LpjI1RG7Weeoyx/8qDs=
-----END RSA PRIVATE KEY-----

View File

@ -1,10 +1,13 @@
{loglevel, 4}.
{hosts, ["localhost"]}.
{define_macro, 'CERTFILE', "../../test/ejabberd_SUITE_data/cert.pem"}.
{listen,
[
{5222, ejabberd_c2s, [
{access, c2s},
{shaper, c2s_shaper},
starttls,
{certfile, 'CERTFILE'},
{max_stanza_size, 65536}
]},
{5269, ejabberd_s2s_in, [