summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Mundrawala <jdmundrawala@gmail.com>2015-05-15 06:51:48 -0700
committerJay Mundrawala <jdmundrawala@gmail.com>2015-05-15 07:04:21 -0700
commit38a38ba43aa68e05c7316649cb1ac3079e595e2a (patch)
tree11d4841e1cec0da9d4487d654c7513a5a07f9d16
parent422e9a95df1c542f76c3060b48f4f7b0a99c531d (diff)
downloadchef-38a38ba43aa68e05c7316649cb1ac3079e595e2a.tar.gz
Surface checksum attribute
-rw-r--r--lib/chef/provider/package/windows.rb16
-rw-r--r--lib/chef/resource/windows_package.rb8
-rw-r--r--spec/unit/resource/windows_package_spec.rb5
3 files changed, 29 insertions, 0 deletions
diff --git a/lib/chef/provider/package/windows.rb b/lib/chef/provider/package/windows.rb
index 599b554ea4..4cb550407c 100644
--- a/lib/chef/provider/package/windows.rb
+++ b/lib/chef/provider/package/windows.rb
@@ -20,12 +20,14 @@ require 'chef/mixin/uris'
require 'chef/resource/windows_package'
require 'chef/provider/package'
require 'chef/util/path_helper'
+require 'chef/mixin/checksum'
class Chef
class Provider
class Package
class Windows < Chef::Provider::Package
include Chef::Mixin::Uris
+ include Chef::Mixin::Checksum
provides :package, os: "windows"
provides :windows_package, os: "windows"
@@ -81,7 +83,10 @@ class Chef
if uri_scheme?(new_resource.source)
download_source_file
load_current_resource
+ else
+ validate_content!
end
+
super
end
@@ -124,6 +129,7 @@ class Chef
def source_resource
@source_resource ||= Chef::Resource::RemoteFile.new(default_download_cache_path, run_context).tap do |r|
r.source(new_resource.source)
+ r.checksum(new_resource.checksum)
r.backup(false)
if new_resource.remote_file_attributes
@@ -148,6 +154,16 @@ class Chef
Chef::Util::PathHelper.cleanpath(new_resource.source)
end
end
+
+ def validate_content!
+ if new_resource.checksum
+ source_checksum = checksum(source_location)
+ if new_resource.checksum != source_checksum
+ raise Chef::Exceptions::ChecksumMismatch.new(short_cksum(new_resource.checksum), short_cksum(source_checksum))
+ end
+ end
+ end
+
end
end
end
diff --git a/lib/chef/resource/windows_package.rb b/lib/chef/resource/windows_package.rb
index 6c6dea0f5a..e900619100 100644
--- a/lib/chef/resource/windows_package.rb
+++ b/lib/chef/resource/windows_package.rb
@@ -79,6 +79,14 @@ class Chef
end
end
+ def checksum(arg=nil)
+ set_or_return(
+ :checksum,
+ arg,
+ :kind_of => [ String ]
+ )
+ end
+
def remote_file_attributes(arg=nil)
set_or_return(
:remote_file_attributes,
diff --git a/spec/unit/resource/windows_package_spec.rb b/spec/unit/resource/windows_package_spec.rb
index 6091621533..094a678cf6 100644
--- a/spec/unit/resource/windows_package_spec.rb
+++ b/spec/unit/resource/windows_package_spec.rb
@@ -79,6 +79,11 @@ describe Chef::Resource::WindowsPackage, "initialize" do
expect(resource.source).to include("solitaire.msi")
end
+ it "supports the checksum attribute" do
+ resource.checksum('somechecksum')
+ expect(resource.checksum).to eq('somechecksum')
+ end
+
context 'when a URL is used' do
let(:resource_source) { 'https://foo.bar/solitare.msi' }
let(:resource) { Chef::Resource::WindowsPackage.new(resource_source) }