summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAliasgar16 <aliasgar.batterywala@msystechnologies.com>2016-09-21 07:02:58 +0530
committerMatt Wrock <matt@mattwrock.com>2016-09-20 18:32:58 -0700
commit555abc008946f8b239a79809104b07062f9082ae (patch)
treee7b85f292f9bbf7a19ad9852c7309638bf04c5ad
parent19b3900b5f6a24009b8f14eb09d4105e721b9262 (diff)
downloadchef-555abc008946f8b239a79809104b07062f9082ae.tar.gz
Fixed undefined short_cksum method issue and checksum in uppercase issue for windows_package resource. (#5332)
* Fixed undefined short_cksum method issue and checksum in uppercase issue for windows_package resource. * Added RSpecs for the changes done here. * Fixed RSpecs issues.
-rw-r--r--lib/chef/mixin/checksum.rb5
-rw-r--r--lib/chef/provider/file.rb7
-rw-r--r--lib/chef/provider/package/windows.rb2
-rw-r--r--spec/unit/mixin/checksum_spec.rb14
-rw-r--r--spec/unit/provider/package/windows_spec.rb45
5 files changed, 66 insertions, 7 deletions
diff --git a/lib/chef/mixin/checksum.rb b/lib/chef/mixin/checksum.rb
index f223894c39..2888b205a9 100644
--- a/lib/chef/mixin/checksum.rb
+++ b/lib/chef/mixin/checksum.rb
@@ -27,6 +27,11 @@ class Chef
Chef::Digester.checksum_for_file(file)
end
+ def short_cksum(checksum)
+ return "none" if checksum.nil?
+ checksum.slice(0, 6)
+ end
+
end
end
end
diff --git a/lib/chef/provider/file.rb b/lib/chef/provider/file.rb
index 7f85085eeb..84bb4d1c94 100644
--- a/lib/chef/provider/file.rb
+++ b/lib/chef/provider/file.rb
@@ -344,7 +344,7 @@ class Chef
end
def do_validate_content
- if new_resource.checksum && tempfile && ( new_resource.checksum != tempfile_checksum )
+ if new_resource.checksum && tempfile && ( new_resource.checksum.downcase != tempfile_checksum )
raise Chef::Exceptions::ChecksumMismatch.new(short_cksum(new_resource.checksum), short_cksum(tempfile_checksum))
end
@@ -462,11 +462,6 @@ class Chef
@tempfile ||= content.tempfile
end
- def short_cksum(checksum)
- return "none" if checksum.nil?
- checksum.slice(0, 6)
- end
-
def load_resource_attributes_from_file(resource)
if Chef::Platform.windows?
# This is a work around for CHEF-3554.
diff --git a/lib/chef/provider/package/windows.rb b/lib/chef/provider/package/windows.rb
index 753d3c279e..b11bcf5192 100644
--- a/lib/chef/provider/package/windows.rb
+++ b/lib/chef/provider/package/windows.rb
@@ -250,7 +250,7 @@ class Chef
def validate_content!
if new_resource.checksum
source_checksum = checksum(source_location)
- if new_resource.checksum != source_checksum
+ if new_resource.checksum.downcase != source_checksum
raise Chef::Exceptions::ChecksumMismatch.new(short_cksum(new_resource.checksum), short_cksum(source_checksum))
end
end
diff --git a/spec/unit/mixin/checksum_spec.rb b/spec/unit/mixin/checksum_spec.rb
index 997dcd523e..801c8820d2 100644
--- a/spec/unit/mixin/checksum_spec.rb
+++ b/spec/unit/mixin/checksum_spec.rb
@@ -37,4 +37,18 @@ describe Chef::Mixin::Checksum do
expect(@checksum_user.checksum(@file)).to eq("09ee9c8cc70501763563bcf9c218d71b2fbf4186bf8e1e0da07f0f42c80a3394")
end
+ describe "short_cksum" do
+ context "nil provided for checksum" do
+ it "returns none" do
+ expect(@checksum_user.short_cksum(nil)).to eq("none")
+ end
+ end
+
+ context "non-nil provided for checksum" do
+ it "returns the short checksum" do
+ expect(@checksum_user.short_cksum("u7ghbxikk3i9blsimmy2y2ionmxx")).to eq("u7ghbx")
+ end
+ end
+ end
+
end
diff --git a/spec/unit/provider/package/windows_spec.rb b/spec/unit/provider/package/windows_spec.rb
index e26662ac75..d1d717bdbe 100644
--- a/spec/unit/provider/package/windows_spec.rb
+++ b/spec/unit/provider/package/windows_spec.rb
@@ -394,4 +394,49 @@ describe Chef::Provider::Package::Windows, :windows_only do
end
end
end
+
+ shared_context "valid checksum" do
+ context "checksum is valid" do
+ before do
+ allow(provider).to receive(:checksum).and_return("jiie00u3bbs92vsbhvgvklb2lasgh20ah")
+ end
+
+ it "does not raise the checksum mismatch exception" do
+ expect { provider.send(:validate_content!) }.to_not raise_error
+ end
+ end
+ end
+
+ shared_context "invalid checksum" do
+ context "checksum is invalid" do
+ before do
+ allow(provider).to receive(:checksum).and_return("kiie30u3bbs92vsbhvgvklb2lasgh20ah")
+ end
+
+ it "raises the checksum mismatch exception" do
+ expect { provider.send(:validate_content!) }.to raise_error(
+ Chef::Exceptions::ChecksumMismatch)
+ end
+ end
+ end
+
+ describe "validate_content!" do
+ before(:each) do
+ new_resource.checksum("jiie00u3bbs92vsbhvgvklb2lasgh20ah")
+ end
+
+ context "checksum is in lowercase" do
+ include_context "valid checksum"
+ include_context "invalid checksum"
+ end
+
+ context "checksum is in uppercase" do
+ before do
+ new_resource.checksum = new_resource.checksum.upcase
+ end
+
+ include_context "valid checksum"
+ include_context "invalid checksum"
+ end
+ end
end