From 139a65e555c9d2cb22f1ea099e39bd9285293c3d Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Mon, 31 Jul 2017 15:44:37 -0700 Subject: [PATCH] Format host address for rsync when IPv6 --- plugins/synced_folders/rsync/helper.rb | 10 +++++++++ .../synced_folders/rsync/helper_test.rb | 22 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/plugins/synced_folders/rsync/helper.rb b/plugins/synced_folders/rsync/helper.rb index 1a25f27a6..d39e233b2 100644 --- a/plugins/synced_folders/rsync/helper.rb +++ b/plugins/synced_folders/rsync/helper.rb @@ -1,3 +1,4 @@ +require "ipaddr" require "shellwords" require "vagrant/util/platform" @@ -147,6 +148,15 @@ module VagrantPlugins args << "--rsync-path"<< rsync_path end + # If the remote host is an IPv6 address reformat + begin + if IPAddr.new(host).ipv6? + host = "[#{host}]" + end + rescue IPAddr::Error + # Ignore + end + # Build up the actual command to execute command = [ "rsync", diff --git a/test/unit/plugins/synced_folders/rsync/helper_test.rb b/test/unit/plugins/synced_folders/rsync/helper_test.rb index 4640b5977..77c11f8eb 100644 --- a/test/unit/plugins/synced_folders/rsync/helper_test.rb +++ b/test/unit/plugins/synced_folders/rsync/helper_test.rb @@ -233,6 +233,28 @@ describe VagrantPlugins::SyncedFolderRSync::RsyncHelper do guest.stub(capability?: false) end + context "with an IPv6 address" do + before { ssh_info[:host] = "fe00::0" } + + it "formats the address correctly" do + expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(args[13]).to include("@[#{ssh_info[:host]}]") + } + subject.rsync_single(machine, ssh_info, opts) + end + end + + context "with an IPv4 address" do + before { ssh_info[:host] = "127.0.0.1" } + + it "formats the address correctly" do + expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args| + expect(args[13]).to include("@#{ssh_info[:host]}") + } + subject.rsync_single(machine, ssh_info, opts) + end + end + it "includes IdentitiesOnly, StrictHostKeyChecking, and UserKnownHostsFile with defaults" do expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|