Merge pull request #11211 from briancain/fixup/ensure-checksum-and-type-are-not-empty

Fixes #11207: Do not validate checksums if options are empty string
This commit is contained in:
Brian Cain 2019-11-22 10:17:10 -08:00 committed by GitHub
commit 6831129720
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 5 deletions

View File

@ -348,10 +348,16 @@ module Vagrant
end
if opts[:checksum] && opts[:checksum_type]
if opts[:checksum].to_s.strip.empty?
@logger.warn("Given checksum is empty, cannot validate checksum for box")
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
# Add the box!
box = env[:box_collection].add(

View File

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

View File

@ -578,7 +578,7 @@ en:
The specified checksum type is not supported by Vagrant: %{type}.
Vagrant supports the following checksum types:
md5, sha1, sha256
%{types}
box_checksum_mismatch: |-
The checksum of the downloaded box did not match the expected
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)
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
box_path = iso_env.box2_file(:virtualbox)