File 2779-ssh-Extend-known_hosts-test-in-ssh_basic_SUITE.patch of Package erlang
From a23dbc39576763a39784154c39e43bbd687ff655 Mon Sep 17 00:00:00 2001
From: Hans Nilsson <hans@erlang.org>
Date: Tue, 18 Feb 2020 18:13:51 +0100
Subject: [PATCH 09/10] ssh: Extend known_hosts test in ssh_basic_SUITE
---
lib/ssh/test/ssh_basic_SUITE.erl | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/lib/ssh/test/ssh_basic_SUITE.erl b/lib/ssh/test/ssh_basic_SUITE.erl
index 2ed3a248d5..5565c05ef8 100644
--- a/lib/ssh/test/ssh_basic_SUITE.erl
+++ b/lib/ssh/test/ssh_basic_SUITE.erl
@@ -900,13 +900,34 @@ known_hosts(Config) when is_list(Config) ->
{ok, _Channel} = ssh_connection:session_channel(ConnectionRef, infinity),
ok = ssh:close(ConnectionRef),
{ok, Binary} = file:read_file(KnownHosts),
+ ct:log("known_hosts:~n~p",[Binary]),
Lines = string:tokens(binary_to_list(Binary), "\n"),
[Line] = Lines,
[HostAndIp, Alg, _KeyData] = string:tokens(Line, " "),
- [StoredHost, _Ip] = string:tokens(HostAndIp, ","),
+ [StoredHost|_] = string:tokens(HostAndIp, ","),
true = ssh_test_lib:match_ip(StoredHost, Host),
"ssh-" ++ _ = Alg,
+ NLines = length(binary:split(Binary, <<"\n">>, [global,trim_all])),
+ ct:log("NLines = ~p~n~p", [NLines,Binary]),
+ if
+ NLines>1 -> ct:fail("wrong num lines", []);
+ NLines<1 -> ct:fail("wrong num lines", []);
+ true -> ok
+ end,
+
+ _ConnectionRef2 =
+ ssh_test_lib:connect(Host, Port, [{user_dir, PrivDir},
+ {user_interaction, false},
+ silently_accept_hosts]),
+ {ok, Binary2} = file:read_file(KnownHosts),
+ case Binary of
+ Binary2 -> ok;
+ _ -> ct:log("2nd differ~n~p", [Binary2]),
+ ct:fail("wrong num lines", [])
+ end,
+
ssh:stop_daemon(Pid).
+
%%--------------------------------------------------------------------
%%% Test that we can use keyes protected by pass phrases
--
2.16.4