diff --git a/lib/vagrant/action/builtin/box_add.rb b/lib/vagrant/action/builtin/box_add.rb index 677be66d4..ce1130091 100644 --- a/lib/vagrant/action/builtin/box_add.rb +++ b/lib/vagrant/action/builtin/box_add.rb @@ -53,7 +53,7 @@ module Vagrant next if url[i] !~ /^[^\/]+\/[^\/]+$/ if !File.file?(url[i]) - server = Vagrant.server_url + server = Vagrant.server_url env[:box_server_url] raise Errors::BoxServerNotSet if !server expanded = true diff --git a/lib/vagrant/shared_helpers.rb b/lib/vagrant/shared_helpers.rb index 6288af43a..a93dbbe8a 100644 --- a/lib/vagrant/shared_helpers.rb +++ b/lib/vagrant/shared_helpers.rb @@ -60,9 +60,9 @@ module Vagrant # Returns the URL prefix to the server. # # @return [String] - def self.server_url + def self.server_url(config_server_url=nil) result = ENV["VAGRANT_SERVER_URL"] - result = nil if result == "" + result = config_server_url if result == "" or result == nil result || DEFAULT_SERVER_URL end diff --git a/plugins/kernel_v2/config/vm.rb b/plugins/kernel_v2/config/vm.rb index de70e5f66..c152c45ba 100644 --- a/plugins/kernel_v2/config/vm.rb +++ b/plugins/kernel_v2/config/vm.rb @@ -19,6 +19,7 @@ module VagrantPlugins attr_accessor :box attr_accessor :box_check_update attr_accessor :box_url + attr_accessor :box_server_url attr_accessor :box_version attr_accessor :box_download_ca_cert attr_accessor :box_download_ca_path diff --git a/test/unit/vagrant/action/builtin/box_add_test.rb b/test/unit/vagrant/action/builtin/box_add_test.rb index dce7fde02..03e064920 100644 --- a/test/unit/vagrant/action/builtin/box_add_test.rb +++ b/test/unit/vagrant/action/builtin/box_add_test.rb @@ -306,6 +306,53 @@ describe Vagrant::Action::Builtin::BoxAdd do end end + it "add from shorthand path with configured server url" do + box_path = iso_env.box2_file(:virtualbox) + td = Pathname.new(Dir.mktmpdir) + tf = td.join("mitchellh", "precise64.json") + tf.dirname.mkpath + tf.open("w") do |f| + f.write(<<-RAW) + { + "name": "mitchellh/precise64", + "versions": [ + { + "version": "0.5" + }, + { + "version": "0.7", + "providers": [ + { + "name": "virtualbox", + "url": "#{box_path}" + } + ] + } + ] + } + RAW + end + + with_web_server(tf.dirname) do |port| + url = "http://127.0.0.1:#{port}" + env[:box_url] = "mitchellh/precise64.json" + env[:box_server_url] = url + + expect(box_collection).to receive(:add).with { |path, name, version, **opts| + expect(name).to eq("mitchellh/precise64") + expect(version).to eq("0.7") + expect(checksum(path)).to eq(checksum(box_path)) + expect(opts[:metadata_url]).to eq( + "#{url}/#{env[:box_url]}") + true + }.and_return(box) + + expect(app).to receive(:call).with(env) + + subject.call(env) + end + end + it "authenticates HTTP URLs and adds them" do box_path = iso_env.box2_file(:virtualbox) tf = Tempfile.new(["vagrant", ".json"]).tap do |f| diff --git a/test/unit/vagrant/shared_helpers_test.rb b/test/unit/vagrant/shared_helpers_test.rb index 67772c79f..7333ea1f5 100644 --- a/test/unit/vagrant/shared_helpers_test.rb +++ b/test/unit/vagrant/shared_helpers_test.rb @@ -71,6 +71,18 @@ describe Vagrant do expect(subject.server_url).to eq("foo") end end + + it "is the VAGRANT_SERVER_URL value if the server url is configured" do + with_temp_env("VAGRANT_SERVER_URL" => "foo") do + expect(subject.server_url('bar')).to eq("foo") + end + end + + it "is the configured server url if VAGRANT_SERVER_URL is not set" do + with_temp_env("VAGRANT_SERVER_URL" => nil) do + expect(subject.server_url("bar")).to eq("bar") + end + end end describe "#user_data_path" do