aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ssh/test/ssh_sftp_SUITE.erl
diff options
context:
space:
mode:
authorHans Nilsson <[email protected]>2016-06-01 11:47:52 +0200
committerHans Nilsson <[email protected]>2016-06-01 11:47:52 +0200
commit317079a89bdf69888e398cb7e5703bfda7bd2c74 (patch)
tree82e0a323967b1506eb21cc0ec652476e4c3933ac /lib/ssh/test/ssh_sftp_SUITE.erl
parentb2cefac14a6b26c78f584592801413611ff6f31c (diff)
parent84051a76ee4c07f7453ba2bf24fe32c8cf8c7b48 (diff)
downloadotp-317079a89bdf69888e398cb7e5703bfda7bd2c74.tar.gz
otp-317079a89bdf69888e398cb7e5703bfda7bd2c74.tar.bz2
otp-317079a89bdf69888e398cb7e5703bfda7bd2c74.zip
Merge branch 'hans/ssh/use_open_socket_client/OTP-12860'
Diffstat (limited to 'lib/ssh/test/ssh_sftp_SUITE.erl')
-rw-r--r--lib/ssh/test/ssh_sftp_SUITE.erl55
1 files changed, 54 insertions, 1 deletions
diff --git a/lib/ssh/test/ssh_sftp_SUITE.erl b/lib/ssh/test/ssh_sftp_SUITE.erl
index 26fe0935e1..46db85c1be 100644
--- a/lib/ssh/test/ssh_sftp_SUITE.erl
+++ b/lib/ssh/test/ssh_sftp_SUITE.erl
@@ -86,7 +86,8 @@ groups() ->
write_file, write_file_iolist, write_big_file, sftp_read_big_file,
rename_file, mk_rm_dir, remove_file, links,
retrieve_attributes, set_attributes, async_read,
- async_write, position, pos_read, pos_write
+ async_write, position, pos_read, pos_write,
+ start_channel_sock
]}
].
@@ -625,6 +626,58 @@ pos_write(Config) when is_list(Config) ->
{ok, NewData1} = ssh_sftp:read_file(Sftp, FileName).
%%--------------------------------------------------------------------
+start_channel_sock(Config) ->
+ LoginOpts =
+ case proplists:get_value(group,Config) of
+ erlang_server ->
+ [{user, proplists:get_value(user, Config)},
+ {password, proplists:get_value(passwd, Config)}];
+ openssh_server ->
+ [] % Use public key
+ end,
+
+ Opts = [{user_interaction, false},
+ {silently_accept_hosts, true}
+ | LoginOpts],
+
+ {Host,Port} = proplists:get_value(peer, Config),
+
+ %% Get a tcp socket
+ {ok, Sock} = gen_tcp:connect(Host, Port, [{active,false}]),
+
+ %% and open one channel on one new Connection
+ {ok, ChPid1, Conn} = ssh_sftp:start_channel(Sock, Opts),
+
+ %% Test that the channel is usable
+ FileName = proplists:get_value(filename, Config),
+ ok = open_close_file(ChPid1, FileName, [read]),
+ ok = open_close_file(ChPid1, FileName, [write]),
+
+ %% Try to open a second channel on the Connection
+ {ok, ChPid2} = ssh_sftp:start_channel(Conn, Opts),
+ ok = open_close_file(ChPid1, FileName, [read]),
+ ok = open_close_file(ChPid2, FileName, [read]),
+
+ %% Test that the second channel still works after closing the first one
+ ok = ssh_sftp:stop_channel(ChPid1),
+ ok = open_close_file(ChPid2, FileName, [write]),
+
+ %% Test the Connection survives that all channels are closed
+ ok = ssh_sftp:stop_channel(ChPid2),
+ {ok, ChPid3} = ssh_sftp:start_channel(Conn, Opts),
+ ok = open_close_file(ChPid3, FileName, [write]),
+
+ %% Test that a closed channel really is closed
+ {error, closed} = ssh_sftp:open(ChPid2, FileName, [write]),
+ ok = ssh_sftp:stop_channel(ChPid3),
+
+ %% Test that the socket is closed when the Connection closes
+ ok = ssh:close(Conn),
+ {error,einval} = inet:getopts(Sock, [active]),
+
+ ok.
+
+%%--------------------------------------------------------------------
sftp_nonexistent_subsystem() ->
[{doc, "Try to execute sftp subsystem on a server that does not support it"}].
sftp_nonexistent_subsystem(Config) when is_list(Config) ->