2020-10-10 14:16:11 +02:00
|
|
|
# typed: false
|
2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-09-06 08:29:14 +02:00
|
|
|
module Cask
|
2018-09-05 01:39:30 +02:00
|
|
|
describe Verify, :cask do
|
|
|
|
describe "::all" do
|
|
|
|
subject(:verification) { described_class.all(cask, downloaded_path) }
|
2018-09-20 09:07:56 +01:00
|
|
|
|
2018-09-05 01:39:30 +02:00
|
|
|
let(:cask) { instance_double(Cask, token: "cask", sha256: expected_sha256) }
|
|
|
|
let(:cafebabe) { "cafebabecafebabecafebabecafebabecafebabecafebabecafebabecafebabe" }
|
|
|
|
let(:deadbeef) { "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef" }
|
|
|
|
let(:computed_sha256) { cafebabe }
|
|
|
|
let(:downloaded_path) { instance_double(Pathname, sha256: computed_sha256) }
|
|
|
|
|
|
|
|
context "when the expected checksum is :no_check" do
|
|
|
|
let(:expected_sha256) { :no_check }
|
|
|
|
|
|
|
|
it "skips the check" do
|
|
|
|
expect { verification }.to output(/skipping verification/).to_stdout
|
|
|
|
end
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2018-09-05 01:39:30 +02:00
|
|
|
context "when expected and computed checksums match" do
|
|
|
|
let(:expected_sha256) { cafebabe }
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2018-09-05 01:39:30 +02:00
|
|
|
it "does not raise an error" do
|
|
|
|
expect { verification }.not_to raise_error
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
2018-09-05 01:39:30 +02:00
|
|
|
context "when the expected checksum is nil" do
|
|
|
|
let(:expected_sha256) { nil }
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2018-09-05 01:39:30 +02:00
|
|
|
it "raises an error" do
|
2020-09-16 17:40:26 -05:00
|
|
|
expect { verification }.to raise_error(CaskSha256MissingError, /sha256 "#{computed_sha256}"/)
|
2018-09-05 01:39:30 +02:00
|
|
|
end
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2018-09-05 01:39:30 +02:00
|
|
|
context "when the expected checksum is empty" do
|
|
|
|
let(:expected_sha256) { "" }
|
2018-03-25 13:30:37 +01:00
|
|
|
|
2018-09-05 01:39:30 +02:00
|
|
|
it "raises an error" do
|
2020-09-16 17:40:26 -05:00
|
|
|
expect { verification }.to raise_error(CaskSha256MissingError, /sha256 "#{computed_sha256}"/)
|
2018-09-05 01:39:30 +02:00
|
|
|
end
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2018-09-05 01:39:30 +02:00
|
|
|
context "when expected and computed checksums do not match" do
|
|
|
|
let(:expected_sha256) { deadbeef }
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2018-09-05 01:39:30 +02:00
|
|
|
it "raises an error" do
|
|
|
|
expect { verification }.to raise_error CaskSha256MismatchError
|
|
|
|
end
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|