aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorjuhlig <[email protected]>2019-05-14 11:27:04 +0200
committerLoïc Hoguin <[email protected]>2019-05-18 21:50:44 +0200
commitb1e6406e4f0871c656f92fdd0755c8ef82be2818 (patch)
treeb628d0e65859384d8cbc7315d96cfdbb22f8b742 /test
parentc7dcc9cb1362e397d8d3d184b0643f2ca50c032e (diff)
downloadranch-b1e6406e4f0871c656f92fdd0755c8ef82be2818.tar.gz
ranch-b1e6406e4f0871c656f92fdd0755c8ef82be2818.tar.bz2
ranch-b1e6406e4f0871c656f92fdd0755c8ef82be2818.zip
Add support for UNIX domain sockets
It was working already but the types were wrong and some small details needed to be corrected.
Diffstat (limited to 'test')
-rw-r--r--test/acceptor_SUITE.erl70
1 files changed, 70 insertions, 0 deletions
diff --git a/test/acceptor_SUITE.erl b/test/acceptor_SUITE.erl
index 41939b0..ad74f0d 100644
--- a/test/acceptor_SUITE.erl
+++ b/test/acceptor_SUITE.erl
@@ -30,6 +30,7 @@ groups() ->
[{tcp, [
tcp_active_echo,
tcp_echo,
+ tcp_local_echo,
tcp_graceful,
tcp_inherit_options,
tcp_max_connections,
@@ -49,6 +50,7 @@ groups() ->
ssl_accept_error,
ssl_active_echo,
ssl_echo,
+ ssl_local_echo,
ssl_graceful,
ssl_sni_echo,
ssl_sni_fail,
@@ -481,6 +483,36 @@ ssl_echo(_) ->
{'EXIT', _} = begin catch ranch:get_port(Name) end,
ok.
+ssl_local_echo(_) ->
+ case do_os_supports_local_sockets() of
+ true ->
+ do_ssl_local_echo();
+ false ->
+ {skip, "No local socket support."}
+ end.
+
+do_ssl_local_echo() ->
+ doc("Ensure that listening on a local socket works with SSL transport."),
+ SockFile = do_tempname(),
+ try
+ Name = name(),
+ Opts = ct_helper:get_certs_from_ets(),
+ {ok, _} = ranch:start_listener(Name,
+ ranch_ssl, #{socket_opts => [{ip, {local, SockFile}}|Opts]},
+ echo_protocol, []),
+ undefined = ranch:get_port(Name),
+ {ok, Socket} = ssl:connect({local, SockFile}, 0, [binary, {active, false}, {packet, raw}]),
+ ok = ssl:send(Socket, <<"SSL Ranch is working!">>),
+ {ok, <<"SSL Ranch is working!">>} = ssl:recv(Socket, 21, 1000),
+ ok = ranch:stop_listener(Name),
+ {error, closed} = ssl:recv(Socket, 0, 1000),
+ %% Make sure the listener stopped.
+ {'EXIT', _} = begin catch ranch:get_port(Name) end,
+ ok
+ after
+ file:delete(SockFile)
+ end.
+
ssl_sni_echo(_) ->
case application:get_key(ssl, vsn) of
{ok, Vsn} when Vsn >= "7.0" ->
@@ -744,6 +776,35 @@ tcp_echo(_) ->
{'EXIT', _} = begin catch ranch:get_port(Name) end,
ok.
+tcp_local_echo(_) ->
+ case do_os_supports_local_sockets() of
+ true ->
+ do_tcp_local_echo();
+ false ->
+ {skip, "No local socket support."}
+ end.
+
+do_tcp_local_echo() ->
+ doc("Ensure that listening on a local socket works with TCP transport."),
+ SockFile = do_tempname(),
+ try
+ Name = name(),
+ {ok, _} = ranch:start_listener(Name,
+ ranch_tcp, #{socket_opts => [{ip, {local, SockFile}}]},
+ echo_protocol, []),
+ undefined = ranch:get_port(Name),
+ {ok, Socket} = gen_tcp:connect({local, SockFile}, 0, [binary, {active, false}, {packet, raw}]),
+ ok = gen_tcp:send(Socket, <<"TCP Ranch is working!">>),
+ {ok, <<"TCP Ranch is working!">>} = gen_tcp:recv(Socket, 21, 1000),
+ ok = ranch:stop_listener(Name),
+ {error, closed} = gen_tcp:recv(Socket, 0, 1000),
+ %% Make sure the listener stopped.
+ {'EXIT', _} = begin catch ranch:get_port(Name) end,
+ ok
+ after
+ file:delete(SockFile)
+ end.
+
tcp_graceful(_) ->
doc("Ensure suspending and resuming of listeners does not kill active connections."),
Name = name(),
@@ -1373,3 +1434,12 @@ do_os_supports_reuseport() ->
{{unix, linux}, {3, Minor, _}} when Minor >= 9 -> true;
_ -> false
end.
+
+do_os_supports_local_sockets() ->
+ case os:type() of
+ {unix, _} -> true;
+ _ -> false
+ end.
+
+do_tempname() ->
+ lists:droplast(os:cmd("mktemp -u")).