From 754c1eebe59d229dfaa03090aa934b1a114a10be Mon Sep 17 00:00:00 2001 From: Torsten Juergeleit Date: Sat, 11 Jun 2016 16:40:25 +0200 Subject: [PATCH] fixes #6220 - adds check for communicator type and executes the mount script as encoded command via powershell from within 'sh' for communicator != winrm --- .../guests/windows/cap/mount_shared_folder.rb | 14 ++++++++++- .../windows/cap/mount_shared_folder_test.rb | 23 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/plugins/guests/windows/cap/mount_shared_folder.rb b/plugins/guests/windows/cap/mount_shared_folder.rb index 4329025f6..9e9f403b9 100644 --- a/plugins/guests/windows/cap/mount_shared_folder.rb +++ b/plugins/guests/windows/cap/mount_shared_folder.rb @@ -1,4 +1,5 @@ require "vagrant/util/template_renderer" +require "base64" module VagrantPlugins module GuestWindows @@ -33,7 +34,18 @@ module VagrantPlugins vm_provider_unc_path: vm_provider_unc_base + name, }) - machine.communicate.execute(script, shell: :powershell) + if machine.config.vm.communicator == :winrm + machine.communicate.execute(script, shell: :powershell) + else + # Convert script to double byte unicode string then base64 encode + # just like PowerShell -EncodedCommand expects. + # Suppress the progress stream from leaking to stderr. + wrapped_encoded_command = Base64.strict_encode64( + "$ProgressPreference='SilentlyContinue'; #{script}; exit $LASTEXITCODE".encode('UTF-16LE', 'UTF-8')) + # Execute encoded PowerShell script via OpenSSH shell + machine.communicate.execute("powershell.exe -noprofile -executionpolicy bypass " + + "-encodedcommand '#{wrapped_encoded_command}'", shell: "sh") + end end end end diff --git a/test/unit/plugins/guests/windows/cap/mount_shared_folder_test.rb b/test/unit/plugins/guests/windows/cap/mount_shared_folder_test.rb index 851c71da7..ccec7932e 100644 --- a/test/unit/plugins/guests/windows/cap/mount_shared_folder_test.rb +++ b/test/unit/plugins/guests/windows/cap/mount_shared_folder_test.rb @@ -6,10 +6,15 @@ describe "VagrantPlugins::GuestWindows::Cap::MountSharedFolder" do let(:machine) { double("machine") } let(:communicator) { double(:execute) } + let(:config) { double("config") } + let(:vm) { double("vm") } before do allow(machine).to receive(:communicate).and_return(communicator) allow(communicator).to receive(:execute) + allow(machine).to receive(:config).and_return(config) + allow(config).to receive(:vm).and_return(vm) + allow(vm).to receive(:communicator).and_return(:winrm) end describe "virtualbox" do @@ -98,4 +103,22 @@ describe "VagrantPlugins::GuestWindows::Cap::MountSharedFolder" do end end + describe "virtualbox-ssh" do + + let(:described_class) do + VagrantPlugins::GuestWindows::Plugin.components.guest_capabilities[:windows].get(:mount_virtualbox_shared_folder) + end + + before do + allow(vm).to receive(:communicator).and_return(:ssh) + end + + describe ".mount_shared_folder" do + it "should call mount_volume script via ssh" do + expect(communicator).to receive(:execute).with(/powershell/, shell: "sh") + described_class.mount_virtualbox_shared_folder(machine, 'name', 'guestpath', {}) + end + end + end + end