From 844cca9013be0ebf8de3d3b3b2cc367e041eb1c5 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Mon, 23 Nov 2015 17:20:02 -0500 Subject: [PATCH] Skip nil IP addresses in ipv6 fix Fixes GH-6558 --- .../virtualbox/action/network_fix_ipv6.rb | 3 +- .../action/network_fix_ipv6_test.rb | 33 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 test/unit/plugins/providers/virtualbox/action/network_fix_ipv6_test.rb diff --git a/plugins/providers/virtualbox/action/network_fix_ipv6.rb b/plugins/providers/virtualbox/action/network_fix_ipv6.rb index eb4ca48ef..b8b12be58 100644 --- a/plugins/providers/virtualbox/action/network_fix_ipv6.rb +++ b/plugins/providers/virtualbox/action/network_fix_ipv6.rb @@ -27,7 +27,8 @@ module VagrantPlugins env[:machine].config.vm.networks.each do |type, options| next if type != :private_network options = scoped_hash_override(options, :virtualbox) - next if options[:ip] == "" + next if options[:ip].to_s.strip == "" + if IPAddr.new(options[:ip]).ipv6? has_v6 = true break diff --git a/test/unit/plugins/providers/virtualbox/action/network_fix_ipv6_test.rb b/test/unit/plugins/providers/virtualbox/action/network_fix_ipv6_test.rb new file mode 100644 index 000000000..d4b985a63 --- /dev/null +++ b/test/unit/plugins/providers/virtualbox/action/network_fix_ipv6_test.rb @@ -0,0 +1,33 @@ +require_relative "../base" + +describe VagrantPlugins::ProviderVirtualBox::Action::NetworkFixIPv6 do + include_context "unit" + include_context "virtualbox" + + let(:iso_env) do + env = isolated_environment + env.vagrantfile("") + env.create_vagrant_env + end + + let(:machine) do + iso_env.machine(iso_env.machine_names[0], :dummy) + end + + let(:env) {{ machine: machine }} + let(:app) { lambda { |*args| }} + + subject { described_class.new(app, env) } + + it "ignores nil IP addresses" do + allow(machine.config.vm).to receive(:networks) + .and_return(private_network: { ip: nil }) + expect { subject.call(env) }.to_not raise_error + end + + it "blank nil IP addresses" do + allow(machine.config.vm).to receive(:networks) + .and_return(private_network: { ip: "" }) + expect { subject.call(env) }.to_not raise_error + end +end