aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ssl/test/ssl_test_lib.erl
diff options
context:
space:
mode:
authorIngela Anderton Andin <[email protected]>2012-10-08 10:36:49 +0200
committerIngela Anderton Andin <[email protected]>2013-01-11 10:16:33 +0100
commit102cd877bc3ed83dc17bb17a691fa08d020fab34 (patch)
tree0f85860845104806c67572ab67017389c77ae05a /lib/ssl/test/ssl_test_lib.erl
parent12c4a0b0c8963c03806613bb73487fdc14733db9 (diff)
downloadotp-102cd877bc3ed83dc17bb17a691fa08d020fab34.tar.gz
otp-102cd877bc3ed83dc17bb17a691fa08d020fab34.tar.bz2
otp-102cd877bc3ed83dc17bb17a691fa08d020fab34.zip
ssl: CTify test cases
Diffstat (limited to 'lib/ssl/test/ssl_test_lib.erl')
-rw-r--r--lib/ssl/test/ssl_test_lib.erl127
1 files changed, 74 insertions, 53 deletions
diff --git a/lib/ssl/test/ssl_test_lib.erl b/lib/ssl/test/ssl_test_lib.erl
index 456da0cfd9..e6f71183c7 100644
--- a/lib/ssl/test/ssl_test_lib.erl
+++ b/lib/ssl/test/ssl_test_lib.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2008-2012. All Rights Reserved.
+%% Copyright Ericsson AB 2008-2013. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
@@ -20,8 +20,7 @@
%%
-module(ssl_test_lib).
--include("test_server.hrl").
--include("test_server_line.hrl").
+-include_lib("common_test/include/ct.hrl").
-include_lib("public_key/include/public_key.hrl").
%% Note: This directive should only be used in test suites.
@@ -29,12 +28,6 @@
-record(sslsocket, { fd = nil, pid = nil}).
-timetrap(Time) ->
- Mul = try
- test_server:timetrap_scale_factor()
- catch _:_ -> 1 end,
- test_server:timetrap(1000+Time*Mul).
-
%% For now always run locally
run_where(_) ->
ClientNode = node(),
@@ -66,7 +59,7 @@ run_server(Opts) ->
Options = proplists:get_value(options, Opts),
Pid = proplists:get_value(from, Opts),
Transport = proplists:get_value(transport, Opts, ssl),
- test_server:format("~p:listen(~p, ~p)~n", [Transport, Port, Options]),
+ ct:print("ssl:listen(~p, ~p)~n", [Port, Options]),
{ok, ListenSocket} = rpc:call(Node, Transport, listen, [Port, Options]),
Pid ! {listen, up},
send_selected_port(Pid, Port, ListenSocket),
@@ -84,13 +77,13 @@ do_run_server(ListenSocket, AcceptSocket, Opts) ->
Pid = proplists:get_value(from, Opts),
Transport = proplists:get_value(transport, Opts, ssl),
{Module, Function, Args} = proplists:get_value(mfa, Opts),
- test_server:format("Server: apply(~p,~p,~p)~n",
+ ct:print("Server: apply(~p,~p,~p)~n",
[Module, Function, [AcceptSocket | Args]]),
case rpc:call(Node, Module, Function, [AcceptSocket | Args]) of
no_result_msg ->
ok;
Msg ->
- test_server:format("Server Msg: ~p ~n", [Msg]),
+ ct:print("Server Msg: ~p ~n", [Msg]),
Pid ! {self(), Msg}
end,
receive
@@ -99,12 +92,10 @@ do_run_server(ListenSocket, AcceptSocket, Opts) ->
{listen, MFA} ->
run_server(ListenSocket, [MFA | proplists:delete(mfa, Opts)]);
close ->
- test_server:format("Server closing ~p ~n", [self()]),
- test_server:format("~p:close(~p) ~n", [Transport, AcceptSocket]),
- test_server:format("~p:close(~p) ~n", [Transport, ListenSocket]),
+ ct:print("Server closing ~p ~n", [self()]),
Result = rpc:call(Node, Transport, close, [AcceptSocket], 500),
Result1 = rpc:call(Node, Transport, close, [ListenSocket], 500),
- test_server:format("close result 1 ~p close result 2 ~p ~n", [Result, Result1]);
+ ct:print("Result ~p : ~p ~n", [Result, Result1]);
{ssl_closed, _} ->
ok
end.
@@ -124,7 +115,7 @@ connect(#sslsocket{} = ListenSocket, Opts) ->
end;
connect(ListenSocket, Opts) ->
Node = proplists:get_value(node, Opts),
- test_server:format("gen_tcp:accept(~p)~n", [ListenSocket]),
+ ct:format("gen_tcp:accept(~p)~n", [ListenSocket]),
{ok, AcceptSocket} = rpc:call(Node, gen_tcp, accept,
[ListenSocket]),
AcceptSocket.
@@ -132,10 +123,10 @@ connect(ListenSocket, Opts) ->
connect(_, _, 0, AcceptSocket, _) ->
AcceptSocket;
connect(ListenSocket, Node, N, _, Timeout) ->
- test_server:format("ssl:transport_accept(~p)~n", [ListenSocket]),
+ ct:print("ssl:transport_accept(~p)~n", [ListenSocket]),
{ok, AcceptSocket} = rpc:call(Node, ssl, transport_accept,
[ListenSocket]),
- test_server:format("ssl:ssl_accept(~p, ~p)~n", [AcceptSocket, Timeout]),
+ ct:print("ssl:ssl_accept(~p, ~p)~n", [AcceptSocket, Timeout]),
case rpc:call(Node, ssl, ssl_accept, [AcceptSocket, Timeout]) of
ok ->
@@ -170,27 +161,27 @@ run_client(Opts) ->
Pid = proplists:get_value(from, Opts),
Transport = proplists:get_value(transport, Opts, ssl),
Options = proplists:get_value(options, Opts),
- test_server:format("~p:connect(~p, ~p, ~p)~n", [Transport, Host, Port, Options]),
+ ct:print("ssl:connect(~p, ~p, ~p)~n", [Host, Port, Options]),
case rpc:call(Node, Transport, connect, [Host, Port, Options]) of
{ok, Socket} ->
Pid ! { connected, Socket },
- test_server:format("Client: connected~n", []),
+ ct:print("Client: connected~n", []),
%% In special cases we want to know the client port, it will
%% be indicated by sending {port, 0} in options list!
send_selected_port(Pid, proplists:get_value(port, Options), Socket),
{Module, Function, Args} = proplists:get_value(mfa, Opts),
- test_server:format("Client: apply(~p,~p,~p)~n",
+ ct:print("Client: apply(~p,~p,~p)~n",
[Module, Function, [Socket | Args]]),
case rpc:call(Node, Module, Function, [Socket | Args]) of
no_result_msg ->
ok;
Msg ->
- test_server:format("Client Msg: ~p ~n", [Msg]),
+ ct:print("Client Msg: ~p ~n", [Msg]),
Pid ! {self(), Msg}
end,
receive
close ->
- test_server:format("Client closing~n", []),
+ ct:print("Client closing~n", []),
rpc:call(Node, Transport, close, [Socket]);
{ssl_closed, Socket} ->
ok;
@@ -198,18 +189,18 @@ run_client(Opts) ->
ok
end;
{error, Reason} ->
- test_server:format("Client: connection failed: ~p ~n", [Reason]),
+ ct:print("Client: connection failed: ~p ~n", [Reason]),
Pid ! {self(), {error, Reason}}
end.
close(Pid) ->
- test_server:format("Close ~p ~n", [Pid]),
+ ct:print("Close ~p ~n", [Pid]),
Monitor = erlang:monitor(process, Pid),
Pid ! close,
receive
{'DOWN', Monitor, process, Pid, Reason} ->
erlang:demonitor(Monitor),
- test_server:format("Pid: ~p down due to:~p ~n", [Pid, Reason])
+ ct:print("Pid: ~p down due to:~p ~n", [Pid, Reason])
end.
check_result(Server, ServerMsg, Client, ClientMsg) ->
@@ -221,7 +212,7 @@ check_result(Server, ServerMsg, Client, ClientMsg) ->
Unexpected ->
Reason = {{expected, {Client, ClientMsg}},
{got, Unexpected}},
- test_server:fail(Reason)
+ ct:fail(Reason)
end;
{Client, ClientMsg} ->
receive
@@ -230,7 +221,7 @@ check_result(Server, ServerMsg, Client, ClientMsg) ->
Unexpected ->
Reason = {{expected, {Server, ClientMsg}},
{got, Unexpected}},
- test_server:fail(Reason)
+ ct:fail(Reason)
end;
{Port, {data,Debug}} when is_port(Port) ->
io:format("openssl ~s~n",[Debug]),
@@ -239,7 +230,7 @@ check_result(Server, ServerMsg, Client, ClientMsg) ->
Unexpected ->
Reason = {{expected, {Client, ClientMsg}},
{expected, {Server, ServerMsg}}, {got, Unexpected}},
- test_server:fail(Reason)
+ ct:fail(Reason)
end.
check_result(Pid, Msg) ->
@@ -252,7 +243,7 @@ check_result(Pid, Msg) ->
Unexpected ->
Reason = {{expected, {Pid, Msg}},
{got, Unexpected}},
- test_server:fail(Reason)
+ ct:fail(Reason)
end.
wait_for_result(Server, ServerMsg, Client, ClientMsg) ->
@@ -419,33 +410,33 @@ run_upgrade_server(Opts) ->
SslOptions = proplists:get_value(ssl_options, Opts),
Pid = proplists:get_value(from, Opts),
- test_server:format("gen_tcp:listen(~p, ~p)~n", [Port, TcpOptions]),
+ ct:print("gen_tcp:listen(~p, ~p)~n", [Port, TcpOptions]),
{ok, ListenSocket} = rpc:call(Node, gen_tcp, listen, [Port, TcpOptions]),
Pid ! {listen, up},
send_selected_port(Pid, Port, ListenSocket),
- test_server:format("gen_tcp:accept(~p)~n", [ListenSocket]),
+ ct:print("gen_tcp:accept(~p)~n", [ListenSocket]),
{ok, AcceptSocket} = rpc:call(Node, gen_tcp, accept, [ListenSocket]),
try
{ok, SslAcceptSocket} = case TimeOut of
infinity ->
- test_server:format("ssl:ssl_accept(~p, ~p)~n",
+ ct:print("ssl:ssl_accept(~p, ~p)~n",
[AcceptSocket, SslOptions]),
rpc:call(Node, ssl, ssl_accept,
[AcceptSocket, SslOptions]);
_ ->
- test_server:format("ssl:ssl_accept(~p, ~p, ~p)~n",
+ ct:print("ssl:ssl_accept(~p, ~p, ~p)~n",
[AcceptSocket, SslOptions, TimeOut]),
rpc:call(Node, ssl, ssl_accept,
[AcceptSocket, SslOptions, TimeOut])
end,
{Module, Function, Args} = proplists:get_value(mfa, Opts),
Msg = rpc:call(Node, Module, Function, [SslAcceptSocket | Args]),
- test_server:format("Upgrade Server Msg: ~p ~n", [Msg]),
+ ct:print("Upgrade Server Msg: ~p ~n", [Msg]),
Pid ! {self(), Msg},
receive
close ->
- test_server:format("Upgrade Server closing~n", []),
+ ct:print("Upgrade Server closing~n", []),
rpc:call(Node, ssl, close, [SslAcceptSocket])
end
catch error:{badmatch, Error} ->
@@ -463,24 +454,24 @@ run_upgrade_client(Opts) ->
TcpOptions = proplists:get_value(tcp_options, Opts),
SslOptions = proplists:get_value(ssl_options, Opts),
- test_server:format("gen_tcp:connect(~p, ~p, ~p)~n",
+ ct:print("gen_tcp:connect(~p, ~p, ~p)~n",
[Host, Port, TcpOptions]),
{ok, Socket} = rpc:call(Node, gen_tcp, connect, [Host, Port, TcpOptions]),
send_selected_port(Pid, Port, Socket),
- test_server:format("ssl:connect(~p, ~p)~n", [Socket, SslOptions]),
+ ct:print("ssl:connect(~p, ~p)~n", [Socket, SslOptions]),
{ok, SslSocket} = rpc:call(Node, ssl, connect, [Socket, SslOptions]),
{Module, Function, Args} = proplists:get_value(mfa, Opts),
- test_server:format("apply(~p, ~p, ~p)~n",
+ ct:print("apply(~p, ~p, ~p)~n",
[Module, Function, [SslSocket | Args]]),
Msg = rpc:call(Node, Module, Function, [SslSocket | Args]),
- test_server:format("Upgrade Client Msg: ~p ~n", [Msg]),
+ ct:print("Upgrade Client Msg: ~p ~n", [Msg]),
Pid ! {self(), Msg},
receive
close ->
- test_server:format("Upgrade Client closing~n", []),
+ ct:print("Upgrade Client closing~n", []),
rpc:call(Node, ssl, close, [SslSocket])
end.
@@ -499,20 +490,20 @@ run_upgrade_server_error(Opts) ->
SslOptions = proplists:get_value(ssl_options, Opts),
Pid = proplists:get_value(from, Opts),
- test_server:format("gen_tcp:listen(~p, ~p)~n", [Port, TcpOptions]),
+ ct:print("gen_tcp:listen(~p, ~p)~n", [Port, TcpOptions]),
{ok, ListenSocket} = rpc:call(Node, gen_tcp, listen, [Port, TcpOptions]),
Pid ! {listen, up},
send_selected_port(Pid, Port, ListenSocket),
- test_server:format("gen_tcp:accept(~p)~n", [ListenSocket]),
+ ct:print("gen_tcp:accept(~p)~n", [ListenSocket]),
{ok, AcceptSocket} = rpc:call(Node, gen_tcp, accept, [ListenSocket]),
Error = case TimeOut of
infinity ->
- test_server:format("ssl:ssl_accept(~p, ~p)~n",
+ ct:print("ssl:ssl_accept(~p, ~p)~n",
[AcceptSocket, SslOptions]),
rpc:call(Node, ssl, ssl_accept,
[AcceptSocket, SslOptions]);
_ ->
- test_server:format("ssl:ssl_accept(~p, ~p, ~p)~n",
+ ct:print("ssl:ssl_accept(~p, ~p, ~p)~n",
[AcceptSocket, SslOptions, TimeOut]),
rpc:call(Node, ssl, ssl_accept,
[AcceptSocket, SslOptions, TimeOut])
@@ -532,26 +523,26 @@ run_server_error(Opts) ->
Options = proplists:get_value(options, Opts),
Pid = proplists:get_value(from, Opts),
Transport = proplists:get_value(transport, Opts, ssl),
- test_server:format("~p:listen(~p, ~p)~n", [Transport, Port, Options]),
+ ct:print("ssl:listen(~p, ~p)~n", [Port, Options]),
case rpc:call(Node, Transport, listen, [Port, Options]) of
{ok, #sslsocket{} = ListenSocket} ->
%% To make sure error_client will
%% get {error, closed} and not {error, connection_refused}
Pid ! {listen, up},
send_selected_port(Pid, Port, ListenSocket),
- test_server:format("~p:transport_accept(~p)~n", [Transport, ListenSocket]),
+ ct:print("ssl:transport_accept(~p)~n", [ListenSocket]),
case rpc:call(Node, Transport, transport_accept, [ListenSocket]) of
{error, _} = Error ->
Pid ! {self(), Error};
{ok, AcceptSocket} ->
- test_server:format("ssl:ssl_accept(~p)~n", [AcceptSocket]),
+ ct:print("ssl:ssl_accept(~p)~n", [AcceptSocket]),
Error = rpc:call(Node, ssl, ssl_accept, [AcceptSocket]),
Pid ! {self(), Error}
end;
{ok, ListenSocket} ->
Pid ! {listen, up},
send_selected_port(Pid, Port, ListenSocket),
- test_server:format("~p:accept(~p)~n", [Transport, ListenSocket]),
+ ct:format("~p:accept(~p)~n", [Transport, ListenSocket]),
case rpc:call(Node, Transport, accept, [ListenSocket]) of
{error, _} = Error ->
Pid ! {self(), Error}
@@ -573,7 +564,7 @@ run_client_error(Opts) ->
Pid = proplists:get_value(from, Opts),
Transport = proplists:get_value(transport, Opts, ssl),
Options = proplists:get_value(options, Opts),
- test_server:format("~p:connect(~p, ~p, ~p)~n", [Transport, Host, Port, Options]),
+ ct:print("ssl:connect(~p, ~p, ~p)~n", [Host, Port, Options]),
Error = rpc:call(Node, Transport, connect, [Host, Port, Options]),
Pid ! {self(), Error}.
@@ -601,7 +592,7 @@ trigger_renegotiate(Socket, [ErlData, N]) ->
trigger_renegotiate(Socket, ErlData, N, Id).
trigger_renegotiate(Socket, _, 0, Id) ->
- test_server:sleep(1000),
+ ct:sleep(1000),
case ssl:session_info(Socket) of
[{session_id, Id} | _ ] ->
fail_session_not_renegotiated;
@@ -694,7 +685,7 @@ der_to_pem(File, Entries) ->
cipher_result(Socket, Result) ->
Result = ssl:connection_info(Socket),
- test_server:format("Successfull connect: ~p~n", [Result]),
+ ct:print("Successfull connect: ~p~n", [Result]),
%% Importante to send two packets here
%% to properly test "cipher state" handling
ssl:send(Socket, "Hello\n"),
@@ -775,3 +766,33 @@ sufficient_crypto_support('tlsv1.2') ->
end;
sufficient_crypto_support(_) ->
true.
+
+send_recv_result_active(Socket) ->
+ ssl:send(Socket, "Hello world"),
+ receive
+ {ssl, Socket, "H"} ->
+ receive
+ {ssl, Socket, "ello world"} ->
+ ok
+ end;
+ {ssl, Socket, "Hello world"} ->
+ ok
+ end.
+
+send_recv_result(Socket) ->
+ ssl:send(Socket, "Hello world"),
+ {ok,"Hello world"} = ssl:recv(Socket, 11),
+ ok.
+
+send_recv_result_active_once(Socket) ->
+ ssl:send(Socket, "Hello world"),
+ receive
+ {ssl, Socket, "H"} ->
+ ssl:setopts(Socket, [{active, once}]),
+ receive
+ {ssl, Socket, "ello world"} ->
+ ok
+ end;
+ {ssl, Socket, "Hello world"} ->
+ ok
+ end.