Pass ssh command for port forwarding using array (#1469)

Switch to the command as an array format when passing the port
forwarding ssh command to spawn to switch to execution of the ssh
process directly instead of being executed by the default shell.

Fixes: #1467
This commit is contained in:
Darragh Bailey
2022-03-22 07:09:18 +00:00
committed by GitHub
parent 39084ec86b
commit 55a220f1c8
2 changed files with 22 additions and 13 deletions

View File

@@ -132,7 +132,11 @@ describe VagrantPlugins::ProviderLibvirt::Action::ForwardPorts do
it 'should spawn ssh to setup forwarding' do
expect(env).to receive(:[]).with(:forwarded_ports).and_return([port_options])
expect(ui).to receive(:info).with("#{port_options[:guest]} (guest) => #{port_options[:host]} (host) (adapter eth0)")
expect(subject).to receive(:spawn).with(/ssh -n -o User=vagrant -o Port=22.*-L \*:8080:192.168.1.121:80 -N localhost/, anything).and_return(9999)
expect(subject).to receive(:spawn) do |*args, **kwargs|
pargs = RUBY_VERSION < "2.7" ? args[0...-1] : args
expect(pargs).to start_with('ssh', '-o', 'User=vagrant', '-o', 'Port=22')
expect(pargs).to end_with('-n', '-L', '*:8080:192.168.1.121:80', '-N', 'localhost')
end.and_return(9999)
expect(subject.forward_ports(env)).to eq([port_options])
@@ -148,7 +152,11 @@ describe VagrantPlugins::ProviderLibvirt::Action::ForwardPorts do
expect(ui).to receive(:info).with("#{port_options[:guest]} (guest) => #{port_options[:host]} (host) (adapter eth0)")
expect(ui).to receive(:info).with('Requesting sudo for host port(s) <= 1024')
expect(subject).to receive(:system).with('sudo -v').and_return(true)
expect(subject).to receive(:spawn).with(/sudo ssh -n -o User=vagrant -o Port=22.*-L \*:80:192.168.1.121:80 -N localhost/, anything).and_return(10000)
expect(subject).to receive(:spawn) do |*args, **kwargs|
pargs = RUBY_VERSION < "2.7" ? args[0...-1] : args
expect(pargs).to start_with('sudo', 'ssh', '-o', 'User=vagrant', '-o', 'Port=22')
expect(pargs).to end_with('-n', '-L', '*:80:192.168.1.121:80', '-N', 'localhost')
end.and_return(10000)
expect(subject.forward_ports(env)).to eq([port_options])