Box verification

This commit is contained in:
Mitchell Hashimoto 2010-07-08 07:55:27 -07:00
parent 50af3987fc
commit 842ddd75b4
4 changed files with 64 additions and 1 deletions

View File

@ -0,0 +1,23 @@
module Vagrant
class Action
module Box
class Verify
def initialize(app, env)
@app = app
@env = env
end
def call(env)
begin
env.logger.info "Verifying box..."
VirtualBox::Appliance.new(env["box"].ovf_file)
rescue Exception
return env.error!(:box_verification_failed)
end
@app.call(env)
end
end
end
end
end

View File

@ -88,6 +88,7 @@ module Vagrant
box_add = Builder.new do
use Box::Download
use Box::Unpackage
use Box::Verify
end
register :box_add, box_add

View File

@ -0,0 +1,39 @@
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
class VerifyBoxActionTest < Test::Unit::TestCase
setup do
@klass = Vagrant::Action::Box::Verify
@app, @env = mock_action_data
@vm = mock("vm")
@env["vm"] = @vm
@env["box"] = Vagrant::Box.new(mock_environment, "foo")
@internal_vm = mock("internal")
@vm.stubs(:vm).returns(@internal_vm)
@instance = @klass.new(@app, @env)
end
context "calling" do
setup do
@env.logger.stubs(:info)
end
should "continue fine if verification succeeds" do
seq = sequence("seq")
VirtualBox::Appliance.expects(:new).with(@env["box"].ovf_file).in_sequence(seq)
@app.expects(:call).with(@env).once.in_sequence(seq)
@instance.call(@env)
assert !@env.error?
end
should "halt chain if verification fails" do
VirtualBox::Appliance.expects(:new).with(@env["box"].ovf_file).raises(Exception)
@app.expects(:call).with(@env).never
@instance.call(@env)
assert @env.error?
assert_equal :box_verification_failed, @env.error.first
end
end
end

View File

@ -1,6 +1,6 @@
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
class VerifyBoxActionTest < Test::Unit::TestCase
class VerifyBoxActionsTest < Test::Unit::TestCase
setup do
@runner, @vm, @action = mock_action(Vagrant::Actions::Box::Verify)
@runner.stubs(:name).returns("foo")