From ec9d23a531649634dad3ac304d905c6e20fb1f98 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Wed, 4 Mar 2020 15:07:32 -0800 Subject: [PATCH] Update public key cap to use powershell --- plugins/guests/windows/cap/public_key.rb | 4 ++-- .../unit/plugins/guests/windows/cap/insert_public_key_test.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/guests/windows/cap/public_key.rb b/plugins/guests/windows/cap/public_key.rb index 1dbb67151..7ac2a1980 100644 --- a/plugins/guests/windows/cap/public_key.rb +++ b/plugins/guests/windows/cap/public_key.rb @@ -37,7 +37,7 @@ module VagrantPlugins # Ensure the user's ssh directory exists remote_ssh_dir = "#{home_dir}\\.ssh" - comm.create_remote_directory(remote_ssh_dir) + comm.execute("New-Item -Path '#{remote_ssh_dir}' -ItemType directory -Force", shell: "powershell") remote_upload_path = "#{temp_dir}\\vagrant-insert-pubkey-#{Time.now.to_i}" remote_authkeys_path = "#{remote_ssh_dir}\\authorized_keys" @@ -67,7 +67,7 @@ module VagrantPlugins # @return [Hash] {:temp, :home} def self.fetch_guest_paths(communicator) output = "" - communicator.execute("echo %TEMP%\necho %USERPROFILE%", shell: "cmd") do |type, data| + communicator.execute("Write-Output $env:TEMP\nWrite-Output $env:USERPROFILE", shell: "powershell") do |type, data| if type == :stdout output << data end diff --git a/test/unit/plugins/guests/windows/cap/insert_public_key_test.rb b/test/unit/plugins/guests/windows/cap/insert_public_key_test.rb index 071d323b5..7a636f55d 100644 --- a/test/unit/plugins/guests/windows/cap/insert_public_key_test.rb +++ b/test/unit/plugins/guests/windows/cap/insert_public_key_test.rb @@ -19,7 +19,7 @@ describe "VagrantPlugins::GuestWindows::Cap::InsertPublicKey" do allow(comm).to receive(:is_a?).and_return(true) allow(machine).to receive(:communicate).and_return(comm) - allow(comm).to receive(:execute).with(/echo .+/, shell: "cmd").and_yield(:stdout, "TEMP\r\nHOME\r\n") + allow(comm).to receive(:execute).with(/Write .+/, shell: "powershell").and_yield(:stdout, "TEMP\r\nHOME\r\n") allow(comm).to receive(:execute).with(/dir .+\.ssh/, shell: "cmd") allow(comm).to receive(:execute).with(/dir .+authorized_keys/, shell: "cmd", error_check: false).and_return(auth_keys_check_result) allow(comm).to receive(:create_remote_directory) @@ -65,7 +65,7 @@ describe "VagrantPlugins::GuestWindows::Cap::InsertPublicKey" do context "when required directories cannot be fetched from the guest" do before do - expect(comm).to receive(:execute).with(/echo .+/, shell: "cmd").and_yield(:stdout, "TEMP\r\n") + expect(comm).to receive(:execute).with(/Write .+/, shell: "powershell").and_yield(:stdout, "TEMP\r\n") end it "should raise an error" do