cask audit: installer and pkg require uninstall

This commit is contained in:
commitay 2018-05-19 12:38:47 +10:00
parent ed830c7831
commit 1ae2cf9709
4 changed files with 63 additions and 0 deletions

View File

@ -36,6 +36,7 @@ module Hbc
check_untrusted_pkg
check_github_releases_appcast
check_latest_with_appcast
check_stanza_requires_uninstall
self
rescue StandardError => e
odebug "#{e.message}\n#{e.backtrace.join("\n")}"
@ -65,6 +66,14 @@ module Hbc
add_warning "allow_untrusted is not permitted in official Homebrew-Cask taps"
end
def check_stanza_requires_uninstall
odebug "Auditing stanzas which require an uninstall"
return if cask.artifacts.none? { |k| k.is_a?(Hbc::Artifact::Pkg) || k.is_a?(Hbc::Artifact::Installer) }
return if cask.artifacts.any? { |k| k.is_a?(Hbc::Artifact::Uninstall) }
add_warning "installer and pkg stanzas require an uninstall stanza"
end
def check_single_pre_postflight
odebug "Auditing preflight and postflight stanzas"

View File

@ -115,6 +115,40 @@ describe Hbc::Audit, :cask do
end
end
describe "when the Cask stanza requires uninstall" do
let(:error_msg) { "installer and pkg stanzas require an uninstall stanza" }
context "when the Cask does not require an uninstall" do
let(:cask_token) { "basic-cask" }
it { is_expected.not_to warn_with(error_msg) }
end
context "when the pkg Cask has an uninstall" do
let(:cask_token) { "with-uninstall-pkgutil" }
it { is_expected.not_to warn_with(error_msg) }
end
context "when the installer Cask has an uninstall" do
let(:cask_token) { "installer-with-uninstall" }
it { is_expected.not_to warn_with(error_msg) }
end
context "when the installer Cask does not have an uninstall" do
let(:cask_token) { "with-installer-manual" }
it { is_expected.to warn_with(error_msg) }
end
context "when the pkg Cask does not have an uninstall" do
let(:cask_token) { "pkg-without-uninstall" }
it { is_expected.to warn_with(error_msg) }
end
end
describe "preflight stanza checks" do
let(:error_msg) { "only a single preflight stanza is allowed" }

View File

@ -0,0 +1,11 @@
cask 'installer-with-uninstall' do
version '1.2.3'
sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
homepage 'http://example.com/local-caffeine'
installer manual: 'Caffeine.app'
uninstall delete: '/Applications/Caffeine.app'
end

View File

@ -0,0 +1,9 @@
cask 'pkg-without-uninstall' do
version '1.2.3'
sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b'
url "file://#{TEST_FIXTURE_DIR}/cask/MyFancyPkg.zip"
homepage 'http://example.com/fancy-pkg'
pkg 'Fancy.pkg'
end