From 40eb97893152e8a618f31b1f8e60302a1364162d Mon Sep 17 00:00:00 2001 From: Simon Vetter Date: Tue, 20 Jan 2015 14:28:29 +0100 Subject: [PATCH 1/2] fix checksum verification for downloaded boxes (fixes #4665) This makes sure that config.vm.box_download_checksum and config.vm.box_download_checksum_type get passed to Vagrant::Action.action_box_add with other options on box download/import. --- lib/vagrant/action/builtin/handle_box.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/vagrant/action/builtin/handle_box.rb b/lib/vagrant/action/builtin/handle_box.rb index a01e49d64..8cbdd413c 100644 --- a/lib/vagrant/action/builtin/handle_box.rb +++ b/lib/vagrant/action/builtin/handle_box.rb @@ -64,6 +64,8 @@ module Vagrant box_download_ca_path = machine.config.vm.box_download_ca_path box_download_client_cert = machine.config.vm.box_download_client_cert box_download_insecure = machine.config.vm.box_download_insecure + box_download_checksum_type = machine.config.vm.box_download_checksum_type + box_download_checksum = machine.config.vm.box_download_checksum box_formats = machine.provider_options[:box_format] || machine.provider_name @@ -86,6 +88,8 @@ module Vagrant box_download_ca_cert: box_download_ca_cert, box_download_ca_path: box_download_ca_path, box_download_insecure: box_download_insecure, + box_checksum_type: box_download_checksum_type, + box_checksum: box_download_checksum, })) rescue Errors::BoxAlreadyExists # Just ignore this, since it means the next part will succeed! From 1bc364febc936876117e1b22acac02d2ef4d687c Mon Sep 17 00:00:00 2001 From: Simon Vetter Date: Wed, 21 Jan 2015 21:40:25 +0100 Subject: [PATCH 2/2] add test for checksum options mapping --- .../vagrant/action/builtin/handle_box_test.rb | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/unit/vagrant/action/builtin/handle_box_test.rb b/test/unit/vagrant/action/builtin/handle_box_test.rb index 6b7d85818..17f32563f 100644 --- a/test/unit/vagrant/action/builtin/handle_box_test.rb +++ b/test/unit/vagrant/action/builtin/handle_box_test.rb @@ -106,4 +106,31 @@ describe Vagrant::Action::Builtin::HandleBox do subject.call(env) end end + + context "with a box with a checksum set" do + before do + machine.stub(box: nil) + + machine.config.vm.box = "foo" + machine.config.vm.box_url = "bar" + machine.config.vm.box_download_checksum_type = "sha256" + machine.config.vm.box_download_checksum = "1f42ac2decf0169c4af02b2d8c77143ce35f7ba87d5d844e19bf7cbb34fbe74e" + end + + it "adds a box that doesn't exist and maps checksum options correctly" do + expect(action_runner).to receive(:run).with { |action, opts| + expect(opts[:box_name]).to eq(machine.config.vm.box) + expect(opts[:box_url]).to eq(machine.config.vm.box_url) + expect(opts[:box_provider]).to eq(:dummy) + expect(opts[:box_version]).to eq(machine.config.vm.box_version) + expect(opts[:box_checksum_type]).to eq(machine.config.vm.box_download_checksum_type) + expect(opts[:box_checksum]).to eq(machine.config.vm.box_download_checksum) + true + } + + expect(app).to receive(:call).with(env) + + subject.call(env) + end + end end