mirror of
https://github.com/hashicorp/vagrant.git
synced 2026-02-05 06:46:21 +01:00
Merge pull request #11618 from jbonhag/fix/empty-box
Treat an empty box value as invalid
This commit is contained in:
@@ -20,7 +20,7 @@ module Vagrant
|
||||
def call(env)
|
||||
machine = env[:machine]
|
||||
|
||||
if !machine.config.vm.box
|
||||
if !machine.config.vm.box || machine.config.vm.box.to_s.empty?
|
||||
@logger.info("Skipping HandleBox because no box is set")
|
||||
return @app.call(env)
|
||||
end
|
||||
|
||||
@@ -197,7 +197,7 @@ module Vagrant
|
||||
local_keys = keys.dup
|
||||
|
||||
# Load the box Vagrantfile, if there is one
|
||||
if config.vm.box && boxes
|
||||
if !config.vm.box.to_s.empty? && boxes
|
||||
box = boxes.find(config.vm.box, box_formats, config.vm.box_version)
|
||||
if box
|
||||
box_vagrantfile = find_vagrantfile(box.directory)
|
||||
|
||||
@@ -734,6 +734,10 @@ module VagrantPlugins
|
||||
errors << I18n.t("vagrant.config.vm.clone_and_box")
|
||||
end
|
||||
|
||||
if box && box.empty?
|
||||
errors << I18n.t("vagrant.config.vm.box_empty", machine_name: machine.name)
|
||||
end
|
||||
|
||||
errors << I18n.t("vagrant.config.vm.hostname_invalid_characters", name: machine.name) if \
|
||||
@hostname && @hostname !~ /^[a-z0-9][-.a-z0-9]*$/i
|
||||
|
||||
|
||||
@@ -1995,6 +1995,7 @@ en:
|
||||
Checksum type specified but "box_download_checksum" is blank
|
||||
box_download_checksum_notblank: |-
|
||||
Checksum specified but must also specify "box_download_checksum_type"
|
||||
box_empty: "Box value for guest '%{machine_name}' is an empty string."
|
||||
box_missing: "A box must be specified."
|
||||
box_download_options_type: |-
|
||||
Found "box_download_options" specified as type '%{type}', should be a Hash
|
||||
|
||||
0
test/unit/plugins/guests/openwrt/guest_test.rb
Normal file
0
test/unit/plugins/guests/openwrt/guest_test.rb
Normal file
@@ -86,6 +86,12 @@ describe VagrantPlugins::Kernel_V2::VMConfig do
|
||||
assert_invalid
|
||||
end
|
||||
|
||||
it "cannot be an empty string" do
|
||||
subject.box = ""
|
||||
subject.finalize!
|
||||
assert_invalid
|
||||
end
|
||||
|
||||
it "is not required if the provider says so" do
|
||||
machine.provider_options[:box_optional] = true
|
||||
subject.box = nil
|
||||
|
||||
@@ -37,6 +37,15 @@ describe Vagrant::Action::Builtin::HandleBox do
|
||||
subject.call(env)
|
||||
end
|
||||
|
||||
it "works if box is empty string" do
|
||||
machine.config.vm.box = ""
|
||||
machine.config.vm.box_url = nil
|
||||
|
||||
expect(app).to receive(:call).with(env)
|
||||
|
||||
subject.call(env)
|
||||
end
|
||||
|
||||
it "doesn't do anything if a box exists" do
|
||||
allow(machine).to receive(:box).and_return(box)
|
||||
|
||||
|
||||
@@ -368,6 +368,17 @@ describe Vagrant::Vagrantfile do
|
||||
to raise_error(Vagrant::Errors::ProviderNotUsable)
|
||||
end
|
||||
|
||||
it "does not try to load the box if the box is empty" do
|
||||
provider_cls = register_provider("foo")
|
||||
|
||||
configure do |config|
|
||||
config.vm.box = ""
|
||||
end
|
||||
|
||||
expect(boxes).not_to receive(:find)
|
||||
results = subject.machine_config(:default, :foo, boxes)
|
||||
end
|
||||
|
||||
context "when provider validation is ignored" do
|
||||
before do
|
||||
configure do |config|
|
||||
|
||||
Reference in New Issue
Block a user