Permalink
Browse files

Fixed ssl-related tests on R12B (requires ssl/examples from Erlang/OTP)

Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
  • Loading branch information...
1 parent ac87470 commit 0b6e3ffcdb617945fbfb74787b57b95b0198f8b2 @lemenkov lemenkov committed Aug 10, 2010
Showing with 17 additions and 16 deletions.
  1. +9 −8 src/mochiweb.erl
  2. +8 −8 src/mochiweb_multipart.erl
View
@@ -97,21 +97,22 @@ ensure_started(App) ->
-record(treq, {path, body= <<>>, xreply= <<>>}).
-ssl_cert_opts() ->
- EbinDir = filename:dirname(code:which(?MODULE)),
- CertDir = filename:join([EbinDir, "..", "support", "test-materials"]),
- CertFile = filename:join(CertDir, "test_ssl_cert.pem"),
- KeyFile = filename:join(CertDir, "test_ssl_key.pem"),
- [{certfile, CertFile}, {keyfile, KeyFile}].
+ssl_cert_opts(Role) ->
+ CertDir = filename:join([code:lib_dir(ssl), "examples", "certs", "etc", Role]),
+ CaCertFile = filename:join([CertDir, "cacerts.pem"]),
+ CertFile = filename:join(CertDir, "cert.pem"),
+ KeyFile = filename:join(CertDir, "key.pem"),
+ [{cacertfile, CaCertFile}, {certfile, CertFile}, {keyfile, KeyFile}].
with_server(Transport, ServerFun, ClientFun) ->
ServerOpts0 = [{ip, "127.0.0.1"}, {port, 0}, {loop, ServerFun}],
ServerOpts = case Transport of
plain ->
ServerOpts0;
ssl ->
- ServerOpts0 ++ [{ssl, true}, {ssl_opts, ssl_cert_opts()}]
+ ServerOpts0 ++ [{ssl, true}, {ssl_opts, ssl_cert_opts("server")}]
end,
+ io:format("SO: ~p~n",[ServerOpts]),
{ok, Server} = mochiweb_http:start(ServerOpts),
Port = mochiweb_socket_server:get(Server, port),
Res = (catch ClientFun(Transport, Port)),
@@ -222,7 +223,7 @@ client_request(Transport, Port, Method, TestReqs) ->
inet:setopts(Socket, L)
end;
ssl ->
- {ok, Socket} = ssl:connect("127.0.0.1", Port, [{ssl_imp, new} | Opts]),
+ {ok, Socket} = ssl:connect("127.0.0.1", Port, [{ssl_imp, new} | ssl_cert_opts("client") ++ Opts]),
fun (recv) ->
ssl:recv(Socket, 0);
({recv, Length}) ->
View
@@ -298,20 +298,20 @@ find_boundary(Prefix, Data) ->
-include_lib("eunit/include/eunit.hrl").
-ifdef(TEST).
-ssl_cert_opts() ->
- EbinDir = filename:dirname(code:which(?MODULE)),
- CertDir = filename:join([EbinDir, "..", "support", "test-materials"]),
- CertFile = filename:join(CertDir, "test_ssl_cert.pem"),
- KeyFile = filename:join(CertDir, "test_ssl_key.pem"),
- [{certfile, CertFile}, {keyfile, KeyFile}].
+ssl_cert_opts(Role) ->
+ CertDir = filename:join([code:lib_dir(ssl), "examples", "certs", "etc", Role]),
+ CaCertFile = filename:join([CertDir, "cacerts.pem"]),
+ CertFile = filename:join(CertDir, "cert.pem"),
+ KeyFile = filename:join(CertDir, "key.pem"),
+ [{cacertfile, CaCertFile}, {certfile, CertFile}, {keyfile, KeyFile}].
with_socket_server(Transport, ServerFun, ClientFun) ->
ServerOpts0 = [{ip, "127.0.0.1"}, {port, 0}, {loop, ServerFun}],
ServerOpts = case Transport of
plain ->
ServerOpts0;
ssl ->
- ServerOpts0 ++ [{ssl, true}, {ssl_opts, ssl_cert_opts()}]
+ ServerOpts0 ++ [{ssl, true}, {ssl_opts, ssl_cert_opts("server")}]
end,
{ok, Server} = mochiweb_socket_server:start(ServerOpts),
Port = mochiweb_socket_server:get(Server, port),
@@ -320,7 +320,7 @@ with_socket_server(Transport, ServerFun, ClientFun) ->
plain ->
gen_tcp:connect("127.0.0.1", Port, ClientOpts);
ssl ->
- ClientOpts1 = [{ssl_imp, new} | ClientOpts],
+ ClientOpts1 = [{ssl_imp, new} | ssl_cert_opts("client") ++ ClientOpts],
{ok, SslSocket} = ssl:connect("127.0.0.1", Port, ClientOpts1),
{ok, {ssl, SslSocket}}
end,

0 comments on commit 0b6e3ff

Please sign in to comment.