Merge pull request #11183 from briancain/fixup/include-errors-in-checksum-util

Fixes #11179: Ensure Vagrant::Errors are loaded in file_checksum util
This commit is contained in:
Brian Cain 2019-11-12 09:06:49 -08:00 committed by GitHub
commit 39ea1af5ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -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

View File

@ -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