Remove cask-specific checksum errors.
This commit is contained in:
parent
7a83f34dd1
commit
c54a9937e7
@ -50,21 +50,20 @@ module Cask
|
||||
|
||||
def verify_download_integrity(fn)
|
||||
if @cask.sha256 == :no_check
|
||||
opoo "No checksum defined for Cask '#{@cask}', skipping verification."
|
||||
opoo "No checksum defined for cask '#{@cask}', skipping verification."
|
||||
return
|
||||
end
|
||||
|
||||
ohai "Verifying checksum for Cask '#{@cask}'." if verbose?
|
||||
|
||||
expected = @cask.sha256
|
||||
actual = fn.sha256
|
||||
|
||||
begin
|
||||
fn.verify_checksum(expected)
|
||||
ohai "Verifying checksum for cask '#{@cask}'." if verbose?
|
||||
fn.verify_checksum(@cask.sha256)
|
||||
rescue ChecksumMissingError
|
||||
raise CaskSha256MissingError.new(@cask.token, expected, actual)
|
||||
rescue ChecksumMismatchError
|
||||
raise CaskSha256MismatchError.new(@cask.token, expected, actual, fn)
|
||||
opoo <<~EOS
|
||||
Cannot verify integrity of '#{fn.basename}'.
|
||||
No checksum was provided for this cask.
|
||||
For your reference, the checksum is:
|
||||
sha256 "#{fn.sha256}"
|
||||
EOS
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -207,76 +207,6 @@ module Cask
|
||||
end
|
||||
end
|
||||
|
||||
# Error with a cask's checksum.
|
||||
#
|
||||
# @api private
|
||||
class CaskSha256Error < AbstractCaskErrorWithToken
|
||||
attr_reader :expected, :actual
|
||||
|
||||
def initialize(token, expected = nil, actual = nil)
|
||||
super(token)
|
||||
@expected = expected
|
||||
@actual = actual
|
||||
end
|
||||
end
|
||||
|
||||
# Error when a cask's checksum is missing.
|
||||
#
|
||||
# @api private
|
||||
class CaskSha256MissingError < CaskSha256Error
|
||||
extend T::Sig
|
||||
|
||||
sig { returns(String) }
|
||||
def to_s
|
||||
<<~EOS
|
||||
Cask '#{token}' requires a checksum:
|
||||
#{Formatter.identifier("sha256 \"#{actual}\"")}
|
||||
EOS
|
||||
end
|
||||
end
|
||||
|
||||
# Error when a cask's checksum does not match.
|
||||
#
|
||||
# @api private
|
||||
class CaskSha256MismatchError < CaskSha256Error
|
||||
extend T::Sig
|
||||
|
||||
attr_reader :path
|
||||
|
||||
def initialize(token, expected, actual, path)
|
||||
super(token, expected, actual)
|
||||
@path = path
|
||||
end
|
||||
|
||||
sig { returns(String) }
|
||||
def to_s
|
||||
<<~EOS
|
||||
Checksum for Cask '#{token}' does not match.
|
||||
Expected: #{Formatter.success(expected.to_s)}
|
||||
Actual: #{Formatter.error(actual.to_s)}
|
||||
File: #{path}
|
||||
To retry an incomplete download, remove the file above.
|
||||
If the issue persists, visit:
|
||||
#{Formatter.url("https://github.com/Homebrew/homebrew-cask/blob/HEAD/doc/reporting_bugs/checksum_does_not_match_error.md")}
|
||||
EOS
|
||||
end
|
||||
end
|
||||
|
||||
# Error when a cask has no checksum and the `--require-sha` flag is passed.
|
||||
#
|
||||
# @api private
|
||||
class CaskNoShasumError < CaskSha256Error
|
||||
extend T::Sig
|
||||
|
||||
sig { returns(String) }
|
||||
def to_s
|
||||
<<~EOS
|
||||
Cask '#{token}' does not have a sha256 checksum defined and was not installed.
|
||||
This means you have the #{Formatter.identifier("--require-sha")} option set, perhaps in your HOMEBREW_CASK_OPTS.
|
||||
EOS
|
||||
end
|
||||
end
|
||||
|
||||
# Error during quarantining of a file.
|
||||
#
|
||||
# @api private
|
||||
|
||||
@ -163,7 +163,10 @@ module Cask
|
||||
odebug "Checking cask has checksum"
|
||||
return unless @cask.sha256 == :no_check
|
||||
|
||||
raise CaskNoShasumError, @cask.token
|
||||
raise CaskError, <<~EOS
|
||||
Cask '#{@cask}' does not have a sha256 checksum defined and was not installed.
|
||||
This means you have the #{Formatter.identifier("--require-sha")} option set, perhaps in your HOMEBREW_CASK_OPTS.
|
||||
EOS
|
||||
end
|
||||
|
||||
def primary_container
|
||||
|
||||
@ -617,15 +617,15 @@ class ChecksumMissingError < ArgumentError; end
|
||||
class ChecksumMismatchError < RuntimeError
|
||||
attr_reader :expected, :hash_type
|
||||
|
||||
def initialize(fn, expected, actual)
|
||||
def initialize(path, expected, actual)
|
||||
@expected = expected
|
||||
@hash_type = expected.hash_type.to_s.upcase
|
||||
|
||||
super <<~EOS
|
||||
#{@hash_type} mismatch
|
||||
Expected: #{expected}
|
||||
Actual: #{actual}
|
||||
Archive: #{fn}
|
||||
Expected: #{Formatter.success(expected.to_s)}
|
||||
Actual: #{Formatter.error(actual.to_s)}
|
||||
File: #{path}
|
||||
To retry an incomplete download, remove the file above.
|
||||
EOS
|
||||
end
|
||||
|
||||
@ -146,13 +146,16 @@ class Resource
|
||||
|
||||
def verify_download_integrity(fn)
|
||||
if fn.file?
|
||||
ohai "Verifying #{fn.basename} checksum" if verbose?
|
||||
ohai "Verifying checksum for '#{fn.basename}'." if verbose?
|
||||
fn.verify_checksum(checksum)
|
||||
end
|
||||
rescue ChecksumMissingError
|
||||
opoo "Cannot verify integrity of #{fn.basename}"
|
||||
puts "A checksum was not provided for this resource."
|
||||
puts "For your reference the SHA-256 is: #{fn.sha256}"
|
||||
opoo <<~EOS
|
||||
Cannot verify integrity of '#{fn.basename}'.
|
||||
No checksum was provided for this resource.
|
||||
For your reference, the checksum is:
|
||||
sha256 "#{fn.sha256}"
|
||||
EOS
|
||||
end
|
||||
|
||||
Checksum::TYPES.each do |type|
|
||||
|
||||
@ -344,7 +344,7 @@ describe Cask::Cmd::Upgrade, :cask do
|
||||
|
||||
expect {
|
||||
described_class.run("bad-checksum")
|
||||
}.to raise_error(Cask::CaskSha256MismatchError).and(not_to_output(output_reverted).to_stderr)
|
||||
}.to raise_error(ChecksumMismatchError).and(not_to_output(output_reverted).to_stderr)
|
||||
|
||||
expect(bad_checksum).to be_installed
|
||||
expect(bad_checksum_path).to be_a_directory
|
||||
|
||||
@ -35,16 +35,16 @@ module Cask
|
||||
context "when the expected checksum is nil" do
|
||||
let(:expected_sha256) { nil }
|
||||
|
||||
it "raises an error" do
|
||||
expect { verification }.to raise_error(CaskSha256MissingError, /sha256 "#{computed_sha256}"/)
|
||||
it "outputs an error" do
|
||||
expect { verification }.to output(/sha256 "#{computed_sha256}"/).to_stderr
|
||||
end
|
||||
end
|
||||
|
||||
context "when the expected checksum is empty" do
|
||||
let(:expected_sha256) { Checksum.new(:sha256, "") }
|
||||
|
||||
it "raises an error" do
|
||||
expect { verification }.to raise_error(CaskSha256MissingError, /sha256 "#{computed_sha256}"/)
|
||||
it "outputs an error" do
|
||||
expect { verification }.to output(/sha256 "#{computed_sha256}"/).to_stderr
|
||||
end
|
||||
end
|
||||
|
||||
@ -52,7 +52,7 @@ module Cask
|
||||
let(:expected_sha256) { Checksum.new(:sha256, deadbeef) }
|
||||
|
||||
it "raises an error" do
|
||||
expect { verification }.to raise_error CaskSha256MismatchError
|
||||
expect { verification }.to raise_error ChecksumMismatchError
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -65,14 +65,14 @@ describe Cask::Installer, :cask do
|
||||
bad_checksum = Cask::CaskLoader.load(cask_path("bad-checksum"))
|
||||
expect {
|
||||
described_class.new(bad_checksum).install
|
||||
}.to raise_error(Cask::CaskSha256MismatchError)
|
||||
}.to raise_error(ChecksumMismatchError)
|
||||
end
|
||||
|
||||
it "blows up on a missing checksum" do
|
||||
missing_checksum = Cask::CaskLoader.load(cask_path("missing-checksum"))
|
||||
expect {
|
||||
described_class.new(missing_checksum).install
|
||||
}.to raise_error(Cask::CaskSha256MissingError)
|
||||
}.to output(/Cannot verify integrity/).to_stderr
|
||||
end
|
||||
|
||||
it "installs fine if sha256 :no_check is used" do
|
||||
@ -87,7 +87,7 @@ describe Cask::Installer, :cask do
|
||||
no_checksum = Cask::CaskLoader.load(cask_path("no-checksum"))
|
||||
expect {
|
||||
described_class.new(no_checksum, require_sha: true).install
|
||||
}.to raise_error(Cask::CaskNoShasumError)
|
||||
}.to raise_error(/--require-sha/)
|
||||
end
|
||||
|
||||
it "installs fine if sha256 :no_check is used with --require-sha and --force" do
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user