Skip to content

Commit

Permalink
ssh: test case for renegotiation with openssh client
Browse files Browse the repository at this point in the history
  • Loading branch information
HansN committed Oct 17, 2016
1 parent c1c2149 commit dff5068
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
10 changes: 10 additions & 0 deletions lib/ssh/test/ssh_test_lib.erl
Expand Up @@ -208,6 +208,16 @@ reply(TestCase, Result) ->

rcv_expected(Expect, SshPort, Timeout) ->
receive
{SshPort, Recvd} when is_function(Expect) ->
case Expect(Recvd) of
true ->
ct:log("Got expected ~p from ~p",[Recvd,SshPort]),
catch port_close(SshPort),
rcv_lingering(50);
false ->
ct:log("Got UNEXPECTED ~p~n",[Recvd]),
rcv_expected(Expect, SshPort, Timeout)
end;
{SshPort, Expect} ->
ct:log("Got expected ~p from ~p",[Expect,SshPort]),
catch port_close(SshPort),
Expand Down
38 changes: 37 additions & 1 deletion lib/ssh/test/ssh_to_openssh_SUITE.erl
Expand Up @@ -58,7 +58,8 @@ groups() ->
erlang_client_openssh_server_nonexistent_subsystem
]},
{erlang_server, [], [erlang_server_openssh_client_public_key_dsa,
erlang_server_openssh_client_public_key_rsa
erlang_server_openssh_client_public_key_rsa,
erlang_server_openssh_client_renegotiate
]}
].

Expand Down Expand Up @@ -385,6 +386,41 @@ erlang_server_openssh_client_public_key_X(Config, PubKeyAlg) ->
ssh_test_lib:rcv_expected({data,<<"2\n">>}, OpenSsh, ?TIMEOUT),
ssh:stop_daemon(Pid).

%%--------------------------------------------------------------------
%% Test that the Erlang/OTP server can renegotiate with openSSH
erlang_server_openssh_client_renegotiate(Config) ->
PubKeyAlg = ssh_rsa,
SystemDir = proplists:get_value(data_dir, Config),
PrivDir = proplists:get_value(priv_dir, Config),
KnownHosts = filename:join(PrivDir, "known_hosts"),
{Pid, Host, Port} = ssh_test_lib:daemon([{system_dir, SystemDir},
{public_key_alg, PubKeyAlg},
{failfun, fun ssh_test_lib:failfun/2}]),

ct:sleep(500),

DataFile = filename:join(PrivDir, "renegotiate_openssh_client.data"),
Data = lists:duplicate(32000, $a),
ok = file:write_file(DataFile, Data),

Cmd = "ssh -p " ++ integer_to_list(Port) ++
" -o UserKnownHostsFile=" ++ KnownHosts ++
" -o RekeyLimit=20K" ++
" " ++ Host ++ " < " ++ DataFile,
OpenSsh = ssh_test_lib:open_port({spawn, Cmd}),

Expect = fun({data,R}) ->
try lists:prefix(binary_to_list(R), Data)
catch
_:_ -> false
end;
(_) ->
false
end,

ssh_test_lib:rcv_expected(Expect, OpenSsh, ?TIMEOUT),
ssh:stop_daemon(Pid).

%%--------------------------------------------------------------------
erlang_client_openssh_server_password() ->
[{doc, "Test client password option"}].
Expand Down

0 comments on commit dff5068

Please sign in to comment.