Merge pull request #10571 from chrisroberts/fix/ssh-garbage-detection
Fix garbage detection within SSH communicator
This commit is contained in:
commit
abbb5f5ed5
|
@ -573,14 +573,14 @@ module VagrantPlugins
|
||||||
stderr_data_buffer << data
|
stderr_data_buffer << data
|
||||||
marker_index = stderr_data_buffer.index(CMD_GARBAGE_MARKER)
|
marker_index = stderr_data_buffer.index(CMD_GARBAGE_MARKER)
|
||||||
if marker_index
|
if marker_index
|
||||||
marker_found = true
|
stderr_marker_found = true
|
||||||
stderr_data_buffer.slice!(0, marker_index + CMD_GARBAGE_MARKER.size)
|
stderr_data_buffer.slice!(0, marker_index + CMD_GARBAGE_MARKER.size)
|
||||||
data.replace(stderr_data_buffer)
|
data.replace(stderr_data_buffer)
|
||||||
data_buffer = nil
|
stderr_data_buffer = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if block_given? && marker_found && !data.empty?
|
if block_given? && stderr_marker_found && !data.empty?
|
||||||
yield :stderr, data
|
yield :stderr, data
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -321,6 +321,7 @@ describe VagrantPlugins::CommunicatorSSH::Communicator do
|
||||||
let(:command_stdout_data) do
|
let(:command_stdout_data) do
|
||||||
"Line of garbage\nMore garbage\n#{command_garbage_marker}bin\ntmp\n"
|
"Line of garbage\nMore garbage\n#{command_garbage_marker}bin\ntmp\n"
|
||||||
end
|
end
|
||||||
|
let(:command_stderr_data) { "some data" }
|
||||||
|
|
||||||
it "removes any garbage output prepended to command output" do
|
it "removes any garbage output prepended to command output" do
|
||||||
stdout = ''
|
stdout = ''
|
||||||
|
@ -333,12 +334,23 @@ describe VagrantPlugins::CommunicatorSSH::Communicator do
|
||||||
).to eq(0)
|
).to eq(0)
|
||||||
expect(stdout).to eq("bin\ntmp\n")
|
expect(stdout).to eq("bin\ntmp\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should not receive any stderr data" do
|
||||||
|
stderr = ''
|
||||||
|
communicator.execute("ls /") do |type, data|
|
||||||
|
if type == :stderr
|
||||||
|
stderr << data
|
||||||
|
end
|
||||||
|
end
|
||||||
|
expect(stderr).to be_empty
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with no command output" do
|
context "with no command output" do
|
||||||
let(:command_stdout_data) do
|
let(:command_stdout_data) do
|
||||||
"#{command_garbage_marker}"
|
"#{command_garbage_marker}"
|
||||||
end
|
end
|
||||||
|
let(:command_stderr_data) { "some data" }
|
||||||
|
|
||||||
it "does not send empty stdout data string" do
|
it "does not send empty stdout data string" do
|
||||||
empty = true
|
empty = true
|
||||||
|
@ -351,12 +363,23 @@ describe VagrantPlugins::CommunicatorSSH::Communicator do
|
||||||
).to eq(0)
|
).to eq(0)
|
||||||
expect(empty).to be(true)
|
expect(empty).to be(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should not receive any stderr data" do
|
||||||
|
stderr = ''
|
||||||
|
communicator.execute("ls /") do |type, data|
|
||||||
|
if type == :stderr
|
||||||
|
stderr << data
|
||||||
|
end
|
||||||
|
end
|
||||||
|
expect(stderr).to be_empty
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with garbage content prepended to command stderr output" do
|
context "with garbage content prepended to command stderr output" do
|
||||||
let(:command_stderr_data) do
|
let(:command_stderr_data) do
|
||||||
"Line of garbage\nMore garbage\n#{command_garbage_marker}bin\ntmp\n"
|
"Line of garbage\nMore garbage\n#{command_garbage_marker}bin\ntmp\n"
|
||||||
end
|
end
|
||||||
|
let(:command_stdout_data) { "some data" }
|
||||||
|
|
||||||
it "removes any garbage output prepended to command stderr output" do
|
it "removes any garbage output prepended to command stderr output" do
|
||||||
stderr = ''
|
stderr = ''
|
||||||
|
@ -369,12 +392,23 @@ describe VagrantPlugins::CommunicatorSSH::Communicator do
|
||||||
).to eq(0)
|
).to eq(0)
|
||||||
expect(stderr).to eq("bin\ntmp\n")
|
expect(stderr).to eq("bin\ntmp\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should not receive any stdout data" do
|
||||||
|
stdout = ''
|
||||||
|
communicator.execute("ls /") do |type, data|
|
||||||
|
if type == :stdout
|
||||||
|
stdout << data
|
||||||
|
end
|
||||||
|
end
|
||||||
|
expect(stdout).to be_empty
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with no command output on stderr" do
|
context "with no command output on stderr" do
|
||||||
let(:command_stderr_data) do
|
let(:command_stderr_data) do
|
||||||
"#{command_garbage_marker}"
|
"#{command_garbage_marker}"
|
||||||
end
|
end
|
||||||
|
let(:command_std_data) { "some data" }
|
||||||
|
|
||||||
it "does not send empty stderr data string" do
|
it "does not send empty stderr data string" do
|
||||||
empty = true
|
empty = true
|
||||||
|
@ -387,6 +421,16 @@ describe VagrantPlugins::CommunicatorSSH::Communicator do
|
||||||
).to eq(0)
|
).to eq(0)
|
||||||
expect(empty).to be(true)
|
expect(empty).to be(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should not receive any stdout data" do
|
||||||
|
stdout = ''
|
||||||
|
communicator.execute("ls /") do |type, data|
|
||||||
|
if type == :stdout
|
||||||
|
stdout << data
|
||||||
|
end
|
||||||
|
end
|
||||||
|
expect(stdout).to be_empty
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with pty enabled" do
|
context "with pty enabled" do
|
||||||
|
|
Loading…
Reference in New Issue