diff options
-rw-r--r-- | lib/net/ssh/connection/channel.rb | 1 | ||||
-rw-r--r-- | lib/net/ssh/version.rb | 2 | ||||
-rw-r--r-- | test/integration/common.rb | 51 | ||||
-rw-r--r-- | test/integration/playbook.yml | 3 | ||||
-rw-r--r-- | test/integration/test_channel.rb | 10 |
5 files changed, 50 insertions, 17 deletions
diff --git a/lib/net/ssh/connection/channel.rb b/lib/net/ssh/connection/channel.rb index 7bfee72..9a408b2 100644 --- a/lib/net/ssh/connection/channel.rb +++ b/lib/net/ssh/connection/channel.rb @@ -683,6 +683,7 @@ module Net # # channel.set_remote_env foo: 'bar', baz: 'whale' def set_remote_env(env) + env.each { |key, value| puts "E:#{key} V:#{value}" } env.each { |key, value| self.env(key, value) } end end diff --git a/lib/net/ssh/version.rb b/lib/net/ssh/version.rb index cee010a..54cadee 100644 --- a/lib/net/ssh/version.rb +++ b/lib/net/ssh/version.rb @@ -56,7 +56,7 @@ module Net # The prerelease component of this version of the Net::SSH library # nil allowed - PRE = "rc1" + PRE = "rc2" # The current version of the Net::SSH library as a Version instance CURRENT = new(*[MAJOR, MINOR, TINY, PRE].compact) diff --git a/test/integration/common.rb b/test/integration/common.rb index 8fe0881..e9d2546 100644 --- a/test/integration/common.rb +++ b/test/integration/common.rb @@ -84,39 +84,68 @@ module IntegrationTestHelpers end end - def with_lines_as_tempfile(lines = [], &block) + def with_lines_as_tempfile(lines = [], add_pid = true, &block) Tempfile.open('sshd_config') do |f| f.write(lines) + pidpath = nil + if add_pid + pidpath = f.path + '.pid' + f.write("\nPIDFILE #{pidpath}") + end + # f.write("\nLogLevel DEBUG3") f.close - yield(f.path) + yield(f.path, pidpath) end end + def port_open?(path) + Socket.tcp("localhost", 10567, connect_timeout: 1) { true } rescue false # rubocop:disable Style/RescueModifier + end + # @yield [pid, port] def start_sshd_7_or_later(port = '2200', config: nil) pid = nil + sshpidfile = nil if config - with_lines_as_tempfile(config) do |path| - pid = spawn('sudo', '/opt/net-ssh-openssh/sbin/sshd', '-D', '-f', path, '-p', port) + with_lines_as_tempfile(config) do |path, pidpath| + # puts "DEBUG - SSH LOG: #{path}-log.txt" + raise "A leftover sshd is already running" if is_port_open?(port) + pid = spawn('sudo', '/opt/net-ssh-openssh/sbin/sshd', '-D', '-f', path, '-p', port) # '-E', "#{path}-log.txt") + sshpidfile = pidpath yield pid, port end else - pid = spawn('sudo', '/opt/net-ssh-openssh/sbin/sshd', '-D', '-p', port) - yield pid, port + with_lines_as_tempfile('') do |path, pidpath| + pid = spawn('sudo', '/opt/net-ssh-openssh/sbin/sshd', '-D', '-f', path, '-p', port) + sshpidfile = pidpath + yield pid, port + end end ensure - # Our pid is sudo, -9 (KILL) on sudo will not clean up its children + # Our pid is sudo and not sshd, -9 (KILL) on sudo will not clean up its children # properly, so we just have to hope that -15 (TERM) will manage to bring # down sshd. - if pid + if sshpidfile + sshpid = File.read(sshpidfile).strip + system('sudo', 'kill', '-15', sshpid.to_s) + begin + Timeout.timeout(20) do + Process.wait(pid) + end + rescue Timeout::Error + warn "Failed to kill openssh process: #{sshpid}" + system('sudo', 'kill', '-9', sshpid.to_s) + raise + end + elsif pid system('sudo', 'kill', '-15', pid.to_s) begin - Timeout.timeout(5) do + Timeout.timeout(20) do Process.wait(pid) end rescue Timeout::Error - warn "Failed to kill net-ssh process: #{pid}" - system('sudo', 'kill', '-9', pid) + warn "Failed to kill openssh process: #{pid}" + system('sudo', 'kill', '-9', pid.to_s) raise end end diff --git a/test/integration/playbook.yml b/test/integration/playbook.yml index ae9b96c..3013c1f 100644 --- a/test/integration/playbook.yml +++ b/test/integration/playbook.yml @@ -85,6 +85,9 @@ - name: sshd allow forward lineinfile: dest='/etc/ssh/sshd_config' line='GatewayPorts yes' regexp=LogLevel notify: restart sshd + - name: sshd allow forward + lineinfile: dest='/etc/ssh/sshd_config' line='PasswordAuthentication=yes' regexp=PasswordAuthentication + notify: restart sshd - name: put NET_SSH_RUN_INTEGRATION_TESTS=YES environment lineinfile: dest='/etc/environment' line='NET_SSH_RUN_INTEGRATION_TESTS=YES' - name: change dir in bashrc diff --git a/test/integration/test_channel.rb b/test/integration/test_channel.rb index d07e0a1..abd2902 100644 --- a/test/integration/test_channel.rb +++ b/test/integration/test_channel.rb @@ -107,8 +107,8 @@ class TestChannel < NetSSHTest def test_channel_should_set_environment_variables_on_remote setup_ssh_env do - start_sshd_7_or_later(config: 'AcceptEnv *') do |_pid, port| - Timeout.timeout(4) do + start_sshd_7_or_later(config: 'AcceptEnv foo baz') do |_pid, port| + Timeout.timeout(20) do begin # We have our own sshd, give it a chance to come up before # listening. @@ -119,15 +119,15 @@ class TestChannel < NetSSHTest sleep(0.1) system("killall /bin/nc") end - channel = ssh_exec(ssh, "echo $foo; echo $baz", channel_success_handler) do |ch, _type, data| + channel = ssh_exec(ssh, "echo A:$foo; echo B:$baz", channel_success_handler) do |ch, _type, data| ch[:result] ||= "" ch[:result] << data end channel.wait res = channel[:result] - assert_equal(res, "bar\nwhale will\n") + assert_equal(res, "A:bar\nB:whale will\n") end - assert_equal(res, "bar\nwhale will\n") + assert_equal(res, "A:bar\nB:whale will\n") rescue SocketError, Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Net::SSH::Proxy::ConnectError sleep 0.25 retry |