(#9622) Use SafeExec for docker-exec

This commit uses the internal helper SafeExec rather than using the
Kernel class directly. It also adds a test to ensure that if the `-t`
option is used, it will call SafeExec.
This commit is contained in:
Brian Cain 2018-05-02 14:20:29 -07:00
parent de71626922
commit 79e535a7ee
No known key found for this signature in database
GPG Key ID: 43D51080D357A001
2 changed files with 34 additions and 11 deletions

View File

@ -1,3 +1,5 @@
require 'vagrant/util/safe_exec'
module VagrantPlugins
module DockerProvider
module Command
@ -86,7 +88,7 @@ module VagrantPlugins
exec_options = options
if options[:pty]
Kernel.system(*exec_cmd)
Vagrant::Util::SafeExec.exec(exec_cmd[0], *exec_cmd[1..-1])
else
output = ""
machine.provider.driver.execute(*exec_cmd, exec_options) do |type, data|

View File

@ -5,14 +5,30 @@ describe VagrantPlugins::DockerProvider::Command::Exec do
include_context "unit"
include_context "command plugin helpers"
let(:sandbox) do
isolated_environment
let(:env) { {
action_runner: action_runner,
machine: machine,
ui: Vagrant::UI::Silent.new,
} }
subject { described_class.new(app, env) }
let(:argv) { [] }
let(:iso_env) do
# We have to create a Vagrantfile so there is a root path
isolated_environment.tap do |env|
env.vagrantfile("")
end
end
let(:argv) { [] }
let(:env) { sandbox.create_vagrant_env }
let(:iso_vagrant_env) { iso_env.create_vagrant_env }
let(:vagrantfile_path) { File.join(env.cwd, "Vagrantfile") }
let(:action_runner) { double("action_runner") }
let(:box) do
box_dir = iso_env.box3("foo", "1.0", :virtualbox)
Vagrant::Box.new("foo", :virtualbox, "1.0", box_dir)
end
let(:machine) { iso_vagrant_env.machine(iso_vagrant_env.machine_names[0], :dummy) }
subject { described_class.new(argv, env) }
@ -23,14 +39,19 @@ describe VagrantPlugins::DockerProvider::Command::Exec do
before do
allow(Vagrant.plugin("2").manager).to receive(:commands).and_return({})
allow(subject).to receive(:exec_command)
end
after do
sandbox.close
end
describe "#exec_command" do
describe "with -t option" do
let(:command) { ["/bin/bash"] }
let(:options) { {pty: "true"} }
describe "#execute" do
it "calls Safe Exec" do
allow(Kernel).to receive(:exec).and_return(true)
expect(Vagrant::Util::SafeExec).to receive(:exec).with("docker", "exec", "-t", anything, "/bin/bash")
subject.exec_command(machine, command, options)
end
end
describe "without a command" do
let(:argv) { [] }