Small refactor on conditional check and add tests

This commit is contained in:
Dan Dunckel 2015-10-12 17:55:48 -07:00
parent 8e87990599
commit 9d87be51da
3 changed files with 23 additions and 1 deletions

View File

@ -81,7 +81,7 @@ module VagrantPlugins
errors << I18n.t("vagrant.provisioners.shell.args_bad_type")
end
if @elevated_interactive == true && @privileged == false
if elevated_interactive && !privileged
errors << I18n.t("vagrant.provisioners.shell.interactive_not_elevated")
end

View File

@ -93,6 +93,15 @@ describe VagrantPlugins::CommunicatorWinRM::Communicator do
expect(subject.execute("dir", { elevated: true })).to eq(0)
end
it "wraps command in elevated and interactive shell script when elevated and interactive are true" do
expect(shell).to receive(:upload).with(kind_of(String), "c:/tmp/vagrant-elevated-shell.ps1")
expect(shell).to receive(:powershell) do |cmd|
expect(cmd).to eq("powershell -executionpolicy bypass -file \"c:/tmp/vagrant-elevated-shell.ps1\" " +
"-username \"vagrant\" -password \"password\" -encoded_command \"ZABpAHIAOwAgAGUAeABpAHQAIAAkAEwAQQBTAFQARQBYAEkAVABDAE8ARABFAA==\"")
end.and_return({ exitcode: 0 })
expect(subject.execute("dir", { elevated: true, interactive: true })).to eq(0)
end
it "can use cmd shell" do
expect(shell).to receive(:cmd).with(kind_of(String)).and_return({ exitcode: 0 })
expect(subject.execute("dir", { shell: :cmd })).to eq(0)

View File

@ -85,6 +85,19 @@ describe "VagrantPlugins::Shell::Config" do
I18n.t("vagrant.provisioners.shell.args_bad_type")
])
end
it "returns an error if elevated_interactive is true but privileged is false" do
subject.path = file_that_exists
subject.elevated_interactive = true
subject.privileged = false
subject.finalize!
result = subject.validate(machine)
expect(result["shell provisioner"]).to eq([
I18n.t("vagrant.provisioners.shell.interactive_not_elevated")
])
end
end
describe 'finalize!' do