From c9961d64fc42b25883790143b34d93e38c44c849 Mon Sep 17 00:00:00 2001 From: frazze-jobb Date: Tue, 1 Oct 2024 09:27:43 +0200 Subject: [PATCH] ssh: update ssh tests --- lib/ssh/src/ssh_cli.erl | 8 +++++--- lib/ssh/test/ssh_connection_SUITE.erl | 29 +++++++++++++-------------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/lib/ssh/src/ssh_cli.erl b/lib/ssh/src/ssh_cli.erl index 2216cb9ec8e3..f05fda3a7fdc 100644 --- a/lib/ssh/src/ssh_cli.erl +++ b/lib/ssh/src/ssh_cli.erl @@ -67,9 +67,11 @@ %% Description: Initiates the CLI %%-------------------------------------------------------------------- init([Shell, Exec]) -> - {ok, #state{shell = Shell, exec = Exec}}; + TTY = prim_tty:init_ssh(#{input => false}, {80, 24}, utf8), + {ok, #state{shell = Shell, exec = Exec, tty = TTY}}; init([Shell]) -> - {ok, #state{shell = Shell}}. + TTY = prim_tty:init_ssh(#{input => false}, {80, 24}, utf8), + {ok, #state{shell = Shell, tty = TTY}}. %%-------------------------------------------------------------------- %% Function: handle_ssh_msg(Args) -> {ok, State} | {stop, ChannelId, State} @@ -95,7 +97,7 @@ handle_ssh_msg({ssh_cm, ConnectionHandler, pixel_width = PixWidth, pixel_height = PixHeight, modes = Modes}}, - TTY = prim_tty:init_ssh(#{input => false, output => false}, {not_zero(Width, 80), not_zero(Height, 24)}, State#state.encoding), + TTY = prim_tty:init_ssh(#{input => false}, {not_zero(Width, 80), not_zero(Height, 24)}, State#state.encoding), set_echo(State), ssh_connection:reply_request(ConnectionHandler, WantReply, success, ChannelId), diff --git a/lib/ssh/test/ssh_connection_SUITE.erl b/lib/ssh/test/ssh_connection_SUITE.erl index 11e6f95964c4..3d0bd22bc1c9 100644 --- a/lib/ssh/test/ssh_connection_SUITE.erl +++ b/lib/ssh/test/ssh_connection_SUITE.erl @@ -814,12 +814,11 @@ new_shell_xterm_term(Config) when is_list(Config) -> exp_output => [<<"Enter command\r\n">>, <<"1> ">>, - <<"one_atom_please.\r\n\e[1022D\e[1B">>, + <<"one_atom_please.\r\n">>, <<"{simple_eval,one_atom_please}\r\n">>, <<"2> ">>, - <<"\e[3D\e[J">>, <<"\e[;1;4msearch:\e[0m ">>, - <<"\r\n one_atom_please.">>]}, + <<"\b\b\b\b\b\b\b\b\e[J\e[;1;4msearch:\e[0m \r\n one_atom_please.\e[A\b\b\b\b\b\b\b\b\b\b">>]}, Config). new_shell_helper(#{term := Term, cmds := Cmds, @@ -994,7 +993,7 @@ start_shell_exec_fun(Config) -> io:format("echo ~s\n", [Cmd]) end) end, - "testing", <<"echo testing\n">>, 0, + "testing", <<"echo testing\r\n">>, 0, Config). start_shell_exec_fun2(Config) -> @@ -1003,7 +1002,7 @@ start_shell_exec_fun2(Config) -> io:format("echo ~s ~s\n",[User,Cmd]) end) end, - "testing", <<"echo foo testing\n">>, 0, + "testing", <<"echo foo testing\r\n">>, 0, Config). start_shell_exec_fun3(Config) -> @@ -1012,7 +1011,7 @@ start_shell_exec_fun3(Config) -> io:format("echo ~s ~s\n",[User,Cmd]) end) end, - "testing", <<"echo foo testing\n">>, 0, + "testing", <<"echo foo testing\r\n">>, 0, Config). start_shell_exec_direct_fun(Config) -> @@ -1077,11 +1076,11 @@ start_exec_direct_fun1_read_write(Config) -> {ok, Ch} = ssh_connection:session_channel(C, infinity), success = ssh_connection:exec(C, Ch, "> ", infinity), - ssh_test_lib:receive_exec_result_or_fail({ssh_cm,C,{data,Ch,0,<<"Tiny read/write test\n">>}}), + ssh_test_lib:receive_exec_result_or_fail({ssh_cm,C,{data,Ch,0,<<"Tiny read/write test\r\n">>}}), ssh_test_lib:receive_exec_result_or_fail({ssh_cm,C,{data,Ch,0,<<"1> ">>}}), ok = ssh_connection:send(C, Ch, "hej.\n", 5000), - ssh_test_lib:receive_exec_result_or_fail({ssh_cm,C,{data,Ch,0,<<"{simple_eval,hej}\n">>}}), + ssh_test_lib:receive_exec_result_or_fail({ssh_cm,C,{data,Ch,0,<<"{simple_eval,hej}\r\n">>}}), ssh_test_lib:receive_exec_result_or_fail({ssh_cm,C,{data,Ch,0,<<"2> ">>}}), ok = ssh_connection:send(C, Ch, "quit.\n", 5000), @@ -1125,18 +1124,18 @@ start_exec_direct_fun1_read_write_advanced(Config) -> {ok, Ch} = ssh_connection:session_channel(C, infinity), success = ssh_connection:exec(C, Ch, "> ", infinity), - ssh_test_lib:receive_exec_result_or_fail({ssh_cm,C,{data,Ch,0,<<"Tiny read/write test\n">>}}), + ssh_test_lib:receive_exec_result_or_fail({ssh_cm,C,{data,Ch,0,<<"Tiny read/write test\r\n">>}}), ssh_test_lib:receive_exec_result_or_fail({ssh_cm,C,{data,Ch,0,<<"1> ">>}}), ok = ssh_connection:send(C, Ch, "hej.\n", 5000), - ssh_test_lib:receive_exec_result_or_fail({ssh_cm,C,{data,Ch,0,<<"{simple_eval,hej}\n">>}}), + ssh_test_lib:receive_exec_result_or_fail({ssh_cm,C,{data,Ch,0,<<"{simple_eval,hej}\r\n">>}}), ssh_test_lib:receive_exec_result_or_fail({ssh_cm,C,{data,Ch,0,<<"2> ">>}}), ok = ssh_connection:send(C, Ch, "'Hi ", 5000), ok = ssh_connection:send(C, Ch, "there", 5000), ok = ssh_connection:send(C, Ch, "'", 5000), ok = ssh_connection:send(C, Ch, ".\n", 5000), - ssh_test_lib:receive_exec_result_or_fail({ssh_cm,C,{data,Ch,0,<<"{simple_eval,'Hi there'}\n">>}}), + ssh_test_lib:receive_exec_result_or_fail({ssh_cm,C,{data,Ch,0,<<"{simple_eval,'Hi there'}\r\n">>}}), ssh_test_lib:receive_exec_result_or_fail({ssh_cm,C,{data,Ch,0,<<"3> ">>}}), ok = ssh_connection:send(C, Ch, "bad_input.\n", 5000), ssh_test_lib:receive_exec_result_or_fail({ssh_cm,C,{data,Ch,1,<<"**Error** {bad_input,3}">>}}), @@ -1251,7 +1250,7 @@ start_shell_sock_exec_fun(Config) when is_list(Config) -> "testing", infinity), receive - {ssh_cm, ConnectionRef, {data, _ChannelId, 0, <<"echo testing\n">>}} -> + {ssh_cm, ConnectionRef, {data, _ChannelId, 0, <<"echo testing\r\n">>}} -> ok after 5000 -> ct:fail("Exec Timeout") @@ -1296,7 +1295,7 @@ start_shell_sock_daemon_exec(Config) -> "testing", infinity), receive - {ssh_cm, ConnectionRef, {data, _ChannelId, 0, <<"echo testing\n">>}} -> + {ssh_cm, ConnectionRef, {data, _ChannelId, 0, <<"echo testing\r\n">>}} -> ok after 5000 -> ct:fail("Exec Timeout") @@ -1356,7 +1355,7 @@ start_shell_sock_daemon_exec_multi(Config) -> success = ssh_connection:exec(ConnectionRef, ChannelId0, "testing", infinity), ct:log("~p:~p: exec on connection ~p", [?MODULE,?LINE,ConnectionRef]), receive - {ssh_cm, ConnectionRef, {data, _ChannelId, 0, <<"echo testing\n">>}} -> + {ssh_cm, ConnectionRef, {data, _ChannelId, 0, <<"echo testing\r\n">>}} -> Parent ! {answer_received,self()}, ct:log("~p:~p: received result on connection ~p", [?MODULE,?LINE,ConnectionRef]) after 5000 -> @@ -1790,7 +1789,7 @@ do_simple_exec(ConnectionRef, N) -> Cmd = "yes testing | head -n " ++ integer_to_list(N), ct:log("Cmd to be invoked over SSH shell: ~p", [Cmd]), success = ssh_connection:exec(ConnectionRef, ChannelId0, Cmd, infinity), - ExpectedBin = <<"testing\n">>, + ExpectedBin = <<"testing\r\n">>, case N of 1 -> %% receive response to input