From c4ce765dc71a2ad1762ce5c43f0e245a17909378 Mon Sep 17 00:00:00 2001 From: Joseph Larionov <30190605+decoyjoe@users.noreply.github.com> Date: Tue, 1 Nov 2022 12:37:58 -0700 Subject: Bugfix: checksum validation (#13210) * Add a case-insensitive helper to determine if two checksums match * Use case-insensitive checksum match helper for checksum validation This fixes a bug where checksum validation fails because the two checksums are in different letter cases. The existing checksum validation logic was using case sensitive equality checks. Signed-off-by: Joseph Larionov --- spec/unit/mixin/checksum_spec.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'spec') diff --git a/spec/unit/mixin/checksum_spec.rb b/spec/unit/mixin/checksum_spec.rb index e8fb1ed4dc..9c1e19769d 100644 --- a/spec/unit/mixin/checksum_spec.rb +++ b/spec/unit/mixin/checksum_spec.rb @@ -51,4 +51,32 @@ describe Chef::Mixin::Checksum do end end + describe "checksum_match?" do + context "when checksum cases match" do + it "returns true" do + expect(@checksum_user.checksum_match?("u7ghbxikk3i9blsimmy2y2ionmxx", "u7ghbxikk3i9blsimmy2y2ionmxx")).to be true + end + end + + context "when one checksum is uppercase and other is lowercase" do + it "returns true" do + expect(@checksum_user.checksum_match?("U7GHBXIKK3I9BLSIMMY2Y2IONMXX", "u7ghbxikk3i9blsimmy2y2ionmxx")).to be true + end + end + + context "when checksums do not match" do + it "returns false" do + expect(@checksum_user.checksum_match?("u7ghbxikk3i9blsimmy2y2ionmxx", "09ee9c8cc70501763563bcf9c218")).to be false + end + end + + context "when checksum is nil" do + it "returns false" do + expect(@checksum_user.checksum_match?("u7ghbxikk3i9blsimmy2y2ionmxx", nil)).to be false + expect(@checksum_user.checksum_match?(nil, "09ee9c8cc70501763563bcf9c218")).to be false + expect(@checksum_user.checksum_match?(nil, nil)).to be false + end + end + end + end -- cgit v1.2.1