From 1ae2cf97090885beb0ea1cbec9fb8692744d8183 Mon Sep 17 00:00:00 2001 From: commitay Date: Sat, 19 May 2018 12:38:47 +1000 Subject: [PATCH] cask audit: installer and pkg require uninstall --- Library/Homebrew/cask/lib/hbc/audit.rb | 9 +++++ Library/Homebrew/test/cask/audit_spec.rb | 34 +++++++++++++++++++ .../cask/Casks/installer-with-uninstall.rb | 11 ++++++ .../cask/Casks/pkg-without-uninstall.rb | 9 +++++ 4 files changed, 63 insertions(+) create mode 100644 Library/Homebrew/test/support/fixtures/cask/Casks/installer-with-uninstall.rb create mode 100644 Library/Homebrew/test/support/fixtures/cask/Casks/pkg-without-uninstall.rb diff --git a/Library/Homebrew/cask/lib/hbc/audit.rb b/Library/Homebrew/cask/lib/hbc/audit.rb index d83bcd5e0f..742f1e6857 100644 --- a/Library/Homebrew/cask/lib/hbc/audit.rb +++ b/Library/Homebrew/cask/lib/hbc/audit.rb @@ -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" diff --git a/Library/Homebrew/test/cask/audit_spec.rb b/Library/Homebrew/test/cask/audit_spec.rb index 751a31241f..7ec1675a97 100644 --- a/Library/Homebrew/test/cask/audit_spec.rb +++ b/Library/Homebrew/test/cask/audit_spec.rb @@ -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" } diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/installer-with-uninstall.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/installer-with-uninstall.rb new file mode 100644 index 0000000000..9e249fc3fb --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/installer-with-uninstall.rb @@ -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 diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/pkg-without-uninstall.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/pkg-without-uninstall.rb new file mode 100644 index 0000000000..9b62304de9 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/pkg-without-uninstall.rb @@ -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