From 4e21dd78e4e9d50e56059cf00610c2201201bb4c Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Mon, 7 Dec 2015 10:30:44 -0500 Subject: [PATCH] Ignore case when comparing checksums Fixes GH-6648 --- lib/vagrant/action/builtin/box_add.rb | 2 +- .../vagrant/action/builtin/box_add_test.rb | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/vagrant/action/builtin/box_add.rb b/lib/vagrant/action/builtin/box_add.rb index fbc6bd51f..b87bf46b6 100644 --- a/lib/vagrant/action/builtin/box_add.rb +++ b/lib/vagrant/action/builtin/box_add.rb @@ -522,7 +522,7 @@ module Vagrant @logger.info("Expected checksum: #{checksum}") actual = FileChecksum.new(path, checksum_klass).checksum - if actual != checksum + if actual.casecmp(checksum) != 0 raise Errors::BoxChecksumMismatch, actual: actual, expected: checksum diff --git a/test/unit/vagrant/action/builtin/box_add_test.rb b/test/unit/vagrant/action/builtin/box_add_test.rb index d881fad0b..db3c7044f 100644 --- a/test/unit/vagrant/action/builtin/box_add_test.rb +++ b/test/unit/vagrant/action/builtin/box_add_test.rb @@ -207,6 +207,28 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do to raise_error(Vagrant::Errors::BoxChecksumMismatch) end + it "does not raise an error if the checksum has different case" do + box_path = iso_env.box2_file(:virtualbox) + + box = double( + name: "foo", + version: "1.2.3", + provider: "virtualbox", + ) + + env[:box_name] = box.name + env[:box_url] = box_path.to_s + env[:box_checksum] = checksum(box_path) + env[:box_checksum_type] = "sha1" + + # Convert to a different case + env[:box_checksum].upcase! + + expect(box_collection).to receive(:add).and_return(box) + + expect { subject.call(env) }.to_not raise_error + end + it "raises an error if the box path doesn't exist" do box_path = iso_env.box2_file(:virtualbox)