diff options
author | Hans Nilsson <hans@erlang.org> | 2021-05-21 16:58:10 +0200 |
---|---|---|
committer | Hans Nilsson <hans@erlang.org> | 2021-05-27 15:07:59 +0200 |
commit | c2208a045406fce57ab82c9f14740f84ed0ea2c9 (patch) | |
tree | 0b4ce523e565a9aea1eaccd91428bb3ca10987c6 /lib | |
parent | 118572ff45c21a8aa3891c0249458cec9c25e244 (diff) | |
download | erlang-c2208a045406fce57ab82c9f14740f84ed0ea2c9.tar.gz |
ssh: No knownhosts entry created in tests
Running tests for ssh earlier cloged the .ssh/knownhosts of the user
running the test with 28 entries. This is fixed now, and no entry
should be created.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ssh/test/ssh_algorithms_SUITE.erl | 7 | ||||
-rw-r--r-- | lib/ssh/test/ssh_basic_SUITE.erl | 23 | ||||
-rw-r--r-- | lib/ssh/test/ssh_bench_SUITE.erl | 1 | ||||
-rw-r--r-- | lib/ssh/test/ssh_compat_SUITE.erl | 9 | ||||
-rw-r--r-- | lib/ssh/test/ssh_connection_SUITE.erl | 43 | ||||
-rw-r--r-- | lib/ssh/test/ssh_options_SUITE.erl | 35 | ||||
-rw-r--r-- | lib/ssh/test/ssh_protocol_SUITE.erl | 1 | ||||
-rw-r--r-- | lib/ssh/test/ssh_pubkey_SUITE.erl | 8 | ||||
-rw-r--r-- | lib/ssh/test/ssh_sftp_SUITE.erl | 30 | ||||
-rw-r--r-- | lib/ssh/test/ssh_sup_SUITE.erl | 12 | ||||
-rw-r--r-- | lib/ssh/test/ssh_test_lib.erl | 39 | ||||
-rw-r--r-- | lib/ssh/test/ssh_to_openssh_SUITE.erl | 37 |
12 files changed, 165 insertions, 80 deletions
diff --git a/lib/ssh/test/ssh_algorithms_SUITE.erl b/lib/ssh/test/ssh_algorithms_SUITE.erl index 21d7c92236..1b8c09c088 100644 --- a/lib/ssh/test/ssh_algorithms_SUITE.erl +++ b/lib/ssh/test/ssh_algorithms_SUITE.erl @@ -364,6 +364,7 @@ sshc_simple_exec_os_cmd(Config) -> " -o UserKnownHostsFile=",KnownHosts, " -o CheckHostIP=no" " -o StrictHostKeyChecking=no" + " -o UpdateHostKeys=no" " -q" " -x" ], @@ -394,10 +395,8 @@ sshd_simple_exec(Config) -> _ -> [] end, ConnectionRef = ssh_test_lib:connect(?SSH_DEFAULT_PORT, - [{silently_accept_hosts, true}, - proplists:get_value(pref_algs,Config), - {user_interaction, false} - | ClientPubKeyOpts]), + [proplists:get_value(pref_algs,Config) + | ClientPubKeyOpts]), {ok, ChannelId0} = ssh_connection:session_channel(ConnectionRef, infinity), success = ssh_connection:exec(ConnectionRef, ChannelId0, "echo testing", infinity), diff --git a/lib/ssh/test/ssh_basic_SUITE.erl b/lib/ssh/test/ssh_basic_SUITE.erl index c1251338f9..e2993cd14f 100644 --- a/lib/ssh/test/ssh_basic_SUITE.erl +++ b/lib/ssh/test/ssh_basic_SUITE.erl @@ -550,7 +550,7 @@ shell_ssh_conn(Config) when is_list(Config) -> ct:sleep(500), IO = ssh_test_lib:start_io_server(), - {ok,C} = ssh:connect(Host, Port, [{silently_accept_hosts, true}, + C = ssh_test_lib:connect(Host, Port, [{silently_accept_hosts, true}, {user_dir, UserDir}, {user_interaction, false}]), Shell = ssh_test_lib:start_shell(C, IO, undefined), @@ -716,7 +716,9 @@ known_hosts(Config) when is_list(Config) -> ConnectionRef = ssh_test_lib:connect(Host, Port, [{user_dir, PrivDir}, {user_interaction, false}, - silently_accept_hosts]), + {silently_accept_hosts, true}, + {save_accepted_host, true} + ]), {ok, _Channel} = ssh_connection:session_channel(ConnectionRef, infinity), ok = ssh:close(ConnectionRef), {ok, Binary} = file:read_file(KnownHosts), @@ -745,7 +747,9 @@ known_hosts(Config) when is_list(Config) -> _ConnectionRef2 = ssh_test_lib:connect(Host, Port, [{user_dir, PrivDir}, {user_interaction, false}, - silently_accept_hosts]), + {silently_accept_hosts, true}, + {save_accepted_host, true} + ]), {ok, Binary2} = file:read_file(KnownHosts), case Binary of Binary2 -> ok; @@ -758,7 +762,9 @@ known_hosts(Config) when is_list(Config) -> _ConnectionRef3 = ssh_test_lib:connect(Host, Port, [{user_dir, PrivDir}, {user_interaction, false}, - silently_accept_hosts]), + {silently_accept_hosts, true}, + {save_accepted_host, true} + ]), ct:log("New known_hosts:~n~p",[Binary3]), {ok, Binary4} = file:read_file(KnownHosts), case Binary3 of @@ -979,6 +985,7 @@ internal_error(Config) when is_list(Config) -> {error, Error} = ssh:connect(Host, Port, [{silently_accept_hosts, true}, + {save_accepted_host, false}, {user_dir, UserDir}, {user_interaction, false}]), check_error(Error), @@ -1091,7 +1098,7 @@ double_close(Config) when is_list(Config) -> {user_dir, UserDir}, {user_passwords, [{"vego", "morot"}]}, {failfun, fun ssh_test_lib:failfun/2}]), - {ok, CM} = ssh:connect(Host, Port, [{silently_accept_hosts, true}, + CM = ssh_test_lib:connect(Host, Port, [{silently_accept_hosts, true}, {user_dir, UserDir}, {user, "vego"}, {password, "morot"}, @@ -1119,7 +1126,7 @@ daemon_opt_fd(Config) -> {failfun, fun ssh_test_lib:failfun/2}]), {ok,{_Host1,Port1}} = inet:sockname(S1), - {ok, C1} = ssh:connect("localhost", Port1, [{silently_accept_hosts, true}, + C1 = ssh_test_lib:connect(Port1, [{silently_accept_hosts, true}, {user_dir, UserDir}, {user, "vego"}, {password, "morot"}, @@ -1149,7 +1156,7 @@ multi_daemon_opt_fd(Config) -> {failfun, fun ssh_test_lib:failfun/2}]), {ok,{_Host,Port}} = inet:sockname(S), - {ok, C} = ssh:connect("localhost", Port, [{silently_accept_hosts, true}, + C = ssh_test_lib:connect(Port, [{silently_accept_hosts, true}, {user_dir, UserDir}, {user, "vego"}, {password, "morot"}, @@ -1470,7 +1477,7 @@ basic_test(Config) -> ServerOpts = proplists:get_value(server_opts, Config), {Pid, Host, Port} = ssh_test_lib:daemon(ServerOpts), - {ok, CM} = ssh:connect(Host, Port, ClientOpts), + CM = ssh_test_lib:connect(Host, Port, ClientOpts), ok = ssh:close(CM), ssh:stop_daemon(Pid). diff --git a/lib/ssh/test/ssh_bench_SUITE.erl b/lib/ssh/test/ssh_bench_SUITE.erl index 98c1936c43..202d4f0733 100644 --- a/lib/ssh/test/ssh_bench_SUITE.erl +++ b/lib/ssh/test/ssh_bench_SUITE.erl @@ -156,6 +156,7 @@ transfer_text(Config) -> {password, proplists:get_value(pwd, Config)}, {user_dir, proplists:get_value(priv_dir, Config)}, {silently_accept_hosts, true}, + {save_accepted_host, false}, {user_interaction, false}, {max_random_length_padding, 0} ], diff --git a/lib/ssh/test/ssh_compat_SUITE.erl b/lib/ssh/test/ssh_compat_SUITE.erl index bb46653657..1fb364842d 100644 --- a/lib/ssh/test/ssh_compat_SUITE.erl +++ b/lib/ssh/test/ssh_compat_SUITE.erl @@ -228,6 +228,7 @@ login_otp_is_client(Config) -> {user,?USER}, {user_dir, Dir}, {silently_accept_hosts,true}, + {save_accepted_host, false}, {user_interaction,false} | Opts ]) @@ -296,6 +297,7 @@ all_algorithms_sftp_exec_reneg_otp_is_client(Config) -> {user_dir, new_dir(Config)}, {preferred_algorithms, [{Tag,[Alg]} | PrefAlgs]}, {silently_accept_hosts,true}, + {save_accepted_host, false}, {user_interaction,false} ]) , test_erl_client_reneg(ConnRes, % Seems that max 10 channels may be open in sshd @@ -366,7 +368,7 @@ reneg_tester_loop(Parent, Ref, HostConnRef, Kex1) -> send_recv_big_with_renegotiate_otp_is_client(Config) -> %% Connect to the remote openssh server: {IP,Port} = ip_port(Config), - {ok,C} = ssh:connect(IP, Port, [{user,?USER}, + C = ssh_test_lib:connect(IP, Port, [{user,?USER}, {password,?PASSWD}, {user_dir, setup_remote_auth_keys_and_local_priv('ssh-rsa', Config)}, {silently_accept_hosts,true}, @@ -475,7 +477,7 @@ loop_until(CondFun, DoFun, Acc) -> exec_from_docker(Config, HostIP, HostPort, Command, Expects, ExtraSshArg) when is_binary(hd(Expects)), is_list(Config) -> {DockerIP,DockerPort} = ip_port(Config), - {ok,C} = ssh:connect(DockerIP, DockerPort, + C = ssh_test_lib:connect(DockerIP, DockerPort, [{user,?USER}, {password,?PASSWD}, {user_dir, new_dir(Config)}, @@ -636,6 +638,7 @@ setup_remote_auth_keys_and_local_priv(KeyAlg, IP, Port, UserDir, Config) -> {password, ?PASSWD }, {auth_methods, "password"}, {silently_accept_hosts,true}, + {save_accepted_host, false}, {preferred_algorithms, ssh_transport:supported_algorithms()}, {user_interaction,false} ]), @@ -1184,7 +1187,7 @@ do_check_local_directory(ServerRootDir) -> call_sftp_in_docker(Config, ServerIP, ServerPort, Cmnds, UserDir, Ref) -> {DockerIP,DockerPort} = ip_port(Config), ct:log("Going to connect ~p:~p", [DockerIP, DockerPort]), - {ok,C} = ssh:connect(DockerIP, DockerPort, + C = ssh_test_lib:connect(DockerIP, DockerPort, [{user,?USER}, {password,?PASSWD}, {user_dir, UserDir}, diff --git a/lib/ssh/test/ssh_connection_SUITE.erl b/lib/ssh/test/ssh_connection_SUITE.erl index 2fce57c02b..01eecfabbc 100644 --- a/lib/ssh/test/ssh_connection_SUITE.erl +++ b/lib/ssh/test/ssh_connection_SUITE.erl @@ -201,15 +201,16 @@ end_per_testcase(_TestCase, _Config) -> %% Test Cases -------------------------------------------------------- %%-------------------------------------------------------------------- simple_exec(Config) when is_list(Config) -> - ConnectionRef = ssh_test_lib:connect(?SSH_DEFAULT_PORT, [{silently_accept_hosts, true}, - {user_interaction, false}]), + ConnectionRef = ssh_test_lib:connect(?SSH_DEFAULT_PORT, []), do_simple_exec(ConnectionRef). %%-------------------------------------------------------------------- simple_exec_sock(_Config) -> {ok, Sock} = ssh_test_lib:gen_tcp_connect(?SSH_DEFAULT_PORT, [{active,false}]), - {ok, ConnectionRef} = ssh:connect(Sock, [{silently_accept_hosts, true}, - {user_interaction, false}]), + {ok, ConnectionRef} = ssh:connect(Sock, [{save_accepted_host, false}, + {silently_accept_hosts, true}, + {user_interaction, true} + ]), do_simple_exec(ConnectionRef). %%-------------------------------------------------------------------- @@ -219,8 +220,9 @@ simple_exec_two_socks(_Config) -> spawn_link( fun() -> {ok, Sock} = ssh_test_lib:gen_tcp_connect(?SSH_DEFAULT_PORT, [{active,false}]), - {ok, ConnectionRef} = ssh:connect(Sock, [{silently_accept_hosts, true}, - {user_interaction, false}]), + {ok, ConnectionRef} = ssh:connect(Sock, [{save_accepted_host, false}, + {silently_accept_hosts, true}, + {user_interaction, true}]), Parent ! {self(),do_simple_exec(ConnectionRef)} end) end, @@ -236,7 +238,9 @@ simple_exec_two_socks(_Config) -> %%-------------------------------------------------------------------- connect_sock_not_tcp(_Config) -> {ok,Sock} = gen_udp:open(0, []), - {error, not_tcp_socket} = ssh:connect(Sock, []), + {error, not_tcp_socket} = ssh:connect(Sock, [{save_accepted_host, false}, + {silently_accept_hosts, true}, + {user_interaction, true}]), gen_udp:close(Sock). %%-------------------------------------------------------------------- @@ -248,7 +252,9 @@ daemon_sock_not_tcp(_Config) -> %%-------------------------------------------------------------------- connect_sock_not_passive(_Config) -> {ok,Sock} = ssh_test_lib:gen_tcp_connect(?SSH_DEFAULT_PORT, []), - {error, not_passive_mode} = ssh:connect(Sock, []), + {error, not_passive_mode} = ssh:connect(Sock, [{save_accepted_host, false}, + {silently_accept_hosts, true}, + {user_interaction, true}]), gen_tcp:close(Sock). %%-------------------------------------------------------------------- @@ -259,8 +265,7 @@ daemon_sock_not_passive(_Config) -> %%-------------------------------------------------------------------- small_cat(Config) when is_list(Config) -> - ConnectionRef = ssh_test_lib:connect(?SSH_DEFAULT_PORT, [{silently_accept_hosts, true}, - {user_interaction, false}]), + ConnectionRef = ssh_test_lib:connect(?SSH_DEFAULT_PORT, []), {ok, ChannelId0} = ssh_connection:session_channel(ConnectionRef, infinity), success = ssh_connection:exec(ConnectionRef, ChannelId0, "cat", infinity), @@ -348,8 +353,7 @@ big_cat(Config) when is_list(Config) -> %%-------------------------------------------------------------------- send_after_exit(Config) when is_list(Config) -> - ConnectionRef = ssh_test_lib:connect(?SSH_DEFAULT_PORT, [{silently_accept_hosts, true}, - {user_interaction, false}]), + ConnectionRef = ssh_test_lib:connect(?SSH_DEFAULT_PORT, []), {ok, ChannelId0} = ssh_connection:session_channel(ConnectionRef, infinity), Data = <<"I like spaghetti squash">>, @@ -413,8 +417,7 @@ encode_decode_pty_opts(_Config) -> %%-------------------------------------------------------------------- ptty_alloc_default(Config) when is_list(Config) -> - ConnectionRef = ssh_test_lib:connect(?SSH_DEFAULT_PORT, [{silently_accept_hosts, true}, - {user_interaction, false}]), + ConnectionRef = ssh_test_lib:connect(?SSH_DEFAULT_PORT, []), {ok, ChannelId} = ssh_connection:session_channel(ConnectionRef, infinity), Expect = case proplists:get_value(ptty_supported, Config) of true -> success; @@ -425,8 +428,7 @@ ptty_alloc_default(Config) when is_list(Config) -> %%-------------------------------------------------------------------- ptty_alloc(Config) when is_list(Config) -> - ConnectionRef = ssh_test_lib:connect(?SSH_DEFAULT_PORT, [{silently_accept_hosts, true}, - {user_interaction, false}]), + ConnectionRef = ssh_test_lib:connect(?SSH_DEFAULT_PORT, []), {ok, ChannelId} = ssh_connection:session_channel(ConnectionRef, infinity), Expect = case proplists:get_value(ptty_supported, Config) of true -> success; @@ -439,8 +441,7 @@ ptty_alloc(Config) when is_list(Config) -> %%-------------------------------------------------------------------- ptty_alloc_pixel(Config) when is_list(Config) -> - ConnectionRef = ssh_test_lib:connect(?SSH_DEFAULT_PORT, [{silently_accept_hosts, true}, - {user_interaction, false}]), + ConnectionRef = ssh_test_lib:connect(?SSH_DEFAULT_PORT, []), {ok, ChannelId} = ssh_connection:session_channel(ConnectionRef, infinity), Expect = case proplists:get_value(ptty_supported, Config) of true -> success; @@ -940,6 +941,7 @@ start_shell_sock_exec_fun(Config) when is_list(Config) -> {ok, Sock} = ssh_test_lib:gen_tcp_connect(Host, Port, [{active,false}]), {ok,ConnectionRef} = ssh:connect(Sock, [{silently_accept_hosts, true}, + {save_accepted_host, false}, {user, "foo"}, {password, "morot"}, {user_interaction, true}, @@ -983,6 +985,7 @@ start_shell_sock_daemon_exec(Config) -> %% The client accepts the tcp connection from the server and ssh-connects to it {ok,Sc} = gen_tcp:accept(Sl), {ok,ConnectionRef} = ssh:connect(Sc, [{silently_accept_hosts, true}, + {save_accepted_host, false}, {user, "foo"}, {password, "morot"}, {user_interaction, true}, @@ -1035,6 +1038,7 @@ start_shell_sock_daemon_exec_multi(Config) -> [begin {ok,Sc} = gen_tcp:accept(Sl), {ok,ConnectionRef} = ssh:connect(Sc, [{silently_accept_hosts, true}, + {save_accepted_host, false}, {user, "foo"}, {password, "morot"}, {user_interaction, true}, @@ -1186,6 +1190,8 @@ stop_listener(Config) when is_list(Config) -> ssh:stop_listener(Host, Port), {error, _} = ssh:connect(Host, Port, [{silently_accept_hosts, true}, + {save_accepted_host, false}, + {save_accepted_host, false}, {user, "foo"}, {password, "morot"}, {user_interaction, true}, @@ -1210,6 +1216,7 @@ stop_listener(Config) when is_list(Config) -> {user_interaction, true}, {user_dir, UserDir}]), {error, _} = ssh:connect(Host, Port, [{silently_accept_hosts, true}, + {save_accepted_host, false}, {user, "foo"}, {password, "morot"}, {user_interaction, true}, diff --git a/lib/ssh/test/ssh_options_SUITE.erl b/lib/ssh/test/ssh_options_SUITE.erl index 88b3d09eba..773a6e37f5 100644 --- a/lib/ssh/test/ssh_options_SUITE.erl +++ b/lib/ssh/test/ssh_options_SUITE.erl @@ -258,6 +258,7 @@ server_password_option(Config) when is_list(Config) -> {error, Reason} = ssh:connect(Host, Port, [{silently_accept_hosts, true}, + {save_accepted_host, false}, {user, "vego"}, {password, "foo"}, {user_interaction, false}, @@ -290,12 +291,14 @@ server_userpassword_option(Config) when is_list(Config) -> {error, Reason} = ssh:connect(Host, Port, [{silently_accept_hosts, true}, + {save_accepted_host, false}, {user, "foo"}, {password, "morot"}, {user_interaction, false}, {user_dir, UserDir}]), {error, Reason} = ssh:connect(Host, Port, [{silently_accept_hosts, true}, + {save_accepted_host, false}, {user, "vego"}, {password, "foo"}, {user_interaction, false}, @@ -325,12 +328,14 @@ server_pwdfun_option(Config) -> {error, Reason} = ssh:connect(Host, Port, [{silently_accept_hosts, true}, + {save_accepted_host, false}, {user, "foo"}, {password, "morot"}, {user_interaction, false}, {user_dir, UserDir}]), {error, Reason} = ssh:connect(Host, Port, [{silently_accept_hosts, true}, + {save_accepted_host, false}, {user, "vego"}, {password, "foo"}, {user_interaction, false}, @@ -371,12 +376,14 @@ server_pwdfun_4_option(Config) -> {error, Reason} = ssh:connect(Host, Port, [{silently_accept_hosts, true}, + {save_accepted_host, false}, {user, "foo"}, {password, "morot"}, {user_interaction, false}, {user_dir, UserDir}]), {error, Reason} = ssh:connect(Host, Port, [{silently_accept_hosts, true}, + {save_accepted_host, false}, {user, "fie"}, {password, "morot"}, {user_interaction, false}, @@ -390,6 +397,7 @@ server_pwdfun_4_option(Config) -> {error, Reason} = ssh:connect(Host, Port, [{silently_accept_hosts, true}, + {save_accepted_host, false}, {user, "bandit"}, {password, "pwd breaking"}, {user_interaction, false}, @@ -593,14 +601,16 @@ user_dir_option(Config) -> %% Any port will do (beware, implementation knowledge!): Port = 65535, - case ssh:connect("localhost", Port, [{user_dir, DirUnread}]) of + case ssh:connect("localhost", Port, [{user_dir, DirUnread}, + {save_accepted_host, false}]) of {error,{eoptions,{{user_dir,DirUnread},eacces}}} -> ok; {error,econnrefused} -> ct:fail("Didn't detect that dir is unreadable", []) end, - case ssh:connect("localhost", Port, [{user_dir, FileRead}]) of + case ssh:connect("localhost", Port, [{user_dir, FileRead}, + {save_accepted_host, false}]) of {error,{eoptions,{{user_dir,FileRead},enotdir}}} -> ok; {error,econnrefused} -> @@ -1048,6 +1058,7 @@ ssh_connect_timeout(_Config) -> {error,{faked_transport,connect,TimeoutToTransport}} = ssh:connect("localhost", 12345, [{transport,{tcp,?MODULE,tcp_closed}}, + {save_accepted_host, false}, {connect_timeout,ConnTimeout}], 1000), case TimeoutToTransport of @@ -1086,7 +1097,7 @@ ssh_connect_arg4_timeout(_Config) -> %% try to connect with a timeout, but "supervise" it Client = spawn(fun() -> T0 = erlang:monotonic_time(), - Rc = ssh:connect("localhost",Port,[],Timeout), + Rc = ssh:connect("localhost",Port,[{save_accepted_host, false}],Timeout), ct:log("Client ssh:connect got ~p",[Rc]), Parent ! {done,self(),Rc,T0} end), @@ -1154,7 +1165,7 @@ ssh_daemon_minimal_remote_max_packet_size_option(Config) -> %% This test try every algorithm by connecting to an Erlang server id_string_no_opt_client(Config) -> {Server, _Host, Port} = fake_daemon(Config), - {error,_} = ssh:connect("localhost", Port, [], 1000), + {error,_} = ssh:connect("localhost", Port, [{save_accepted_host, false}], 1000), receive {id,Server,"SSH-2.0-Erlang/"++Vsn} -> true = expected_ssh_vsn(Vsn); @@ -1167,7 +1178,9 @@ id_string_no_opt_client(Config) -> %%-------------------------------------------------------------------- id_string_own_string_client(Config) -> {Server, _Host, Port} = fake_daemon(Config), - {error,_} = ssh:connect("localhost", Port, [{id_string,"Pelle"}], 1000), + {error,_} = ssh:connect("localhost", Port, [{id_string,"Pelle"}, + {save_accepted_host, false} + ], 1000), receive {id,Server,"SSH-2.0-Pelle\r\n"} -> ok; @@ -1180,7 +1193,8 @@ id_string_own_string_client(Config) -> %%-------------------------------------------------------------------- id_string_own_string_client_trail_space(Config) -> {Server, _Host, Port} = fake_daemon(Config), - {error,_} = ssh:connect("localhost", Port, [{id_string,"Pelle "}], 1000), + {error,_} = ssh:connect("localhost", Port, [{id_string,"Pelle "}, + {save_accepted_host, false}], 1000), receive {id,Server,"SSH-2.0-Pelle \r\n"} -> ok; @@ -1193,7 +1207,8 @@ id_string_own_string_client_trail_space(Config) -> %%-------------------------------------------------------------------- id_string_random_client(Config) -> {Server, _Host, Port} = fake_daemon(Config), - {error,_} = ssh:connect("localhost", Port, [{id_string,random}], 1000), + {error,_} = ssh:connect("localhost", Port, [{id_string,random}, + {save_accepted_host, false}], 1000), receive {id,Server,Id="SSH-2.0-Erlang"++_} -> ct:fail("Unexpected id: ~s.",[Id]); @@ -1365,6 +1380,7 @@ connect_fun(ssh_sftp__start_channel, _Config) -> {ok,_Pid,ConnRef} = ssh_sftp:start_channel(Host, Port, [{silently_accept_hosts, true}, + {save_accepted_host, false}, {user, "carni"}, {password, "meat"} ]), @@ -1477,6 +1493,7 @@ max_sessions_drops_tcp_connects(Config) -> SSHconnect = fun(N) -> R = ssh:connect(Host, Port, [{silently_accept_hosts, true}, + {save_accepted_host, false}, {user_dir, proplists:get_value(priv_dir,Config)}, {user_interaction, false}, {user, "carni"}, @@ -1539,10 +1556,10 @@ save_accepted_host_option(Config) -> {error,enoent} = file:read_file(KnownHosts), {ok,_C1} = ssh:connect(Host, Port, [{silently_accept_hosts, true}, + {save_accepted_host, false}, {user, "vego"}, {password, "morot"}, {user_interaction, false}, - {save_accepted_host, false}, {user_dir, UserDir}]), {error,enoent} = file:read_file(KnownHosts), @@ -1636,6 +1653,7 @@ config_file(Config) -> %% First connection. The client_options should be applied: {ok,C1} = rpc:call(Node, ssh, connect, [loopback, ?SSH_DEFAULT_PORT, [{silently_accept_hosts, true}, + {save_accepted_host, false}, {user_interaction, false} ]]), ct:log("C1 = ~n~p", [C1]), @@ -1650,6 +1668,7 @@ config_file(Config) -> C2_Opts = [{modify_algorithms,[{rm,[{kex,[K1b]}]}, % N.B. {append, [{kex,[K2a]}]}]}, {silently_accept_hosts, true}, + {save_accepted_host, false}, {user_interaction, false} ], {ok,C2} = rpc:call(Node, ssh, connect, [loopback, ?SSH_DEFAULT_PORT, C2_Opts]), diff --git a/lib/ssh/test/ssh_protocol_SUITE.erl b/lib/ssh/test/ssh_protocol_SUITE.erl index ab854e4282..41eb6fcdee 100644 --- a/lib/ssh/test/ssh_protocol_SUITE.erl +++ b/lib/ssh/test/ssh_protocol_SUITE.erl @@ -1026,6 +1026,7 @@ std_connect(Host, Port, Config, Opts) -> %% Prefere User's Opts to the default opts [O || O = {Tag,_} <- [{user,User},{password,Pwd}, {silently_accept_hosts, true}, + {save_accepted_host, false}, {user_dir, user_dir(Config)}, {user_interaction, false}], not lists:keymember(Tag, 1, Opts) diff --git a/lib/ssh/test/ssh_pubkey_SUITE.erl b/lib/ssh/test/ssh_pubkey_SUITE.erl index 0e5dac6f33..6c78cd2d68 100644 --- a/lib/ssh/test/ssh_pubkey_SUITE.erl +++ b/lib/ssh/test/ssh_pubkey_SUITE.erl @@ -568,10 +568,10 @@ ssh_list_public_key(Config) when is_list(Config) -> chk_encode(Data, Type) -> case ssh_file:decode(ssh_file:encode(Data,Type), Type) of Data-> - ct:pal("re-encode ~p ok", [Type]), + ct:log("re-encode ~p ok", [Type]), true; Result -> - ct:pal("re-encode ~p FAILED~n" + ct:log("re-encode ~p FAILED~n" "Got~n ~p~nExpect~n ~p~n", [Type, Result, Data]), false @@ -581,10 +581,10 @@ chk_encode(Data, Type) -> chk_decode(Data, Expect, Type) -> case ssh_file:decode(Data, Type) of Expect -> - ct:pal("decode ~p ok", [Type]), + ct:log("decode ~p ok", [Type]), true; BadResult -> - ct:pal("decode ~p FAILED~n" + ct:log("decode ~p FAILED~n" "Result~n ~p~nExpect~n ~p~n" "~p", [Type, BadResult, Expect, diff --git a/lib/ssh/test/ssh_sftp_SUITE.erl b/lib/ssh/test/ssh_sftp_SUITE.erl index 89f449040a..2e9c3e3cb6 100644 --- a/lib/ssh/test/ssh_sftp_SUITE.erl +++ b/lib/ssh/test/ssh_sftp_SUITE.erl @@ -119,7 +119,8 @@ groups() -> {unicode, [], [{group,erlang_server}, {group,openssh_server}, - sftp_nonexistent_subsystem]}, + sftp_nonexistent_subsystem + ]}, {big_recvpkt_size, [], [{group,erlang_server}, {group,openssh_server}]}, @@ -231,7 +232,9 @@ init_per_group(openssh_server, Config) -> Host = ssh_test_lib:hostname(), case (catch ssh_sftp:start_channel(Host, [{user_interaction, false}, - {silently_accept_hosts, true}])) of + {silently_accept_hosts, true}, + {save_accepted_host, false} + ])) of {ok, _ChannelPid, Connection} -> [{peer, {_HostName,{IPx,Portx}}}] = ssh:connection_info(Connection,[peer]), ssh:close(Connection), @@ -250,16 +253,16 @@ init_per_group(remote_tar, Config) -> ct:log("Server (~p) at ~p:~p",[proplists:get_value(group,Config),Host,Port]), User = proplists:get_value(user, Config), Passwd = proplists:get_value(passwd, Config), - {ok, Connection} = + Connection = case proplists:get_value(group, Config) of erlang_server -> - ssh:connect(Host, Port, + ssh_test_lib:connect(Host, Port, [{user, User}, {password, Passwd}, {user_interaction, false}, {silently_accept_hosts, true}]); openssh_server -> - ssh:connect(Host, Port, + ssh_test_lib:connect(Host, Port, [{user_interaction, false}, {silently_accept_hosts, true}]) end, @@ -312,7 +315,9 @@ init_per_testcase(version_option, Config0) -> {user, User}, {password, Passwd}, {user_interaction, false}, - {silently_accept_hosts, true}]), + {silently_accept_hosts, true}, + {save_accepted_host, false} + ]), Sftp = {ChannelPid, Connection}, [{sftp,Sftp}, {watchdog, Dog} | TmpConfig]; @@ -336,7 +341,8 @@ init_per_testcase(Case, Config00) -> [{user, User}, {password, Passwd}, {user_interaction, false}, - {silently_accept_hosts, true} + {silently_accept_hosts, true}, + {save_accepted_host, false} | PktSzOpt ] ), @@ -349,7 +355,8 @@ init_per_testcase(Case, Config00) -> {ok, ChannelPid, Connection} = ssh_sftp:start_channel(Host, [{user_interaction, false}, - {silently_accept_hosts, true} + {silently_accept_hosts, true}, + {save_accepted_host, false} | PktSzOpt ]), Sftp = {ChannelPid, Connection}, @@ -736,7 +743,8 @@ start_channel_sock(Config) -> end, Opts = [{user_interaction, false}, - {silently_accept_hosts, true} + {silently_accept_hosts, true}, + {save_accepted_host, false} | LoginOpts], {Host,Port} = proplists:get_value(peer, Config), @@ -789,7 +797,9 @@ sftp_nonexistent_subsystem(Config) when is_list(Config) -> [{user_interaction, false}, {user, User}, {password, Passwd}, - {silently_accept_hosts, true}]). + {silently_accept_hosts, true}, + {save_accepted_host, false} + ]). %%-------------------------------------------------------------------- version_option(Config) when is_list(Config) -> diff --git a/lib/ssh/test/ssh_sup_SUITE.erl b/lib/ssh/test/ssh_sup_SUITE.erl index c52c95c477..7c31898b0c 100644 --- a/lib/ssh/test/ssh_sup_SUITE.erl +++ b/lib/ssh/test/ssh_sup_SUITE.erl @@ -129,7 +129,8 @@ sshc_subtree(Config) when is_list(Config) -> ?wait_match([], supervisor:which_children(sshc_sup)), - {ok, Pid1} = ssh:connect(Host, Port, [{silently_accept_hosts, true}, + Pid1 = ssh_test_lib:connect(Host, Port, [{silently_accept_hosts, true}, + {save_accepted_host, false}, {user_interaction, false}, {user, ?USER}, {password, ?PASSWD},{user_dir, UserDir}]), @@ -139,7 +140,8 @@ sshc_subtree(Config) when is_list(Config) -> [SysSup, LocalIP, LocalPort]), check_sshc_system_tree(SysSup, Pid1, LocalIP, LocalPort, Config), - {ok, Pid2} = ssh:connect(Host, Port, [{silently_accept_hosts, true}, + Pid2 = ssh_test_lib:connect(Host, Port, [{silently_accept_hosts, true}, + {save_accepted_host, false}, {user_interaction, false}, {user, ?USER}, {password, ?PASSWD}, {user_dir, UserDir}]), ?wait_match([?SYSTEM_SUP(_,_), @@ -219,7 +221,8 @@ killed_acceptor_restarts(Config) -> true = (AccPid /= AccPid2), %% Connect first client and check it is alive: - {ok,C1} = ssh:connect("localhost", Port, [{silently_accept_hosts, true}, + C1 = ssh_test_lib:connect("localhost", Port, [{silently_accept_hosts, true}, + {save_accepted_host, false}, {user_interaction, false}, {user, ?USER}, {password, ?PASSWD}, @@ -246,6 +249,7 @@ killed_acceptor_restarts(Config) -> %% Connect second client and check it is alive: C2 = case ssh:connect("localhost", Port, [{silently_accept_hosts, true}, + {save_accepted_host, false}, {user_interaction, false}, {user, ?USER}, {password, ?PASSWD}, @@ -383,7 +387,7 @@ chk_empty_con_daemon(Daemon) -> %%------------------------------------------------------------------------- check_sshd_system_tree(Daemon, Host, Port, Config) -> UserDir = proplists:get_value(userdir, Config), - {ok, ClientConn} = ssh:connect(Host, Port, [{silently_accept_hosts, true}, + ClientConn = ssh_test_lib:connect(Host, Port, [{silently_accept_hosts, true}, {user_interaction, false}, {user, ?USER}, {password, ?PASSWD}, diff --git a/lib/ssh/test/ssh_test_lib.erl b/lib/ssh/test/ssh_test_lib.erl index 9623dc767a..e8f34723f8 100644 --- a/lib/ssh/test/ssh_test_lib.erl +++ b/lib/ssh/test/ssh_test_lib.erl @@ -135,12 +135,43 @@ connect(Port, Options) when is_integer(Port) -> connect(any, Port, Options) -> connect(hostname(), Port, Options); -connect(Host, Port, Options) -> + +connect(Host, ?SSH_DEFAULT_PORT, Options0) -> + Options = + set_opts_if_not_set([{silently_accept_hosts, true}, + {save_accepted_host, false}, + {user_interaction, false} + ], Options0), + do_connect(Host, ?SSH_DEFAULT_PORT, Options); + +connect(Host, Port, Options0) -> + Options = + case proplists:get_value(user_dir,Options0) of + undefined -> + %% Avoid uppdating the known_hosts if it is the default one + set_opts_if_not_set([{save_accepted_host, false}], Options0); + _ -> + Options0 + end, + do_connect(Host, Port, Options). + + +do_connect(Host, Port, Options) -> R = ssh:connect(Host, Port, Options), ct:log("~p:~p ssh:connect(~p, ~p, ~p)~n -> ~p",[?MODULE,?LINE,Host, Port, Options, R]), {ok, ConnectionRef} = R, ConnectionRef. +set_opts_if_not_set(OptsToSet, Options0) -> + lists:foldl(fun({K,V}, Opts) -> + case proplists:get_value(K, Opts) of + undefined -> + [{K,V} | Opts]; + _ -> + Opts + end + end, Options0, OptsToSet). + %%%---------------------------------------------------------------- daemon(Options) -> daemon(any, 0, Options). @@ -287,7 +318,9 @@ start_shell(Port, IOServer, ExtraOptions) -> ct:log("~p:~p:~p ssh_test_lib:start_shell(~p, ~p, ~p)", [?MODULE,?LINE,self(), Port, IOServer, ExtraOptions]), Options = [{user_interaction, false}, - {silently_accept_hosts,true} | ExtraOptions], + {silently_accept_hosts,true}, + {save_accepted_host,false} + | ExtraOptions], try group_leader(IOServer, self()), case Port of @@ -535,6 +568,7 @@ openssh_sanity_check(Config) -> case ssh:connect("localhost", ?SSH_DEFAULT_PORT, [{password,""}, {silently_accept_hosts, true}, + {save_accepted_host, false}, {user_interaction, false} ]) of {ok, Pid} -> @@ -560,6 +594,7 @@ default_algorithms(sshd, Host, Port) -> try run_fake_ssh( ssh_trpt_test_lib:exec( [{connect,Host,Port, [{silently_accept_hosts, true}, + {save_accepted_host, false}, {user_interaction, false}]}])) catch _C:_E -> diff --git a/lib/ssh/test/ssh_to_openssh_SUITE.erl b/lib/ssh/test/ssh_to_openssh_SUITE.erl index 549239d56c..62d97d9315 100644 --- a/lib/ssh/test/ssh_to_openssh_SUITE.erl +++ b/lib/ssh/test/ssh_to_openssh_SUITE.erl @@ -65,7 +65,7 @@ all() -> {skip, "openSSH not installed on host"}; _ -> [{group, erlang_client}, - {group, erlang_server} + {group, erlang_server} ] end. @@ -81,7 +81,8 @@ groups() -> erlang_server_openssh_client_renegotiate, exec_with_io_in_sshc, exec_direct_with_io_in_sshc - ]}, + ] + }, {tunnel_distro_client, [], [tunnel_in_non_erlclient_erlserver, tunnel_out_non_erlclient_erlserver]} ]. @@ -106,7 +107,7 @@ init_per_group(erlang_server, Config) -> Config; init_per_group(G, Config) when G==tunnel_distro_server ; G==tunnel_distro_client -> - case no_forwarding() of + case no_forwarding(Config) of true -> {skip, "port forwarding disabled in external ssh"}; false -> @@ -176,10 +177,9 @@ exec_with_io_in_sshc(Config) when is_list(Config) -> ct:sleep(500), PrivDir = proplists:get_value(priv_dir, Config), - KnownHosts = filename:join(PrivDir, "known_hosts"), ExecStr = "\"io:read('% ').\"", Cmd = "echo howdy. | " ++ ssh_test_lib:open_sshc_cmd(Host, Port, - [" -o UserKnownHostsFile=", KnownHosts, + [" -o UserKnownHostsFile=", "/dev/null", " -o CheckHostIP=no" " -o StrictHostKeyChecking=no" " -q" @@ -210,9 +210,8 @@ exec_direct_with_io_in_sshc(Config) when is_list(Config) -> ct:sleep(500), PrivDir = proplists:get_value(priv_dir, Config), - KnownHosts = filename:join(PrivDir, "known_hosts"), Cmd = "echo ciao. | " ++ ssh_test_lib:open_sshc_cmd(Host, Port, - [" -o UserKnownHostsFile=", KnownHosts, + [" -o UserKnownHostsFile=", "/dev/null", " -o CheckHostIP=no" " -o StrictHostKeyChecking=no" " -q" @@ -245,9 +244,8 @@ erlang_server_openssh_client_renegotiate(Config) -> Data = lists:duplicate(trunc(1.1*RenegLimitK*1024), $a), ok = file:write_file(DataFile, Data), - KnownHosts = filename:join(PrivDir, "known_hosts"), Cmd = ssh_test_lib:open_sshc_cmd(Host, Port, - [" -o UserKnownHostsFile=", KnownHosts, + [" -o UserKnownHostsFile=", "/dev/null", " -o CheckHostIP=no" " -o StrictHostKeyChecking=no" " -q" @@ -301,9 +299,8 @@ tunnel_out_non_erlclient_erlserver(Config) -> ListenHost = {127,0,0,1}, ListenPort = 2345, - KnownHosts = filename:join(PrivDir, "known_hosts"), Cmd = ssh_test_lib:open_sshc_cmd(Host, Port, - [" -o UserKnownHostsFile=", KnownHosts, + [" -o UserKnownHostsFile=", "/dev/null", " -o CheckHostIP=no" " -o StrictHostKeyChecking=no" " -q" @@ -330,10 +327,9 @@ tunnel_in_non_erlclient_erlserver(Config) -> ListenHost = {127,0,0,1}, ListenPort = 2345, - KnownHosts = filename:join(UserDir, "known_hosts"), Cmd = ssh_test_lib:open_sshc_cmd(Host, Port, - [" -o UserKnownHostsFile=", KnownHosts, + [" -o UserKnownHostsFile=", "/dev/null", " -o CheckHostIP=no" " -o StrictHostKeyChecking=no" " -q" @@ -369,8 +365,7 @@ tunnel_in_erlclient_erlserver(Config) -> %%-------------------------------------------------------------------- tunnel_in_erlclient_openssh_server(_Config) -> - C = ssh_test_lib:connect(?SSH_DEFAULT_PORT, [{silently_accept_hosts, true}, - {user_interaction, false}]), + C = ssh_test_lib:connect(?SSH_DEFAULT_PORT, []), {ToSock, ToHost, ToPort} = tunneling_listner(), ListenHost = {127,0,0,1}, @@ -400,8 +395,7 @@ tunnel_out_erlclient_erlserver(Config) -> %%-------------------------------------------------------------------- tunnel_out_erlclient_openssh_server(_Config) -> - C = ssh_test_lib:connect(?SSH_DEFAULT_PORT, [{silently_accept_hosts, true}, - {user_interaction, false}]), + C = ssh_test_lib:connect(?SSH_DEFAULT_PORT, []), {ToSock, ToHost, ToPort} = tunneling_listner(), ListenHost = {127,0,0,1}, @@ -534,9 +528,14 @@ extra_logout() -> end. %%%---------------------------------------------------------------- -no_forwarding() -> +no_forwarding(Config) -> %%% Check if the ssh of the OS has tunneling enabled - Cmnd = "ssh -R 0:localhost:4567 localhost exit", + UserDir = proplists:get_value(priv_dir, Config), + Cmnd = ["ssh " + " -o UserKnownHostsFile=", "/dev/null", + " -o CheckHostIP=no" + " -o StrictHostKeyChecking=no" + " -R 0:localhost:4567 localhost exit"], FailRegExp = "Port forwarding is disabled" "|remote port forwarding failed" |