winssh communicator: retain the authorized_keys file acl permissions

This commit is contained in:
Rui Lopes 2017-07-18 09:40:56 +01:00 committed by Chris Roberts
parent aeac480683
commit 4ab0dc19b1
3 changed files with 6 additions and 0 deletions

View File

@ -50,6 +50,7 @@ module VagrantPlugins
end
comm.upload(keys_file.path, remote_upload_path)
keys_file.delete
comm.execute("Set-Acl \"#{remote_upload_path}\" (Get-Acl \"#{remote_authkeys_path}\")", shell: "powershell")
comm.execute("move /y \"#{remote_upload_path}\" \"#{remote_authkeys_path}\"", shell: "cmd")
end
@ -75,6 +76,7 @@ module VagrantPlugins
File.write(keys_file.path, current_content.join("\r\n") + "\r\n")
comm.upload(keys_file.path, remote_upload_path)
keys_file.delete
comm.execute("Set-Acl \"#{remote_upload_path}\" (Get-Acl \"#{remote_authkeys_path}\")", shell: "powershell")
comm.execute("move /y \"#{remote_upload_path}\" \"#{remote_authkeys_path}\"", shell: "cmd")
end
end

View File

@ -41,6 +41,7 @@ describe "VagrantPlugins::GuestWindows::Cap::InsertPublicKey" do
it "inserts the public key" do
expect(comm).to receive(:download)
expect(comm).to receive(:upload)
expect(comm).to receive(:execute).with(/Set-Acl .*/, shell: "powershell")
expect(comm).to receive(:execute).with(/move .*/, shell: "cmd")
cap.insert_public_key(machine, "ssh-rsa ...")
expect(File.read(@tempfile.path)).to include("ssh-rsa ...")
@ -56,6 +57,7 @@ describe "VagrantPlugins::GuestWindows::Cap::InsertPublicKey" do
it "inserts the public key" do
expect(comm).to_not receive(:download)
expect(comm).to receive(:upload)
expect(comm).to receive(:execute).with(/Set-Acl .*/, shell: "powershell")
expect(comm).to receive(:execute).with(/move .*/, shell: "cmd")
cap.insert_public_key(machine, "ssh-rsa ...")
expect(File.read(@tempfile.path)).to include("ssh-rsa ...")

View File

@ -47,6 +47,7 @@ describe "VagrantPlugins::GuestWindows::Cap::RemovePublicKey" do
it "removes the public key" do
expect(comm).to receive(:download)
expect(comm).to receive(:upload)
expect(comm).to receive(:execute).with(/Set-Acl .*/, shell: "powershell")
expect(comm).to receive(:execute).with(/move .*/, shell: "cmd")
cap.remove_public_key(machine, public_key_insecure)
expect(File.read(@tempfile.path)).to include(public_key_other)
@ -58,6 +59,7 @@ describe "VagrantPlugins::GuestWindows::Cap::RemovePublicKey" do
it "does nothing" do
expect(comm).to_not receive(:download)
expect(comm).to_not receive(:upload)
expect(comm).to_not receive(:execute).with(/Set-Acl .*/, shell: "powershell")
expect(comm).to_not receive(:execute).with(/move .*/, shell: "cmd")
cap.remove_public_key(machine, public_key_insecure)
end