aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ssh/test/ssh_basic_SUITE.erl
diff options
context:
space:
mode:
authorHans Nilsson <[email protected]>2013-09-30 16:35:09 +0200
committerHans Nilsson <[email protected]>2013-10-28 16:09:20 +0100
commitf5495aa1560daf65c063a8d5b99a5ea17520ea92 (patch)
tree93a94f73c882ab25f9ed3c7fddd4f5237551bd9b /lib/ssh/test/ssh_basic_SUITE.erl
parentd54e4318a77c7a42a7b8952780b33987775c7608 (diff)
downloadotp-f5495aa1560daf65c063a8d5b99a5ea17520ea92.tar.gz
otp-f5495aa1560daf65c063a8d5b99a5ea17520ea92.tar.bz2
otp-f5495aa1560daf65c063a8d5b99a5ea17520ea92.zip
ssh: Add ssh:sockname/1 incl doc and tests
OTP-11345, sto575, tsk374
Diffstat (limited to 'lib/ssh/test/ssh_basic_SUITE.erl')
-rw-r--r--lib/ssh/test/ssh_basic_SUITE.erl55
1 files changed, 36 insertions, 19 deletions
diff --git a/lib/ssh/test/ssh_basic_SUITE.erl b/lib/ssh/test/ssh_basic_SUITE.erl
index e13610bc2a..e8f1d5213c 100644
--- a/lib/ssh/test/ssh_basic_SUITE.erl
+++ b/lib/ssh/test/ssh_basic_SUITE.erl
@@ -49,7 +49,9 @@ all() ->
close].
groups() ->
- [{dsa_key, [], [send, peername, exec, exec_compressed, shell, known_hosts, idle_time, rekey, openssh_zlib_basic_test]},
+ [{dsa_key, [], [send,
+ peername_sockname,
+ exec, exec_compressed, shell, known_hosts, idle_time, rekey, openssh_zlib_basic_test]},
{rsa_key, [], [send, exec, exec_compressed, shell, known_hosts, idle_time, rekey, openssh_zlib_basic_test]},
{dsa_pass_key, [], [pass_phrase]},
{rsa_pass_key, [], [pass_phrase]},
@@ -474,35 +476,50 @@ send(Config) when is_list(Config) ->
%%--------------------------------------------------------------------
-peername() ->
- [{doc, "Test ssh:peername/1"}].
-peername(Config) when is_list(Config) ->
+peername_sockname() ->
+ [{doc, "Test ssh:peername/1 and ssh:sockname/1"}].
+peername_sockname(Config) when is_list(Config) ->
process_flag(trap_exit, true),
SystemDir = filename:join(?config(priv_dir, Config), system),
UserDir = ?config(priv_dir, Config),
- {Pid, Host, Port} = ssh_test_lib:daemon([{system_dir, SystemDir},
+ {_Pid, Host, Port} = ssh_test_lib:daemon([{system_dir, SystemDir},
{user_dir, UserDir},
- {failfun, fun ssh_test_lib:failfun/2}]),
+ {subsystems, [{"peername_sockname",
+ {ssh_peername_sockname_server, []}}
+ ]}
+ ]),
ConnectionRef =
ssh_test_lib:connect(Host, Port, [{silently_accept_hosts, true},
{user_dir, UserDir},
{user_interaction, false}]),
- {ok,{IP,Port}} = ssh:peername(ConnectionRef),
- host_equal(Host,IP),
- ssh:stop_daemon(Pid).
-
+ {ok, ChannelId} = ssh_connection:session_channel(ConnectionRef, infinity),
+ success = ssh_connection:subsystem(ConnectionRef, ChannelId, "peername_sockname", infinity),
+ {ok,{HostPeerClient,PortPeerClient}} = ssh:peername(ConnectionRef),
+ {ok,{HostSockClient,PortSockClient}} = ssh:sockname(ConnectionRef),
+ receive
+ {ssh_cm, ConnectionRef, {data, ChannelId, _, Response}} ->
+ {PeerNameSrv,SockNameSrv} = binary_to_term(Response),
+ {ok,{HostPeerSrv,PortPeerSrv}} = PeerNameSrv,
+ {ok,{HostSockSrv,PortSockSrv}} = SockNameSrv,
+ host_equal(HostPeerSrv, HostSockClient),
+ PortPeerSrv = PortSockClient,
+ host_equal(HostSockSrv, HostPeerClient),
+ PortSockSrv = PortPeerClient,
+ host_equal(HostSockSrv, Host),
+ PortSockSrv = Port
+ after 10000 ->
+ throw(timeout)
+ end.
-host_equal(Name, IP) when is_list(Name), is_tuple(IP) ->
- Family = if size(IP)==4 -> inet;
- size(IP)==8 -> inet6
- end,
- {ok,#hostent{h_addr_list=IPs}} = inet:gethostbyname(Name,Family),
- lists:any(fun(X) -> X==IP end, IPs);
-host_equal(IP, Name) when is_list(Name), is_tuple(IP) ->
- host_equal(Name, IP);
-host_equal(X,Y) -> X==Y.
+host_equal(H1, H2) ->
+ not ordsets:is_disjoint(ips(H1), ips(H2)).
+ips(IP) when is_tuple(IP) -> ordsets:from_list([IP]);
+ips(Name) when is_list(Name) ->
+ {ok,#hostent{h_addr_list=IPs4}} = inet:gethostbyname(Name,inet),
+ {ok,#hostent{h_addr_list=IPs6}} = inet:gethostbyname(Name,inet6),
+ ordsets:from_list(IPs4++IPs6).
%%--------------------------------------------------------------------
close() ->