diff --git a/plugins/communicators/winssh/communicator.rb b/plugins/communicators/winssh/communicator.rb index fb82a4a80..208ec0f90 100644 --- a/plugins/communicators/winssh/communicator.rb +++ b/plugins/communicators/winssh/communicator.rb @@ -48,28 +48,27 @@ module VagrantPlugins remote_name = "#{machine_config_ssh.upload_directory}/#{File.basename(tfile.path)}.#{remote_ext}" if shell == "powershell" - base_cmd = "powershell -File #{remote_name}" tfile.puts <<-SCRIPT.force_encoding('ASCII-8BIT') Remove-Item #{remote_name} Write-Host #{CMD_GARBAGE_MARKER} [Console]::Error.WriteLine("#{CMD_GARBAGE_MARKER}") #{command} SCRIPT + base_cmd = "powershell -file #{remote_name}" else - base_cmd = remote_name tfile.puts <<-SCRIPT.force_encoding('ASCII-8BIT') +DEL #{remote_name} ECHO OFF ECHO #{CMD_GARBAGE_MARKER} ECHO #{CMD_GARBAGE_MARKER} 1>&2 #{command} SCRIPT + base_cmd = "cmd /q /c #{remote_name}" end tfile.close upload(tfile.path, remote_name) tfile.delete - - base_cmd = shell_cmd(opts.merge(shell: base_cmd)) end @logger.debug("Base SSH exec command: #{base_cmd}") diff --git a/plugins/provisioners/shell/provisioner.rb b/plugins/provisioners/shell/provisioner.rb index a86a43a42..34bc49448 100644 --- a/plugins/provisioners/shell/provisioner.rb +++ b/plugins/provisioners/shell/provisioner.rb @@ -194,19 +194,20 @@ module VagrantPlugins @machine.communicate.tap do |comm| # Make sure that the upload path has an extension, since # having an extension is critical for Windows execution - if File.extname(upload_path) == "" - upload_path += File.extname(path.to_s) + winrm_upload_path = upload_path + if File.extname(winrm_upload_path) == "" + winrm_upload_path += File.extname(path.to_s) end # Upload it - comm.upload(path.to_s, upload_path) + comm.upload(path.to_s, winrm_upload_path) # Build the environment env = config.env.map { |k,v| "$env:#{k} = #{quote_and_escape(v.to_s)}" } env = env.join("; ") # Calculate the path that we'll be executing - exec_path = upload_path + exec_path = winrm_upload_path exec_path.gsub!('/', '\\') exec_path = "c:#{exec_path}" if exec_path.start_with?("\\") diff --git a/test/unit/plugins/provisioners/shell/provisioner_test.rb b/test/unit/plugins/provisioners/shell/provisioner_test.rb index c3b566df3..dd83c42e4 100644 --- a/test/unit/plugins/provisioners/shell/provisioner_test.rb +++ b/test/unit/plugins/provisioners/shell/provisioner_test.rb @@ -416,4 +416,52 @@ describe "Vagrant::Shell::Provisioner" do end end end + + describe "#provision_winrm" do + let(:config) { + double( + :config, + :args => "doesn't matter", + :env => {}, + :upload_path => "arbitrary", + :remote? => false, + :path => "script/info.ps1", + :binary => false, + :md5 => nil, + :sha1 => 'EXPECTED_VALUE', + :sha256 => nil, + :sha384 => nil, + :sha512 => nil, + :reset => false, + :reboot => false, + :powershell_args => "", + :name => nil, + :privileged => false, + :powershell_elevated_interactive => false + ) + } + + let(:vsp) { + VagrantPlugins::Shell::Provisioner.new(machine, config) + } + + let(:communicator) { double("communicator") } + let(:guest) { double("guest") } + let(:ui) { double("ui") } + + before { + allow(guest).to receive(:capability?).with(:wait_for_reboot).and_return(false) + allow(ui).to receive(:detail) + allow(communicator).to receive(:sudo) + allow(machine).to receive(:communicate).and_return(communicator) + allow(machine).to receive(:guest).and_return(guest) + allow(machine).to receive(:ui).and_return(ui) + allow(vsp).to receive(:with_script_file).and_yield(config.path) + } + + it "ensures that files are uploaded with an extension" do + expect(communicator).to receive(:upload).with(config.path, /arbitrary.ps1$/) + vsp.send(:provision_winrm, "") + end + end end diff --git a/test/unit/vagrant/util/platform_test.rb b/test/unit/vagrant/util/platform_test.rb index 6b71329e9..9e0506614 100644 --- a/test/unit/vagrant/util/platform_test.rb +++ b/test/unit/vagrant/util/platform_test.rb @@ -533,11 +533,11 @@ EOF expect(subject.wsl_drvfs_path?("/home/vagrant/some/path")).to be_falsey end end + end - describe ".unix_windows_path" do - it "takes a windows path and returns a unixy path" do - expect(subject.unix_windows_path("C:\\Temp\\Windows")).to eq("C:/Temp/Windows") - end + describe ".unix_windows_path" do + it "takes a windows path and returns a POSIX-like path" do + expect(subject.unix_windows_path("C:\\Temp\\Windows")).to eq("C:/Temp/Windows") end end end