Skip to content

Commit

Permalink
ssh: GH-8223 'EXIT' issue testcases
Browse files Browse the repository at this point in the history
Co-authored-by: Maria Scott <[email protected]>
Co-authored-by: Jan Uhlig <[email protected]>
  • Loading branch information
3 people committed Oct 2, 2024
1 parent 0418c10 commit 19be905
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions lib/ssh/test/ssh_connection_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@
start_shell_sock_exec_fun/1,
start_subsystem_on_closed_channel/1,
stop_listener/1,
trap_exit_connect/1,
trap_exit_daemon/1,
ssh_exec_echo/2 % called as an MFA
]).

Expand All @@ -130,6 +132,8 @@ all() ->
exec_disabled,
exec_shell_disabled,
start_shell,
trap_exit_connect,
trap_exit_daemon,
start_shell_pty,
start_shell_exec,
start_shell_exec_fun,
Expand Down Expand Up @@ -1103,6 +1107,59 @@ do_start_shell_exec_fun(Fun, Command, Expect, ExpectType, Config) ->
ssh:close(ConnectionRef),
ssh:stop_daemon(Pid).

%%--------------------------------------------------------------------
%% Issue GH-8223
trap_exit_connect(Config) when is_list(Config) ->
PrivDir = proplists:get_value(priv_dir, Config),
UserDir = filename:join(PrivDir, nopubkey),
file:make_dir(UserDir),
SysDir = proplists:get_value(data_dir, Config),
{Pid, Host, Port} = ssh_test_lib:daemon([{system_dir, SysDir},
{user_dir, UserDir},
{password, "morot"}]),
%% Fake an EXIT message
ExitMsg = {'EXIT', self(), make_ref()},
self() ! ExitMsg,

{ok, ConnectionRef} = ssh:connect(Host, Port, [{silently_accept_hosts, true},
{save_accepted_host, false},
{user, "foo"},
{password, "morot"},
{user_interaction, true},
{user_dir, UserDir}]),
ssh:close(ConnectionRef),
ssh:stop_daemon(Pid),

%% Ensure the EXIT message is still there
receive
ExitMsg -> ok
after 0 ->
ct:fail("No EXIT message")
end.

%%--------------------------------------------------------------------
%% Issue GH-8223
trap_exit_daemon(Config) when is_list(Config) ->
PrivDir = proplists:get_value(priv_dir, Config),
UserDir = filename:join(PrivDir, nopubkey),
file:make_dir(UserDir),
SysDir = proplists:get_value(data_dir, Config),

%% Fake an EXIT message
ExitMsg = {'EXIT', self(), make_ref()},
self() ! ExitMsg,

{ok, DaemonRef} = ssh:daemon(0, [{system_dir, SysDir},
{user_dir, UserDir}]),
ssh:stop_daemon(DaemonRef),

%% Ensure the EXIT message is still there
receive
ExitMsg -> ok
after 0 ->
ct:fail("No EXIT message")
end.

%%--------------------------------------------------------------------
start_shell_sock_exec_fun(Config) when is_list(Config) ->
PrivDir = proplists:get_value(priv_dir, Config),
Expand Down

0 comments on commit 19be905

Please sign in to comment.