Merge pull request #1326 from lolindrath/master

Add test for invalid box file
This commit is contained in:
Mitchell Hashimoto 2013-01-29 11:09:05 -08:00
commit 948a31d7b3
1 changed files with 20 additions and 1 deletions

View File

@ -1,6 +1,8 @@
require File.expand_path("../../base", __FILE__)
require "pathname"
require 'tempfile'
require 'archive/tar/minitar'
describe Vagrant::BoxCollection do
include_context "unit"
@ -105,7 +107,24 @@ describe Vagrant::BoxCollection do
end
it "should raise an exception if you add an invalid box file" do
pending "I don't know how to generate an invalid tar."
# Tar Header information
CHECKSUM_OFFSET = 148
CHECKSUM_LENGTH = 8
Tempfile.new(['vagrant_testing', '.tar']) do |f|
# Create a temp tar file
Archive::Tar::Minitar.pack('test', f)
# Minitar closes the Tempfile so reopen it
f = File.open(f.path, "wb")
# Corrupt the tar by writing over the checksum field
f.seek(CHECKSUM_OFFSET)
f.write("\0"*CHECKSUM_LENGTH)
f.close
expect { instance.add(path, "foo", :virtualbox) }.
to raise_error(Vagrant::Errors::BoxUnpackageFailure)
end
end
end