diff --git a/lib/vagrant/util/file_checksum.rb b/lib/vagrant/util/file_checksum.rb index e5e7cf715..2b195a7b0 100644 --- a/lib/vagrant/util/file_checksum.rb +++ b/lib/vagrant/util/file_checksum.rb @@ -2,6 +2,9 @@ # passed into FileChecksum. Note that this isn't strictly enforced at # the moment, and this class isn't directly used. It is merely here for # documentation of structure of the class. + +require "vagrant/errors" + class DigestClass def update(string); end def hexdigest; end @@ -62,7 +65,7 @@ class FileChecksum def load_digest(type) digest = CHECKSUM_MAP[type.to_s.to_sym] if digest.nil? - raise Errors::BoxChecksumInvalidType, + raise Vagrant::Errors::BoxChecksumInvalidType, type: type.to_s end digest diff --git a/test/unit/vagrant/util/file_checksum_test.rb b/test/unit/vagrant/util/file_checksum_test.rb index c467238d4..43fe40661 100644 --- a/test/unit/vagrant/util/file_checksum_test.rb +++ b/test/unit/vagrant/util/file_checksum_test.rb @@ -32,4 +32,15 @@ describe FileChecksum do expect(t_i.checksum).to eq(k_i.checksum) end end + + context "with an invalid digest" do + let(:fake_digest) { :fake_digest } + + it "should raise an exception if the box has an invalid checksum type" do + file = environment.workdir.join("file") + file.open("w+") { |f| f.write("HELLO!") } + + expect{ described_class.new(file, fake_digest) }.to raise_error(Vagrant::Errors::BoxChecksumInvalidType) + end + end end