Fixes #11207: Do not validate checksums if options are empty string

Prior to this commit, if Vagrant received checksum options from Vagrant
Cloud that were simply empty strings, it would try to validate its
checksum with those options. This commit fixes that by ignoring empty
string values.
This commit is contained in:
Brian Cain 2019-11-21 09:56:58 -08:00
parent 237af1b6aa
commit efd3a62ffe
No known key found for this signature in database
GPG Key ID: 9FC4639B2E4510A0
4 changed files with 35 additions and 5 deletions

View File

@ -348,9 +348,15 @@ module Vagrant
end end
if opts[:checksum] && opts[:checksum_type] if opts[:checksum] && opts[:checksum_type]
env[:ui].detail(I18n.t("vagrant.actions.box.add.checksumming")) if opts[:checksum].to_s.strip.empty?
validate_checksum( @logger.warn("Given checksum is empty, cannot validate checksum for box")
opts[:checksum_type], opts[:checksum], box_url) elsif opts[:checksum_type].to_s.strip.empty?
@logger.warn("Given checksum type is empty, cannot validate checksum for box")
else
env[:ui].detail(I18n.t("vagrant.actions.box.add.checksumming"))
validate_checksum(
opts[:checksum_type], opts[:checksum], box_url)
end
end end
# Add the box! # Add the box!

View File

@ -66,7 +66,8 @@ class FileChecksum
digest = CHECKSUM_MAP[type.to_s.to_sym] digest = CHECKSUM_MAP[type.to_s.to_sym]
if digest.nil? if digest.nil?
raise Vagrant::Errors::BoxChecksumInvalidType, raise Vagrant::Errors::BoxChecksumInvalidType,
type: type.to_s type: type.to_s,
types: CHECKSUM_MAP.keys.join(', ')
end end
digest digest
end end

View File

@ -578,7 +578,7 @@ en:
The specified checksum type is not supported by Vagrant: %{type}. The specified checksum type is not supported by Vagrant: %{type}.
Vagrant supports the following checksum types: Vagrant supports the following checksum types:
md5, sha1, sha256 %{types}
box_checksum_mismatch: |- box_checksum_mismatch: |-
The checksum of the downloaded box did not match the expected The checksum of the downloaded box did not match the expected
value. Please verify that you have the proper URL setup and that value. Please verify that you have the proper URL setup and that

View File

@ -209,6 +209,29 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows, :bsdtar do
to raise_error(Vagrant::Errors::BoxChecksumMismatch) to raise_error(Vagrant::Errors::BoxChecksumMismatch)
end end
it "ignores checksums if empty string" do
box_path = iso_env.box2_file(:virtualbox)
with_web_server(box_path) do |port|
env[:box_name] = "foo"
env[:box_url] = "http://127.0.0.1:#{port}/#{box_path.basename}"
env[:box_checksum] = ""
env[:box_checksum_type] = ""
expect(box_collection).to receive(:add).with(any_args) { |path, name, version, **opts|
expect(checksum(path)).to eq(checksum(box_path))
expect(name).to eq("foo")
expect(version).to eq("0")
expect(opts[:metadata_url]).to be_nil
true
}.and_return(box)
expect(app).to receive(:call).with(env)
subject.call(env)
end
end
it "does not raise an error if the checksum has different case" do it "does not raise an error if the checksum has different case" do
box_path = iso_env.box2_file(:virtualbox) box_path = iso_env.box2_file(:virtualbox)