From 97ec11fb588dc9317490479a02355a1e3afdbe53 Mon Sep 17 00:00:00 2001 From: Josh Hagins Date: Sat, 2 Jan 2016 18:36:52 -0500 Subject: [PATCH 01/18] Add `sudo` test helper to prepend command args with `/usr/bin/sudo -E --` --- test/test_helper.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/test_helper.rb b/test/test_helper.rb index b39cd0620af..80dc1a5b145 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -41,6 +41,10 @@ def shutup end end +def sudo(cmd) + %w[/usr/bin/sudo -E --] + Array(cmd) +end + # making homebrew's cache dir allows us to actually download Casks in tests HOMEBREW_CACHE.mkpath HOMEBREW_CACHE.join('Casks').mkpath From ba88ea2a70a1c06ecd1e0693e0834a7f3430218e Mon Sep 17 00:00:00 2001 From: Josh Hagins Date: Sat, 2 Jan 2016 18:37:10 -0500 Subject: [PATCH 02/18] Clean up uninstall_test.rb --- test/cask/artifact/uninstall_test.rb | 294 +++++++++++++-------------- 1 file changed, 146 insertions(+), 148 deletions(-) diff --git a/test/cask/artifact/uninstall_test.rb b/test/cask/artifact/uninstall_test.rb index 540413222d6..73115a73c49 100644 --- a/test/cask/artifact/uninstall_test.rb +++ b/test/cask/artifact/uninstall_test.rb @@ -1,16 +1,17 @@ require 'test_helper' describe Hbc::Artifact::Uninstall do + let(:cask) { Hbc.load('with-installable') } + let(:uninstall_artifact) { Hbc::Artifact::Uninstall.new(cask, Hbc::FakeSystemCommand) } + before { - @cask = Hbc.load('with-installable') shutup do - TestHelper.install_without_artifacts(@cask) + TestHelper.install_without_artifacts(cask) end } describe 'install_phase' do it 'does nothing, because the install_phase method is a no-op' do - uninstall_artifact = Hbc::Artifact::Uninstall.new(@cask, Hbc::FakeSystemCommand) shutup do uninstall_artifact.install_phase end @@ -19,7 +20,6 @@ describe Hbc::Artifact::Uninstall do describe 'zap_phase' do it 'does nothing, because the zap_phase method is a no-op' do - uninstall_artifact = Hbc::Artifact::Uninstall.new(@cask, Hbc::FakeSystemCommand) shutup do uninstall_artifact.zap_phase end @@ -27,168 +27,166 @@ describe Hbc::Artifact::Uninstall do end describe 'uninstall_phase' do + subject { + shutup do + uninstall_artifact.uninstall_phase + end + } # todo: uninstall tests for :signal (implementation does not use SystemCommand) it 'runs the specified uninstaller for the Cask' do - uninstall_artifact = Hbc::Artifact::Uninstall.new(@cask, Hbc::FakeSystemCommand) - - Hbc::FakeSystemCommand.stubs_command(['/usr/bin/sudo', '-E', '--', '/usr/bin/osascript', '-e', 'tell application "System Events" to count processes whose bundle identifier is "my.fancy.package.app"'], '1') - Hbc::FakeSystemCommand.stubs_command(['/usr/bin/sudo', '-E', '--', '/usr/bin/osascript', '-e', 'tell application id "my.fancy.package.app" to quit']) + Hbc::FakeSystemCommand.stubs_command(sudo(['/usr/bin/osascript', '-e', 'tell application "System Events" to count processes whose bundle identifier is "my.fancy.package.app"']), '1') + Hbc::FakeSystemCommand.stubs_command(sudo(['/usr/bin/osascript', '-e', 'tell application id "my.fancy.package.app" to quit'])) Hbc::FakeSystemCommand.expects_command(['/usr/bin/osascript', '-e', 'tell application "System Events" to delete every login item whose name is "Fancy"']) - Hbc::FakeSystemCommand.expects_command(['/usr/bin/sudo', '-E', '--', @cask.staged_path.join('MyFancyPkg','FancyUninstaller.tool'), '--please']) - Hbc::FakeSystemCommand.expects_command(['/usr/bin/sudo', '-E', '--', '/bin/rm', '-rf', '--', Pathname.new('/permissible/absolute/path'), Pathname.new('~/permissible/path/with/tilde').expand_path]) - Hbc::FakeSystemCommand.expects_command(['/usr/bin/sudo', '-E', '--', '/bin/rm', '-f', '--', Pathname.new(TestHelper.local_binary_path('empty_directory')).join('.DS_Store')]) - Hbc::FakeSystemCommand.expects_command(['/usr/bin/sudo', '-E', '--', '/bin/rmdir', '--', Pathname.new(TestHelper.local_binary_path('empty_directory'))]) + Hbc::FakeSystemCommand.expects_command(sudo([cask.staged_path.join('MyFancyPkg','FancyUninstaller.tool'), '--please'])) + Hbc::FakeSystemCommand.expects_command(sudo(['/bin/rm', '-rf', '--', Pathname.new('/permissible/absolute/path'), Pathname.new('~/permissible/path/with/tilde').expand_path])) + Hbc::FakeSystemCommand.expects_command(sudo(['/bin/rm', '-f', '--', Pathname.new(TestHelper.local_binary_path('empty_directory')).join('.DS_Store')])) + Hbc::FakeSystemCommand.expects_command(sudo(['/bin/rmdir', '--', Pathname.new(TestHelper.local_binary_path('empty_directory'))])) - shutup do - uninstall_artifact.uninstall_phase - end + subject end - it 'can uninstall using pkgutil, launchctl, and file lists' do - cask = Hbc.load('with-pkgutil-uninstall') - uninstall_artifact = Hbc::Artifact::Uninstall.new(cask, Hbc::FakeSystemCommand) + describe 'when using pkgutil, launchutil, and kext' do + let(:cask) { Hbc.load('with-pkgutil-uninstall') } - Hbc::FakeSystemCommand.stubs_command( - ['/usr/sbin/pkgutil', '--pkgs=my.fancy.package.*'], - [ - 'my.fancy.package.main', - 'my.fancy.package.agent', - ].join("\n") - ) + it 'can uninstall' do + Hbc::FakeSystemCommand.stubs_command( + ['/usr/sbin/pkgutil', '--pkgs=my.fancy.package.*'], + <<-FILES.undent + my.fancy.package.main + my.fancy.package.agent + FILES + ) - Hbc::FakeSystemCommand.stubs_command( - ['/usr/sbin/pkgutil', '--only-files', '--files', 'my.fancy.package.main'], - [ - 'fancy/bin/fancy.exe', - 'fancy/var/fancy.data', - ].join("\n") - ) - Hbc::FakeSystemCommand.stubs_command( - ['/usr/sbin/pkgutil', '--only-dirs', '--files', 'my.fancy.package.main'], - [ - 'fancy', - 'fancy/bin', - 'fancy/var', - ].join("\n") - ) - Hbc::FakeSystemCommand.stubs_command( - ['/usr/sbin/pkgutil', '--files', 'my.fancy.package.main'], - [ - 'fancy', - 'fancy/bin', - 'fancy/var', - 'fancy/bin/fancy.exe', - 'fancy/var/fancy.data', - ].join("\n") - ) - Hbc::FakeSystemCommand.stubs_command( - ['/usr/sbin/pkgutil', '--pkg-info-plist', 'my.fancy.package.main'], - <<-PLIST - - - - - install-location - tmp - volume - / - - - PLIST - ) + Hbc::FakeSystemCommand.stubs_command( + ['/usr/sbin/pkgutil', '--only-files', '--files', 'my.fancy.package.main'], + <<-FILES.undent + fancy/bin/fancy.exe + fancy/var/fancy.data + FILES + ) + Hbc::FakeSystemCommand.stubs_command( + ['/usr/sbin/pkgutil', '--only-dirs', '--files', 'my.fancy.package.main'], + <<-FILES.undent + fancy + fancy/bin + fancy/var + FILES + ) + Hbc::FakeSystemCommand.stubs_command( + ['/usr/sbin/pkgutil', '--files', 'my.fancy.package.main'], + <<-FILES.undent + fancy + fancy/bin + fancy/var + fancy/bin/fancy.exe + fancy/var/fancy.data + FILES + ) + Hbc::FakeSystemCommand.stubs_command( + ['/usr/sbin/pkgutil', '--pkg-info-plist', 'my.fancy.package.main'], + <<-PLIST.undent + + + + + install-location + tmp + volume + / + + + PLIST + ) - Hbc::FakeSystemCommand.stubs_command( - ['/bin/launchctl', 'list', 'my.fancy.package.service'], - "launchctl list returned unknown response\n" - ) - Hbc::FakeSystemCommand.stubs_command( - ['/usr/bin/sudo', '-E', '--', '/bin/launchctl', 'list', 'my.fancy.package.service'], - <<-"PLIST" -{ - "LimitLoadToSessionType" = "Aqua"; - "Label" = "my.fancy.package.service"; - "TimeOut" = 30; - "OnDemand" = true; - "LastExitStatus" = 0; - "ProgramArguments" = ( - "argument"; - ); -}; - PLIST - ) + Hbc::FakeSystemCommand.stubs_command( + ['/bin/launchctl', 'list', 'my.fancy.package.service'], + "launchctl list returned unknown response\n" + ) + Hbc::FakeSystemCommand.stubs_command( + sudo(['/bin/launchctl', 'list', 'my.fancy.package.service']), + <<-PLIST.undent + { + "LimitLoadToSessionType" = "Aqua"; + "Label" = "my.fancy.package.service"; + "TimeOut" = 30; + "OnDemand" = true; + "LastExitStatus" = 0; + "ProgramArguments" = ( + "argument"; + ); + }; + PLIST + ) - Hbc::FakeSystemCommand.expects_command(['/usr/bin/sudo', '-E', '--', '/bin/launchctl', 'remove', 'my.fancy.package.service']) + Hbc::FakeSystemCommand.expects_command(sudo(['/bin/launchctl', 'remove', 'my.fancy.package.service'])) - Hbc::FakeSystemCommand.stubs_command(['/usr/bin/sudo', '-E', '--', '/usr/sbin/kextstat', '-l', '-b', 'my.fancy.package.kernelextension'], 'loaded') - Hbc::FakeSystemCommand.expects_command(['/usr/bin/sudo', '-E', '--', '/sbin/kextunload', '-b', 'my.fancy.package.kernelextension']) - Hbc::FakeSystemCommand.stubs_command(['/usr/bin/sudo', '-E', '--', '/usr/sbin/pkgutil', '--forget', 'my.fancy.package.main']) + Hbc::FakeSystemCommand.stubs_command(sudo(['/usr/sbin/kextstat', '-l', '-b', 'my.fancy.package.kernelextension']), 'loaded') + Hbc::FakeSystemCommand.expects_command(sudo(['/sbin/kextunload', '-b', 'my.fancy.package.kernelextension'])) + Hbc::FakeSystemCommand.stubs_command(sudo(['/usr/sbin/pkgutil', '--forget', 'my.fancy.package.main'])) - Hbc::FakeSystemCommand.stubs_command( - ['/usr/sbin/pkgutil', '--only-files', '--files', 'my.fancy.package.agent'], - [ - 'fancy/agent/fancy-agent.exe', - 'fancy/agent/fancy-agent.pid', - 'fancy/agent/fancy-agent.log', - ].join("\n") - ) - Hbc::FakeSystemCommand.stubs_command( - ['/usr/sbin/pkgutil', '--only-dirs', '--files', 'my.fancy.package.agent'], - [ - 'fancy', - 'fancy/agent', - ].join("\n") - ) - Hbc::FakeSystemCommand.stubs_command( - ['/usr/sbin/pkgutil', '--files', 'my.fancy.package.agent'], - [ - 'fancy', - 'fancy/agent', - 'fancy/agent/fancy-agent.exe', - 'fancy/agent/fancy-agent.pid', - 'fancy/agent/fancy-agent.log', - ].join("\n") - ) - Hbc::FakeSystemCommand.stubs_command( - ['/usr/sbin/pkgutil', '--pkg-info-plist', 'my.fancy.package.agent'], - <<-PLIST - - - - - install-location - tmp - volume - / - - - PLIST - ) + Hbc::FakeSystemCommand.stubs_command( + ['/usr/sbin/pkgutil', '--only-files', '--files', 'my.fancy.package.agent'], + <<-FILES.undent + fancy/agent/fancy-agent.exe + fancy/agent/fancy-agent.pid + fancy/agent/fancy-agent.log + FILES + ) + Hbc::FakeSystemCommand.stubs_command( + ['/usr/sbin/pkgutil', '--only-dirs', '--files', 'my.fancy.package.agent'], + <<-FILES.undent + fancy + fancy/agent + FILES + ) + Hbc::FakeSystemCommand.stubs_command( + ['/usr/sbin/pkgutil', '--files', 'my.fancy.package.agent'], + <<-FILES.undent + fancy + fancy/agent + fancy/agent/fancy-agent.exe + fancy/agent/fancy-agent.pid + fancy/agent/fancy-agent.log + FILES + ) + Hbc::FakeSystemCommand.stubs_command( + ['/usr/sbin/pkgutil', '--pkg-info-plist', 'my.fancy.package.agent'], + <<-PLIST.undent + + + + + install-location + tmp + volume + / + + + PLIST + ) - %w[ - /tmp/fancy - /tmp/fancy/agent - /tmp/fancy/bin - /tmp/fancy/var - ].each do |dir| - Hbc::FakeSystemCommand.stubs_command(['/usr/bin/sudo', '-E', '--', '/bin/chmod', '--', '777', '#{dir}']) - end + %w[ + /tmp/fancy + /tmp/fancy/agent + /tmp/fancy/bin + /tmp/fancy/var + ].each do |dir| + Hbc::FakeSystemCommand.stubs_command(sudo(['/bin/chmod', '--', '777', '#{dir}'])) + end - Hbc::FakeSystemCommand.stubs_command(['/usr/bin/sudo', '-E', '--', '/usr/sbin/pkgutil', '--forget', 'my.fancy.package.agent']) + Hbc::FakeSystemCommand.stubs_command(sudo(['/usr/sbin/pkgutil', '--forget', 'my.fancy.package.agent'])) - Hbc::FakeSystemCommand.stubs_command(['/usr/bin/sudo', '-E', '--', '/bin/rm', '-f', '--', - Pathname.new('/tmp/fancy/bin/fancy.exe'), - Pathname.new('/tmp/fancy/var/fancy.data')]) - Hbc::FakeSystemCommand.stubs_command(['/usr/bin/sudo', '-E', '--', '/bin/rm', '-f', '--', - Pathname.new('/tmp/fancy/agent/fancy-agent.exe'), - Pathname.new('/tmp/fancy/agent/fancy-agent.pid'), - Pathname.new('/tmp/fancy/agent/fancy-agent.log')]) + Hbc::FakeSystemCommand.stubs_command(sudo(['/bin/rm', '-f', '--', + Pathname.new('/tmp/fancy/bin/fancy.exe'), + Pathname.new('/tmp/fancy/var/fancy.data')])) + Hbc::FakeSystemCommand.stubs_command(sudo(['/bin/rm', '-f', '--', + Pathname.new('/tmp/fancy/agent/fancy-agent.exe'), + Pathname.new('/tmp/fancy/agent/fancy-agent.pid'), + Pathname.new('/tmp/fancy/agent/fancy-agent.log')])) - # No assertions after call since all assertions are implicit from the interactions setup above. - # TODO: verify rmdir commands (requires setting up actual file tree or faking out .exists? - shutup do - uninstall_artifact.uninstall_phase + subject end end end From 6f115757ed48663cc752db3823fae9d2c67847dd Mon Sep 17 00:00:00 2001 From: Josh Hagins Date: Sat, 2 Jan 2016 18:38:14 -0500 Subject: [PATCH 03/18] Extract tests specific to uninstall :launchctl --- test/cask/artifact/uninstall_test.rb | 85 +++++++++++++++++++ .../support/Casks/with-uninstall-launchctl.rb | 11 +++ 2 files changed, 96 insertions(+) create mode 100644 test/support/Casks/with-uninstall-launchctl.rb diff --git a/test/cask/artifact/uninstall_test.rb b/test/cask/artifact/uninstall_test.rb index 73115a73c49..85d231924d7 100644 --- a/test/cask/artifact/uninstall_test.rb +++ b/test/cask/artifact/uninstall_test.rb @@ -47,6 +47,91 @@ describe Hbc::Artifact::Uninstall do subject end + describe 'when using launchctl' do + let(:cask) { Hbc.load('with-uninstall-launchctl') } + let(:launchctl_list_cmd) { %w[/bin/launchctl list my.fancy.package.service] } + let(:launchctl_remove_cmd) { %w[/bin/launchctl remove my.fancy.package.service]} + let(:unknown_response) { "launchctl list returned unknown response\n" } + let(:service_info) { + <<-PLIST.undent + { + "LimitLoadToSessionType" = "Aqua"; + "Label" = "my.fancy.package.service"; + "TimeOut" = 30; + "OnDemand" = true; + "LastExitStatus" = 0; + "ProgramArguments" = ( + "argument"; + ); + }; + PLIST + } + + describe 'when launchctl job is owned by user' do + it 'can uninstall' do + Hbc::FakeSystemCommand.stubs_command( + launchctl_list_cmd, + service_info) + + Hbc::FakeSystemCommand.stubs_command( + sudo(launchctl_list_cmd), + unknown_response) + + Hbc::FakeSystemCommand.expects_command(launchctl_remove_cmd) + + subject + end + end + + describe 'when launchctl job is owned by system' do + it 'can uninstall' do + Hbc::FakeSystemCommand.stubs_command( + launchctl_list_cmd, + unknown_response) + + Hbc::FakeSystemCommand.stubs_command( + sudo(launchctl_list_cmd), + service_info) + + Hbc::FakeSystemCommand.expects_command(sudo(launchctl_remove_cmd)) + + subject + end + end + end + + describe 'when using pkgutil' do + # todo + end + + describe 'when using quit' do + # todo + end + + describe 'when using signal' do + # todo + end + + describe 'when using kext' do + # todo + end + + describe 'when using delete' do + # todo + end + + describe 'when using rmdir' do + # todo + end + + describe 'when using script' do + # todo + end + + describe 'when using early_script' do + # todo + end + describe 'when using pkgutil, launchutil, and kext' do let(:cask) { Hbc.load('with-pkgutil-uninstall') } diff --git a/test/support/Casks/with-uninstall-launchctl.rb b/test/support/Casks/with-uninstall-launchctl.rb new file mode 100644 index 00000000000..cf388a951c2 --- /dev/null +++ b/test/support/Casks/with-uninstall-launchctl.rb @@ -0,0 +1,11 @@ +test_cask 'with-uninstall-launchctl' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyApp.zip') + homepage 'http://example.com/fancy' + + app 'Fancy.app' + + uninstall :launchctl => 'my.fancy.package.service' +end From b1fccc4ee787e37c29255bda6694953150821c4c Mon Sep 17 00:00:00 2001 From: Josh Hagins Date: Sat, 2 Jan 2016 19:21:18 -0500 Subject: [PATCH 04/18] Extract tests specific to uninstall :pkgutil --- test/cask/artifact/uninstall_test.rb | 78 +++++++++++++++++++- test/support/Casks/with-uninstall-pkgutil.rb | 10 +++ 2 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 test/support/Casks/with-uninstall-pkgutil.rb diff --git a/test/cask/artifact/uninstall_test.rb b/test/cask/artifact/uninstall_test.rb index 85d231924d7..33656cfda44 100644 --- a/test/cask/artifact/uninstall_test.rb +++ b/test/cask/artifact/uninstall_test.rb @@ -101,7 +101,83 @@ describe Hbc::Artifact::Uninstall do end describe 'when using pkgutil' do - # todo + let(:cask) { Hbc.load('with-uninstall-pkgutil') } + let(:main_pkg_id) { 'my.fancy.package.main' } + let(:agent_pkg_id) { 'my.fancy.package.agent' } + let(:main_files) { + %w[ + fancy/bin/fancy.exe + fancy/var/fancy.data + ] + } + let(:main_dirs) { + %w[ + fancy + fancy/bin + fancy/var + ] + } + let(:agent_files) { + %w[ + fancy/agent/fancy-agent.exe + fancy/agent/fancy-agent.pid + fancy/agent/fancy-agent.log + ] + } + let(:agent_dirs) { + %w[ + fancy + fancy/agent + ] + } + let(:pkg_info_plist) { + <<-PLIST.undent + + + + + install-location + tmp + volume + / + + + PLIST + } + + it 'can uninstall' do + Hbc::FakeSystemCommand.stubs_command( + %w[/usr/sbin/pkgutil --pkgs=my.fancy.package.*], + "#{main_pkg_id}\n#{agent_pkg_id}") + + [ + [main_pkg_id, main_files, main_dirs], + [agent_pkg_id, agent_files, agent_dirs] + ].each do |pkg_id, pkg_files, pkg_dirs| + Hbc::FakeSystemCommand.stubs_command( + %W[/usr/sbin/pkgutil --only-files --files #{pkg_id}], + pkg_files.join("\n")) + + Hbc::FakeSystemCommand.stubs_command( + %W[/usr/sbin/pkgutil --only-dirs --files #{pkg_id}], + pkg_dirs.join("\n")) + + Hbc::FakeSystemCommand.stubs_command( + %W[/usr/sbin/pkgutil --files #{pkg_id}], + (pkg_files + pkg_dirs).join("\n")) + + Hbc::FakeSystemCommand.stubs_command( + %W[/usr/sbin/pkgutil --pkg-info-plist #{pkg_id}], + pkg_info_plist) + + Hbc::FakeSystemCommand.expects_command(sudo(%W[/usr/sbin/pkgutil --forget #{pkg_id}])) + + Hbc::FakeSystemCommand.expects_command( + sudo(%w[/bin/rm -f --] + pkg_files.map { |path| Pathname("/tmp/#{path}")})) + end + + subject + end end describe 'when using quit' do diff --git a/test/support/Casks/with-uninstall-pkgutil.rb b/test/support/Casks/with-uninstall-pkgutil.rb new file mode 100644 index 00000000000..f65586dc253 --- /dev/null +++ b/test/support/Casks/with-uninstall-pkgutil.rb @@ -0,0 +1,10 @@ +test_cask 'with-uninstall-pkgutil' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'Fancy.pkg' + uninstall :pkgutil => 'my.fancy.package.*' +end From fd9650d8758632ac2309cd4b75b706e8c2cd6fbb Mon Sep 17 00:00:00 2001 From: Josh Hagins Date: Sat, 2 Jan 2016 19:39:14 -0500 Subject: [PATCH 05/18] Extract tests specific to uninstall :kext --- test/cask/artifact/uninstall_test.rb | 19 +++++++++++++++---- test/support/Casks/with-uninstall-kext.rb | 10 ++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 test/support/Casks/with-uninstall-kext.rb diff --git a/test/cask/artifact/uninstall_test.rb b/test/cask/artifact/uninstall_test.rb index 33656cfda44..9bf9d3685f7 100644 --- a/test/cask/artifact/uninstall_test.rb +++ b/test/cask/artifact/uninstall_test.rb @@ -180,6 +180,21 @@ describe Hbc::Artifact::Uninstall do end end + describe 'when using kext' do + let(:cask) { Hbc.load('with-uninstall-kext') } + let(:kext_id) { 'my.fancy.package.kernelextension' } + + it 'can uninstall' do + Hbc::FakeSystemCommand.stubs_command( + sudo(%W[/usr/sbin/kextstat -l -b #{kext_id}]), 'loaded') + + Hbc::FakeSystemCommand.expects_command( + sudo(%W[/sbin/kextunload -b #{kext_id}])) + + subject + end + end + describe 'when using quit' do # todo end @@ -188,10 +203,6 @@ describe Hbc::Artifact::Uninstall do # todo end - describe 'when using kext' do - # todo - end - describe 'when using delete' do # todo end diff --git a/test/support/Casks/with-uninstall-kext.rb b/test/support/Casks/with-uninstall-kext.rb new file mode 100644 index 00000000000..d6be30fe690 --- /dev/null +++ b/test/support/Casks/with-uninstall-kext.rb @@ -0,0 +1,10 @@ +test_cask 'with-uninstall-kext' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'Fancy.pkg' + uninstall :kext => 'my.fancy.package.kernelextension' +end From c1bb87e2ac6b5d9199ebfaac40b8c13fac871827 Mon Sep 17 00:00:00 2001 From: Josh Hagins Date: Sat, 2 Jan 2016 20:09:25 -0500 Subject: [PATCH 06/18] Extract tests specific to uninstall :quit --- test/cask/artifact/uninstall_test.rb | 20 +++++++++++++++++++- test/support/Casks/with-uninstall-quit.rb | 11 +++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 test/support/Casks/with-uninstall-quit.rb diff --git a/test/cask/artifact/uninstall_test.rb b/test/cask/artifact/uninstall_test.rb index 9bf9d3685f7..bee52aa6876 100644 --- a/test/cask/artifact/uninstall_test.rb +++ b/test/cask/artifact/uninstall_test.rb @@ -196,7 +196,25 @@ describe Hbc::Artifact::Uninstall do end describe 'when using quit' do - # todo + let(:cask) { Hbc.load('with-uninstall-quit') } + let(:bundle_id) { 'my.fancy.package.app' } + let(:count_processes_script) { + 'tell application "System Events" to count processes ' + + %Q{whose bundle identifier is "#{bundle_id}"} + } + let(:quit_application_script) { + %Q{tell application id "#{bundle_id}" to quit} + } + + it 'can uninstall' do + Hbc::FakeSystemCommand.stubs_command( + sudo(%W[/usr/bin/osascript -e #{count_processes_script}]), '1') + + Hbc::FakeSystemCommand.stubs_command( + sudo(%W[/usr/bin/osascript -e #{quit_application_script}])) + + subject + end end describe 'when using signal' do diff --git a/test/support/Casks/with-uninstall-quit.rb b/test/support/Casks/with-uninstall-quit.rb new file mode 100644 index 00000000000..f41ed868bbd --- /dev/null +++ b/test/support/Casks/with-uninstall-quit.rb @@ -0,0 +1,11 @@ +test_cask 'with-uninstall-quit' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'MyFancyPkg/Fancy.pkg' + + uninstall :quit => 'my.fancy.package.app' +end From 970a221defa1c9dd4cb665ab64d36738b0bed708 Mon Sep 17 00:00:00 2001 From: Josh Hagins Date: Sat, 2 Jan 2016 22:13:58 -0500 Subject: [PATCH 07/18] Teach sudo helper to flatten argument list --- test/test_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index 80dc1a5b145..4149a386ef1 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -41,8 +41,8 @@ def shutup end end -def sudo(cmd) - %w[/usr/bin/sudo -E --] + Array(cmd) +def sudo(*args) + %w[/usr/bin/sudo -E --] + Array(args).flatten end # making homebrew's cache dir allows us to actually download Casks in tests From 096a2fbc0f540b0dbbdf179e31d625288a23e834 Mon Sep 17 00:00:00 2001 From: Josh Hagins Date: Sat, 2 Jan 2016 22:10:08 -0500 Subject: [PATCH 08/18] Extract tests specific to uninstall :delete --- test/cask/artifact/uninstall_test.rb | 11 ++++++++++- test/support/Casks/with-uninstall-delete.rb | 16 ++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 test/support/Casks/with-uninstall-delete.rb diff --git a/test/cask/artifact/uninstall_test.rb b/test/cask/artifact/uninstall_test.rb index bee52aa6876..f348f8b9442 100644 --- a/test/cask/artifact/uninstall_test.rb +++ b/test/cask/artifact/uninstall_test.rb @@ -222,7 +222,16 @@ describe Hbc::Artifact::Uninstall do end describe 'when using delete' do - # todo + let(:cask) { Hbc.load('with-uninstall-delete') } + + it 'can uninstall' do + Hbc::FakeSystemCommand.expects_command( + sudo(%w[/bin/rm -rf --], + Pathname.new('/permissible/absolute/path'), + Pathname.new('~/permissible/path/with/tilde').expand_path)) + + subject + end end describe 'when using rmdir' do diff --git a/test/support/Casks/with-uninstall-delete.rb b/test/support/Casks/with-uninstall-delete.rb new file mode 100644 index 00000000000..65310843dfd --- /dev/null +++ b/test/support/Casks/with-uninstall-delete.rb @@ -0,0 +1,16 @@ +test_cask 'with-uninstall-delete' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'Fancy.pkg' + + uninstall :delete => [ + '/permissible/absolute/path', + '~/permissible/path/with/tilde', + 'impermissible/relative/path', + '/another/impermissible/../relative/path', + ] +end From 8bd88ecec87fbbaf49d6430d99dc2463ce881e0c Mon Sep 17 00:00:00 2001 From: Josh Hagins Date: Sat, 2 Jan 2016 22:21:16 -0500 Subject: [PATCH 09/18] Extract tests specific to uninstall :rmdir --- test/cask/artifact/uninstall_test.rb | 13 ++++++++++++- test/support/Casks/with-uninstall-rmdir.rb | 10 ++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 test/support/Casks/with-uninstall-rmdir.rb diff --git a/test/cask/artifact/uninstall_test.rb b/test/cask/artifact/uninstall_test.rb index f348f8b9442..2c76dd60067 100644 --- a/test/cask/artifact/uninstall_test.rb +++ b/test/cask/artifact/uninstall_test.rb @@ -235,7 +235,18 @@ describe Hbc::Artifact::Uninstall do end describe 'when using rmdir' do - # todo + let(:cask) { Hbc.load('with-uninstall-rmdir') } + let(:dir_pathname) { Pathname(TestHelper.local_binary_path('empty_directory')) } + + it 'can uninstall' do + Hbc::FakeSystemCommand.expects_command( + sudo(%w[/bin/rm -f --], dir_pathname.join('.DS_Store'))) + + Hbc::FakeSystemCommand.expects_command( + sudo(%w[/bin/rmdir --], dir_pathname)) + + subject + end end describe 'when using script' do diff --git a/test/support/Casks/with-uninstall-rmdir.rb b/test/support/Casks/with-uninstall-rmdir.rb new file mode 100644 index 00000000000..58abc3daa97 --- /dev/null +++ b/test/support/Casks/with-uninstall-rmdir.rb @@ -0,0 +1,10 @@ +test_cask 'with-uninstall-rmdir' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'MyFancyPkg/Fancy.pkg' + uninstall :rmdir => TestHelper.local_binary_path('empty_directory') +end From 606d0da394cb1c92db9e68caf5b2fab45f933e0b Mon Sep 17 00:00:00 2001 From: Josh Hagins Date: Sat, 2 Jan 2016 22:46:55 -0500 Subject: [PATCH 10/18] Make uninstall_early_script delegate to uninstall_script --- lib/hbc/artifact/uninstall_base.rb | 25 ++++++++----------------- test/cask/artifact/uninstall_test.rb | 1 + 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/lib/hbc/artifact/uninstall_base.rb b/lib/hbc/artifact/uninstall_base.rb index a526cdc6f92..bde75e90981 100644 --- a/lib/hbc/artifact/uninstall_base.rb +++ b/lib/hbc/artifact/uninstall_base.rb @@ -225,19 +225,7 @@ class Hbc::Artifact::UninstallBase < Hbc::Artifact::Base # :early_script should not delete files, better defer that to :script. # If Cask writers never need :early_script it may be removed in the future. def uninstall_early_script(directives) - executable, script_arguments = self.class.read_script_arguments( - directives, - 'uninstall', - {:must_succeed => true, :sudo => true}, - {:print_stdout => true}, - :early_script - ) - ohai "Running uninstall script #{executable}" - raise Hbc::CaskInvalidError.new(@cask, "#{stanza} :early_script without :executable") if executable.nil? - executable_path = @cask.staged_path.join(executable) - @command.run('/bin/chmod', :args => ['+x', executable_path]) if File.exists?(executable_path) - @command.run(executable_path, script_arguments) - sleep 1 + uninstall_script(directives, directive_name: :early_script) end # :launchctl must come before :quit/:signal for cases where app would instantly re-launch @@ -335,14 +323,17 @@ class Hbc::Artifact::UninstallBase < Hbc::Artifact::Base end # :script must come before :pkgutil, :delete, or :trash so that the script file is not already deleted - def uninstall_script(directives) + def uninstall_script(directives, directive_name: :script) executable, script_arguments = self.class.read_script_arguments(directives, 'uninstall', {:must_succeed => true, :sudo => true}, {:print_stdout => true}, - :script) - raise Hbc::CaskInvalidError.new(@cask, "#{stanza} :script without :executable.") if executable.nil? - @command.run(@cask.staged_path.join(executable), script_arguments) + directive_name) + ohai "Running uninstall script #{executable}" + raise Hbc::CaskInvalidError.new(@cask, "#{stanza} :#{directive_name} without :executable.") if executable.nil? + executable_path = @cask.staged_path.join(executable) + @command.run('/bin/chmod', :args => ['+x', '--', executable_path]) if File.exists?(executable_path) + @command.run(executable_path, script_arguments) sleep 1 end diff --git a/test/cask/artifact/uninstall_test.rb b/test/cask/artifact/uninstall_test.rb index 2c76dd60067..b9504fdf329 100644 --- a/test/cask/artifact/uninstall_test.rb +++ b/test/cask/artifact/uninstall_test.rb @@ -39,6 +39,7 @@ describe Hbc::Artifact::Uninstall do Hbc::FakeSystemCommand.expects_command(['/usr/bin/osascript', '-e', 'tell application "System Events" to delete every login item whose name is "Fancy"']) + Hbc::FakeSystemCommand.expects_command(['/bin/chmod', '+x', '--', cask.staged_path.join('MyFancyPkg','FancyUninstaller.tool')]) Hbc::FakeSystemCommand.expects_command(sudo([cask.staged_path.join('MyFancyPkg','FancyUninstaller.tool'), '--please'])) Hbc::FakeSystemCommand.expects_command(sudo(['/bin/rm', '-rf', '--', Pathname.new('/permissible/absolute/path'), Pathname.new('~/permissible/path/with/tilde').expand_path])) Hbc::FakeSystemCommand.expects_command(sudo(['/bin/rm', '-f', '--', Pathname.new(TestHelper.local_binary_path('empty_directory')).join('.DS_Store')])) From b63baa8e1fe3711bb72de028d265e445288b710d Mon Sep 17 00:00:00 2001 From: Josh Hagins Date: Sat, 2 Jan 2016 22:47:12 -0500 Subject: [PATCH 11/18] Extract tests specific to uninstall :script and :early_script --- test/cask/artifact/uninstall_test.rb | 24 +++++++++++++++++-- .../Casks/with-uninstall-early-script.rb | 11 +++++++++ test/support/Casks/with-uninstall-script.rb | 11 +++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 test/support/Casks/with-uninstall-early-script.rb create mode 100644 test/support/Casks/with-uninstall-script.rb diff --git a/test/cask/artifact/uninstall_test.rb b/test/cask/artifact/uninstall_test.rb index b9504fdf329..af1eb7cc711 100644 --- a/test/cask/artifact/uninstall_test.rb +++ b/test/cask/artifact/uninstall_test.rb @@ -251,11 +251,31 @@ describe Hbc::Artifact::Uninstall do end describe 'when using script' do - # todo + let(:cask) { Hbc.load('with-uninstall-script') } + let(:script_pathname) { cask.staged_path.join('MyFancyPkg','FancyUninstaller.tool') } + + it 'can uninstall' do + Hbc::FakeSystemCommand.expects_command(%w[/bin/chmod +x --] + [script_pathname]) + + Hbc::FakeSystemCommand.expects_command( + sudo(cask.staged_path.join('MyFancyPkg','FancyUninstaller.tool'), '--please')) + + subject + end end describe 'when using early_script' do - # todo + let(:cask) { Hbc.load('with-uninstall-early-script') } + let(:script_pathname) { cask.staged_path.join('MyFancyPkg','FancyUninstaller.tool') } + + it 'can uninstall' do + Hbc::FakeSystemCommand.expects_command(%w[/bin/chmod +x --] + [script_pathname]) + + Hbc::FakeSystemCommand.expects_command( + sudo(cask.staged_path.join('MyFancyPkg','FancyUninstaller.tool'), '--please')) + + subject + end end describe 'when using pkgutil, launchutil, and kext' do diff --git a/test/support/Casks/with-uninstall-early-script.rb b/test/support/Casks/with-uninstall-early-script.rb new file mode 100644 index 00000000000..c201141a2bb --- /dev/null +++ b/test/support/Casks/with-uninstall-early-script.rb @@ -0,0 +1,11 @@ +test_cask 'with-uninstall-early-script' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'MyFancyPkg/Fancy.pkg' + + uninstall :early_script => { :executable => 'MyFancyPkg/FancyUninstaller.tool', :args => %w[--please] } +end diff --git a/test/support/Casks/with-uninstall-script.rb b/test/support/Casks/with-uninstall-script.rb new file mode 100644 index 00000000000..dc319c782b2 --- /dev/null +++ b/test/support/Casks/with-uninstall-script.rb @@ -0,0 +1,11 @@ +test_cask 'with-uninstall-script' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'MyFancyPkg/Fancy.pkg' + + uninstall :script => { :executable => 'MyFancyPkg/FancyUninstaller.tool', :args => %w[--please] } +end From 385701cac45d2bf089cd74b26bda255390a00d3b Mon Sep 17 00:00:00 2001 From: Josh Hagins Date: Sat, 2 Jan 2016 22:53:18 -0500 Subject: [PATCH 12/18] Reinstate :trash as a synonym for :delete (was a no-op) --- lib/hbc/artifact/uninstall_base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/hbc/artifact/uninstall_base.rb b/lib/hbc/artifact/uninstall_base.rb index bde75e90981..577dfa8020e 100644 --- a/lib/hbc/artifact/uninstall_base.rb +++ b/lib/hbc/artifact/uninstall_base.rb @@ -346,7 +346,7 @@ class Hbc::Artifact::UninstallBase < Hbc::Artifact::Base end def uninstall_delete(directives, expand_tilde=true) - Array(directives[:delete]).flatten.each_slice(PATH_ARG_SLICE_SIZE) do |path_slice| + Array(directives[:delete]).concat(Array(directives[:trash])).flatten.each_slice(PATH_ARG_SLICE_SIZE) do |path_slice| ohai "Removing files: #{path_slice.utf8_inspect}" path_slice = self.class.expand_path_strings(path_slice) if expand_tilde path_slice = self.class.remove_relative_path_strings(:delete, path_slice) From b4774934a8d1f2f59f2ea8b683484111dfa571d3 Mon Sep 17 00:00:00 2001 From: Josh Hagins Date: Sat, 2 Jan 2016 22:53:31 -0500 Subject: [PATCH 13/18] Add tests for uninstall :trash --- test/cask/artifact/uninstall_test.rb | 13 +++++++++++++ test/support/Casks/with-uninstall-trash.rb | 16 ++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 test/support/Casks/with-uninstall-trash.rb diff --git a/test/cask/artifact/uninstall_test.rb b/test/cask/artifact/uninstall_test.rb index af1eb7cc711..ee310e80a4a 100644 --- a/test/cask/artifact/uninstall_test.rb +++ b/test/cask/artifact/uninstall_test.rb @@ -235,6 +235,19 @@ describe Hbc::Artifact::Uninstall do end end + describe 'when using trash' do + let(:cask) { Hbc.load('with-uninstall-trash') } + + it 'can uninstall' do + Hbc::FakeSystemCommand.expects_command( + sudo(%w[/bin/rm -rf --], + Pathname.new('/permissible/absolute/path'), + Pathname.new('~/permissible/path/with/tilde').expand_path)) + + subject + end + end + describe 'when using rmdir' do let(:cask) { Hbc.load('with-uninstall-rmdir') } let(:dir_pathname) { Pathname(TestHelper.local_binary_path('empty_directory')) } diff --git a/test/support/Casks/with-uninstall-trash.rb b/test/support/Casks/with-uninstall-trash.rb new file mode 100644 index 00000000000..2ccd2c39cd9 --- /dev/null +++ b/test/support/Casks/with-uninstall-trash.rb @@ -0,0 +1,16 @@ +test_cask 'with-uninstall-trash' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'Fancy.pkg' + + uninstall :trash => [ + '/permissible/absolute/path', + '~/permissible/path/with/tilde', + 'impermissible/relative/path', + '/another/impermissible/../relative/path', + ] +end From fd717965e5b5789bc9d37d707d0d9dd524265e03 Mon Sep 17 00:00:00 2001 From: Josh Hagins Date: Sat, 2 Jan 2016 22:59:08 -0500 Subject: [PATCH 14/18] Extract tests specific to uninstall :login_item --- test/cask/artifact/uninstall_test.rb | 12 ++++++++++++ test/support/Casks/with-uninstall-login-item.rb | 11 +++++++++++ 2 files changed, 23 insertions(+) create mode 100644 test/support/Casks/with-uninstall-login-item.rb diff --git a/test/cask/artifact/uninstall_test.rb b/test/cask/artifact/uninstall_test.rb index ee310e80a4a..f57e22853dd 100644 --- a/test/cask/artifact/uninstall_test.rb +++ b/test/cask/artifact/uninstall_test.rb @@ -291,6 +291,18 @@ describe Hbc::Artifact::Uninstall do end end + describe 'when using login_item' do + let(:cask) { Hbc.load('with-uninstall-login-item') } + + it 'can uninstall' do + Hbc::FakeSystemCommand.expects_command( + ['/usr/bin/osascript', '-e', 'tell application "System Events" to delete every login ' \ + 'item whose name is "Fancy"']) + + subject + end + end + describe 'when using pkgutil, launchutil, and kext' do let(:cask) { Hbc.load('with-pkgutil-uninstall') } diff --git a/test/support/Casks/with-uninstall-login-item.rb b/test/support/Casks/with-uninstall-login-item.rb new file mode 100644 index 00000000000..45e5ad5cf26 --- /dev/null +++ b/test/support/Casks/with-uninstall-login-item.rb @@ -0,0 +1,11 @@ +test_cask 'with-uninstall-login-item' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'MyFancyPkg/Fancy.pkg' + + uninstall :login_item => 'Fancy' +end From f186f860821f147549e2376061b4e80f2b7c93d1 Mon Sep 17 00:00:00 2001 From: Josh Hagins Date: Sat, 2 Jan 2016 22:59:50 -0500 Subject: [PATCH 15/18] Remove redundant tests --- test/cask/artifact/uninstall_test.rb | 158 ------------------- test/support/Casks/with-pkgutil-uninstall.rb | 12 -- 2 files changed, 170 deletions(-) delete mode 100644 test/support/Casks/with-pkgutil-uninstall.rb diff --git a/test/cask/artifact/uninstall_test.rb b/test/cask/artifact/uninstall_test.rb index f57e22853dd..0877243e0f7 100644 --- a/test/cask/artifact/uninstall_test.rb +++ b/test/cask/artifact/uninstall_test.rb @@ -32,21 +32,6 @@ describe Hbc::Artifact::Uninstall do uninstall_artifact.uninstall_phase end } - # todo: uninstall tests for :signal (implementation does not use SystemCommand) - it 'runs the specified uninstaller for the Cask' do - Hbc::FakeSystemCommand.stubs_command(sudo(['/usr/bin/osascript', '-e', 'tell application "System Events" to count processes whose bundle identifier is "my.fancy.package.app"']), '1') - Hbc::FakeSystemCommand.stubs_command(sudo(['/usr/bin/osascript', '-e', 'tell application id "my.fancy.package.app" to quit'])) - - Hbc::FakeSystemCommand.expects_command(['/usr/bin/osascript', '-e', 'tell application "System Events" to delete every login item whose name is "Fancy"']) - - Hbc::FakeSystemCommand.expects_command(['/bin/chmod', '+x', '--', cask.staged_path.join('MyFancyPkg','FancyUninstaller.tool')]) - Hbc::FakeSystemCommand.expects_command(sudo([cask.staged_path.join('MyFancyPkg','FancyUninstaller.tool'), '--please'])) - Hbc::FakeSystemCommand.expects_command(sudo(['/bin/rm', '-rf', '--', Pathname.new('/permissible/absolute/path'), Pathname.new('~/permissible/path/with/tilde').expand_path])) - Hbc::FakeSystemCommand.expects_command(sudo(['/bin/rm', '-f', '--', Pathname.new(TestHelper.local_binary_path('empty_directory')).join('.DS_Store')])) - Hbc::FakeSystemCommand.expects_command(sudo(['/bin/rmdir', '--', Pathname.new(TestHelper.local_binary_path('empty_directory'))])) - - subject - end describe 'when using launchctl' do let(:cask) { Hbc.load('with-uninstall-launchctl') } @@ -302,148 +287,5 @@ describe Hbc::Artifact::Uninstall do subject end end - - describe 'when using pkgutil, launchutil, and kext' do - let(:cask) { Hbc.load('with-pkgutil-uninstall') } - - it 'can uninstall' do - Hbc::FakeSystemCommand.stubs_command( - ['/usr/sbin/pkgutil', '--pkgs=my.fancy.package.*'], - <<-FILES.undent - my.fancy.package.main - my.fancy.package.agent - FILES - ) - - Hbc::FakeSystemCommand.stubs_command( - ['/usr/sbin/pkgutil', '--only-files', '--files', 'my.fancy.package.main'], - <<-FILES.undent - fancy/bin/fancy.exe - fancy/var/fancy.data - FILES - ) - Hbc::FakeSystemCommand.stubs_command( - ['/usr/sbin/pkgutil', '--only-dirs', '--files', 'my.fancy.package.main'], - <<-FILES.undent - fancy - fancy/bin - fancy/var - FILES - ) - Hbc::FakeSystemCommand.stubs_command( - ['/usr/sbin/pkgutil', '--files', 'my.fancy.package.main'], - <<-FILES.undent - fancy - fancy/bin - fancy/var - fancy/bin/fancy.exe - fancy/var/fancy.data - FILES - ) - Hbc::FakeSystemCommand.stubs_command( - ['/usr/sbin/pkgutil', '--pkg-info-plist', 'my.fancy.package.main'], - <<-PLIST.undent - - - - - install-location - tmp - volume - / - - - PLIST - ) - - Hbc::FakeSystemCommand.stubs_command( - ['/bin/launchctl', 'list', 'my.fancy.package.service'], - "launchctl list returned unknown response\n" - ) - Hbc::FakeSystemCommand.stubs_command( - sudo(['/bin/launchctl', 'list', 'my.fancy.package.service']), - <<-PLIST.undent - { - "LimitLoadToSessionType" = "Aqua"; - "Label" = "my.fancy.package.service"; - "TimeOut" = 30; - "OnDemand" = true; - "LastExitStatus" = 0; - "ProgramArguments" = ( - "argument"; - ); - }; - PLIST - ) - - Hbc::FakeSystemCommand.expects_command(sudo(['/bin/launchctl', 'remove', 'my.fancy.package.service'])) - - Hbc::FakeSystemCommand.stubs_command(sudo(['/usr/sbin/kextstat', '-l', '-b', 'my.fancy.package.kernelextension']), 'loaded') - Hbc::FakeSystemCommand.expects_command(sudo(['/sbin/kextunload', '-b', 'my.fancy.package.kernelextension'])) - Hbc::FakeSystemCommand.stubs_command(sudo(['/usr/sbin/pkgutil', '--forget', 'my.fancy.package.main'])) - - Hbc::FakeSystemCommand.stubs_command( - ['/usr/sbin/pkgutil', '--only-files', '--files', 'my.fancy.package.agent'], - <<-FILES.undent - fancy/agent/fancy-agent.exe - fancy/agent/fancy-agent.pid - fancy/agent/fancy-agent.log - FILES - ) - Hbc::FakeSystemCommand.stubs_command( - ['/usr/sbin/pkgutil', '--only-dirs', '--files', 'my.fancy.package.agent'], - <<-FILES.undent - fancy - fancy/agent - FILES - ) - Hbc::FakeSystemCommand.stubs_command( - ['/usr/sbin/pkgutil', '--files', 'my.fancy.package.agent'], - <<-FILES.undent - fancy - fancy/agent - fancy/agent/fancy-agent.exe - fancy/agent/fancy-agent.pid - fancy/agent/fancy-agent.log - FILES - ) - Hbc::FakeSystemCommand.stubs_command( - ['/usr/sbin/pkgutil', '--pkg-info-plist', 'my.fancy.package.agent'], - <<-PLIST.undent - - - - - install-location - tmp - volume - / - - - PLIST - ) - - %w[ - /tmp/fancy - /tmp/fancy/agent - /tmp/fancy/bin - /tmp/fancy/var - ].each do |dir| - Hbc::FakeSystemCommand.stubs_command(sudo(['/bin/chmod', '--', '777', '#{dir}'])) - end - - Hbc::FakeSystemCommand.stubs_command(sudo(['/usr/sbin/pkgutil', '--forget', 'my.fancy.package.agent'])) - - Hbc::FakeSystemCommand.stubs_command(sudo(['/bin/rm', '-f', '--', - Pathname.new('/tmp/fancy/bin/fancy.exe'), - Pathname.new('/tmp/fancy/var/fancy.data')])) - Hbc::FakeSystemCommand.stubs_command(sudo(['/bin/rm', '-f', '--', - Pathname.new('/tmp/fancy/agent/fancy-agent.exe'), - Pathname.new('/tmp/fancy/agent/fancy-agent.pid'), - Pathname.new('/tmp/fancy/agent/fancy-agent.log')])) - - subject - end - end end end diff --git a/test/support/Casks/with-pkgutil-uninstall.rb b/test/support/Casks/with-pkgutil-uninstall.rb deleted file mode 100644 index 680714eb197..00000000000 --- a/test/support/Casks/with-pkgutil-uninstall.rb +++ /dev/null @@ -1,12 +0,0 @@ -test_cask 'with-pkgutil-uninstall' do - version '1.2.3' - sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' - - url TestHelper.local_binary_url('MyFancyPkg.zip') - homepage 'http://example.com/fancy-pkg' - - pkg 'Fancy.pkg' - uninstall :pkgutil => 'my.fancy.package.*', - :kext => 'my.fancy.package.kernelextension', - :launchctl => 'my.fancy.package.service' -end From be1d76ddae247992bc901db807081efe2ceb5ec9 Mon Sep 17 00:00:00 2001 From: Josh Hagins Date: Sat, 2 Jan 2016 23:11:26 -0500 Subject: [PATCH 16/18] Fix typo in UninstallBase#get_unix_pids --- lib/hbc/artifact/uninstall_base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/hbc/artifact/uninstall_base.rb b/lib/hbc/artifact/uninstall_base.rb index 577dfa8020e..2cc697b06e2 100644 --- a/lib/hbc/artifact/uninstall_base.rb +++ b/lib/hbc/artifact/uninstall_base.rb @@ -294,7 +294,7 @@ class Hbc::Artifact::UninstallBase < Hbc::Artifact::Base def get_unix_pids(bundle_id) pid_string = @command.run!('/usr/bin/osascript', - :args => ['-e', %Q{tell application "System Events" to get the unix id of every process whose bundle identifier is "#{id}"}], + :args => ['-e', %Q{tell application "System Events" to get the unix id of every process whose bundle identifier is "#{bundle_id}"}], :sudo => true).stdout.chomp return [] unless pid_string.match(%r{\A\d+(?:\s*,\s*\d+)*\Z}) # sanity check pid_string.split(%r{\s*,\s*}).map(&:strip).map(&:to_i) From 0e9660d67c33d9d56893928a8d8469e93c3d7905 Mon Sep 17 00:00:00 2001 From: Josh Hagins Date: Sat, 2 Jan 2016 23:12:10 -0500 Subject: [PATCH 17/18] Add tests for uninstall :signal --- test/cask/artifact/uninstall_test.rb | 20 +++++++++++++++++++- test/support/Casks/with-uninstall-signal.rb | 14 ++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 test/support/Casks/with-uninstall-signal.rb diff --git a/test/cask/artifact/uninstall_test.rb b/test/cask/artifact/uninstall_test.rb index 0877243e0f7..e5f0ae34ca2 100644 --- a/test/cask/artifact/uninstall_test.rb +++ b/test/cask/artifact/uninstall_test.rb @@ -204,7 +204,25 @@ describe Hbc::Artifact::Uninstall do end describe 'when using signal' do - # todo + let(:cask) { Hbc.load('with-uninstall-signal') } + let(:bundle_id) { 'my.fancy.package.app' } + let(:signals) { %w[TERM KILL] } + let(:unix_pids) { [12345, 67890] } + let(:get_unix_pids_script) { + 'tell application "System Events" to get the unix id of every process ' + + %Q{whose bundle identifier is "#{bundle_id}"} + } + + it 'can uninstall' do + Hbc::FakeSystemCommand.stubs_command( + sudo(%W[/usr/bin/osascript -e #{get_unix_pids_script}]), unix_pids.join(', ')) + + signals.each do |signal| + Process.expects(:kill).with(signal, *unix_pids) + end + + subject + end end describe 'when using delete' do diff --git a/test/support/Casks/with-uninstall-signal.rb b/test/support/Casks/with-uninstall-signal.rb new file mode 100644 index 00000000000..b229ee9116c --- /dev/null +++ b/test/support/Casks/with-uninstall-signal.rb @@ -0,0 +1,14 @@ +test_cask 'with-uninstall-signal' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'MyFancyPkg/Fancy.pkg' + + uninstall :signal => [ + ['TERM', 'my.fancy.package.app'], + ['KILL', 'my.fancy.package.app'] + ] +end From e1e13497c30298f9faa8441bd1ffbebf6f1e5d4a Mon Sep 17 00:00:00 2001 From: Josh Hagins Date: Sat, 2 Jan 2016 23:37:20 -0500 Subject: [PATCH 18/18] Implement uninstall_test refactorings in zap_test --- test/cask/artifact/zap_test.rb | 418 +++++++++++++------- test/support/Casks/with-zap-delete.rb | 16 + test/support/Casks/with-zap-early-script.rb | 11 + test/support/Casks/with-zap-kext.rb | 10 + test/support/Casks/with-zap-launchctl.rb | 11 + test/support/Casks/with-zap-login-item.rb | 11 + test/support/Casks/with-zap-pkgutil.rb | 10 + test/support/Casks/with-zap-quit.rb | 11 + test/support/Casks/with-zap-rmdir.rb | 10 + test/support/Casks/with-zap-script.rb | 11 + test/support/Casks/with-zap-signal.rb | 14 + test/support/Casks/with-zap-trash.rb | 16 + 12 files changed, 397 insertions(+), 152 deletions(-) create mode 100644 test/support/Casks/with-zap-delete.rb create mode 100644 test/support/Casks/with-zap-early-script.rb create mode 100644 test/support/Casks/with-zap-kext.rb create mode 100644 test/support/Casks/with-zap-launchctl.rb create mode 100644 test/support/Casks/with-zap-login-item.rb create mode 100644 test/support/Casks/with-zap-pkgutil.rb create mode 100644 test/support/Casks/with-zap-quit.rb create mode 100644 test/support/Casks/with-zap-rmdir.rb create mode 100644 test/support/Casks/with-zap-script.rb create mode 100644 test/support/Casks/with-zap-signal.rb create mode 100644 test/support/Casks/with-zap-trash.rb diff --git a/test/cask/artifact/zap_test.rb b/test/cask/artifact/zap_test.rb index 9aebd4e076d..c2fd9dbf3bb 100644 --- a/test/cask/artifact/zap_test.rb +++ b/test/cask/artifact/zap_test.rb @@ -2,18 +2,18 @@ require 'test_helper' # todo # - test that zap removes an alternate version of the same Cask - describe Hbc::Artifact::Zap do + let(:cask) { Hbc.load('with-installable') } + let(:zap_artifact) { Hbc::Artifact::Zap.new(cask, Hbc::FakeSystemCommand) } + before { - @cask = Hbc.load('with-zap') shutup do - TestHelper.install_without_artifacts(@cask) + TestHelper.install_without_artifacts(cask) end } describe 'install_phase' do it 'does nothing, because the install_phase method is a no-op' do - zap_artifact = Hbc::Artifact::Zap.new(@cask, Hbc::FakeSystemCommand) shutup do zap_artifact.install_phase end @@ -22,7 +22,6 @@ describe Hbc::Artifact::Zap do describe 'uninstall_phase' do it 'does nothing, because the uninstall_phase method is a no-op' do - zap_artifact = Hbc::Artifact::Zap.new(@cask, Hbc::FakeSystemCommand) shutup do zap_artifact.uninstall_phase end @@ -30,167 +29,282 @@ describe Hbc::Artifact::Zap do end describe 'zap_phase' do - # todo: zap tests for :signal (implementation does not use SystemCommand) - it 'runs the specified zap procedures for the Cask' do - zap_artifact = Hbc::Artifact::Zap.new(@cask, Hbc::FakeSystemCommand) - - Hbc::FakeSystemCommand.stubs_command(['/usr/bin/sudo', '-E', '--', '/usr/bin/osascript', '-e', 'tell application "System Events" to count processes whose bundle identifier is "my.fancy.package.app"'], '1') - Hbc::FakeSystemCommand.stubs_command(['/usr/bin/sudo', '-E', '--', '/usr/bin/osascript', '-e', 'tell application id "my.fancy.package.app" to quit']) - - Hbc::FakeSystemCommand.expects_command(['/usr/bin/osascript', '-e', 'tell application "System Events" to delete every login item whose name is "Fancy"']) - - Hbc::FakeSystemCommand.expects_command(['/usr/bin/sudo', '-E', '--', @cask.staged_path.join('MyFancyPkg','FancyUninstaller.tool'), '--please']) - Hbc::FakeSystemCommand.expects_command(['/usr/bin/sudo', '-E', '--', '/bin/rm', '-rf', '--', - Pathname.new('~/Library/Preferences/my.fancy.app.plist').expand_path]) - + subject { shutup do zap_artifact.zap_phase end + } + + describe 'when using launchctl' do + let(:cask) { Hbc.load('with-zap-launchctl') } + let(:launchctl_list_cmd) { %w[/bin/launchctl list my.fancy.package.service] } + let(:launchctl_remove_cmd) { %w[/bin/launchctl remove my.fancy.package.service]} + let(:unknown_response) { "launchctl list returned unknown response\n" } + let(:service_info) { + <<-PLIST.undent + { + "LimitLoadToSessionType" = "Aqua"; + "Label" = "my.fancy.package.service"; + "TimeOut" = 30; + "OnDemand" = true; + "LastExitStatus" = 0; + "ProgramArguments" = ( + "argument"; + ); + }; + PLIST + } + + describe 'when launchctl job is owned by user' do + it 'can zap' do + Hbc::FakeSystemCommand.stubs_command( + launchctl_list_cmd, + service_info) + + Hbc::FakeSystemCommand.stubs_command( + sudo(launchctl_list_cmd), + unknown_response) + + Hbc::FakeSystemCommand.expects_command(launchctl_remove_cmd) + + subject + end + end + + describe 'when launchctl job is owned by system' do + it 'can zap' do + Hbc::FakeSystemCommand.stubs_command( + launchctl_list_cmd, + unknown_response) + + Hbc::FakeSystemCommand.stubs_command( + sudo(launchctl_list_cmd), + service_info) + + Hbc::FakeSystemCommand.expects_command(sudo(launchctl_remove_cmd)) + + subject + end + end end - it 'can zap using pkgutil, launchctl, and file lists' do - cask = Hbc.load('with-pkgutil-zap') - zap_artifact = Hbc::Artifact::Zap.new(cask, Hbc::FakeSystemCommand) - - Hbc::FakeSystemCommand.stubs_command( - ['/usr/sbin/pkgutil', '--pkgs=my.fancy.package.*'], - [ - 'my.fancy.package.main', - 'my.fancy.package.agent', - ].join("\n") - ) - - Hbc::FakeSystemCommand.stubs_command( - ['/usr/sbin/pkgutil', '--only-files', '--files', 'my.fancy.package.main'], - [ - 'fancy/bin/fancy.exe', - 'fancy/var/fancy.data', - ].join("\n") - ) - Hbc::FakeSystemCommand.stubs_command( - ['/usr/sbin/pkgutil', '--only-dirs', '--files', 'my.fancy.package.main'], - [ - 'fancy', - 'fancy/bin', - 'fancy/var', - ].join("\n") - ) - Hbc::FakeSystemCommand.stubs_command( - ['/usr/sbin/pkgutil', '--files', 'my.fancy.package.main'], - [ - 'fancy', - 'fancy/bin', - 'fancy/var', - 'fancy/bin/fancy.exe', - 'fancy/var/fancy.data', - ].join("\n") - ) - Hbc::FakeSystemCommand.stubs_command( - ['/usr/sbin/pkgutil', '--pkg-info-plist', 'my.fancy.package.main'], - <<-PLIST - - - - - install-location - tmp - volume - / - - + describe 'when using pkgutil' do + let(:cask) { Hbc.load('with-zap-pkgutil') } + let(:main_pkg_id) { 'my.fancy.package.main' } + let(:agent_pkg_id) { 'my.fancy.package.agent' } + let(:main_files) { + %w[ + fancy/bin/fancy.exe + fancy/var/fancy.data + ] + } + let(:main_dirs) { + %w[ + fancy + fancy/bin + fancy/var + ] + } + let(:agent_files) { + %w[ + fancy/agent/fancy-agent.exe + fancy/agent/fancy-agent.pid + fancy/agent/fancy-agent.log + ] + } + let(:agent_dirs) { + %w[ + fancy + fancy/agent + ] + } + let(:pkg_info_plist) { + <<-PLIST.undent + + + + + install-location + tmp + volume + / + + PLIST - ) + } - Hbc::FakeSystemCommand.stubs_command( - ['/bin/launchctl', 'list', 'my.fancy.package.service'], - "launchctl list returned unknown response\n" - ) - Hbc::FakeSystemCommand.stubs_command( - ['/usr/bin/sudo', '-E', '--', '/bin/launchctl', 'list', 'my.fancy.package.service'], - <<-"PLIST" -{ - "LimitLoadToSessionType" = "Aqua"; - "Label" = "my.fancy.package.service"; - "TimeOut" = 30; - "OnDemand" = true; - "LastExitStatus" = 0; - "ProgramArguments" = ( - "argument"; - ); -}; - PLIST - ) + it 'can zap' do + Hbc::FakeSystemCommand.stubs_command( + %w[/usr/sbin/pkgutil --pkgs=my.fancy.package.*], + "#{main_pkg_id}\n#{agent_pkg_id}") - Hbc::FakeSystemCommand.expects_command(['/usr/bin/sudo', '-E', '--', '/bin/launchctl', 'remove', 'my.fancy.package.service']) - - Hbc::FakeSystemCommand.stubs_command(['/usr/bin/sudo', '-E', '--', '/usr/sbin/kextstat', '-l', '-b', 'my.fancy.package.kernelextension'], 'loaded') - Hbc::FakeSystemCommand.expects_command(['/usr/bin/sudo', '-E', '--', '/sbin/kextunload', '-b', 'my.fancy.package.kernelextension']) - Hbc::FakeSystemCommand.stubs_command(['/usr/bin/sudo', '-E', '--', '/usr/sbin/pkgutil', '--forget', 'my.fancy.package.main']) - - Hbc::FakeSystemCommand.stubs_command( - ['/usr/sbin/pkgutil', '--only-files', '--files', 'my.fancy.package.agent'], [ - 'fancy/agent/fancy-agent.exe', - 'fancy/agent/fancy-agent.pid', - 'fancy/agent/fancy-agent.log', - ].join("\n") - ) - Hbc::FakeSystemCommand.stubs_command( - ['/usr/sbin/pkgutil', '--only-dirs', '--files', 'my.fancy.package.agent'], - [ - 'fancy', - 'fancy/agent', - ].join("\n") - ) - Hbc::FakeSystemCommand.stubs_command( - ['/usr/sbin/pkgutil', '--files', 'my.fancy.package.agent'], - [ - 'fancy', - 'fancy/agent', - 'fancy/agent/fancy-agent.exe', - 'fancy/agent/fancy-agent.pid', - 'fancy/agent/fancy-agent.log', - ].join("\n") - ) - Hbc::FakeSystemCommand.stubs_command( - ['/usr/sbin/pkgutil', '--pkg-info-plist', 'my.fancy.package.agent'], - <<-PLIST - - - - - install-location - tmp - volume - / - - - PLIST - ) + [main_pkg_id, main_files, main_dirs], + [agent_pkg_id, agent_files, agent_dirs] + ].each do |pkg_id, pkg_files, pkg_dirs| + Hbc::FakeSystemCommand.stubs_command( + %W[/usr/sbin/pkgutil --only-files --files #{pkg_id}], + pkg_files.join("\n")) - %w[ - /tmp/fancy - /tmp/fancy/agent - /tmp/fancy/bin - /tmp/fancy/var - ].each do |dir| - Hbc::FakeSystemCommand.stubs_command(['/usr/bin/sudo', '-E', '--', '/bin/chmod', '--', '777', '#{dir}']) + Hbc::FakeSystemCommand.stubs_command( + %W[/usr/sbin/pkgutil --only-dirs --files #{pkg_id}], + pkg_dirs.join("\n")) + + Hbc::FakeSystemCommand.stubs_command( + %W[/usr/sbin/pkgutil --files #{pkg_id}], + (pkg_files + pkg_dirs).join("\n")) + + Hbc::FakeSystemCommand.stubs_command( + %W[/usr/sbin/pkgutil --pkg-info-plist #{pkg_id}], + pkg_info_plist) + + Hbc::FakeSystemCommand.expects_command(sudo(%W[/usr/sbin/pkgutil --forget #{pkg_id}])) + + Hbc::FakeSystemCommand.expects_command( + sudo(%w[/bin/rm -f --] + pkg_files.map { |path| Pathname("/tmp/#{path}")})) + end + + subject end + end - Hbc::FakeSystemCommand.stubs_command(['/usr/bin/sudo', '-E', '--', '/usr/sbin/pkgutil', '--forget', 'my.fancy.package.agent']) + describe 'when using kext' do + let(:cask) { Hbc.load('with-zap-kext') } + let(:kext_id) { 'my.fancy.package.kernelextension' } - Hbc::FakeSystemCommand.stubs_command(['/usr/bin/sudo', '-E', '--', '/bin/rm', '-f', '--', - Pathname.new('/tmp/fancy/bin/fancy.exe'), - Pathname.new('/tmp/fancy/var/fancy.data')]) - Hbc::FakeSystemCommand.stubs_command(['/usr/bin/sudo', '-E', '--', '/bin/rm', '-f', '--', - Pathname.new('/tmp/fancy/agent/fancy-agent.exe'), - Pathname.new('/tmp/fancy/agent/fancy-agent.pid'), - Pathname.new('/tmp/fancy/agent/fancy-agent.log')]) + it 'can zap' do + Hbc::FakeSystemCommand.stubs_command( + sudo(%W[/usr/sbin/kextstat -l -b #{kext_id}]), 'loaded') - # No assertions after call since all assertions are implicit from the interactions setup above. - # TODO: verify rmdir commands (requires setting up actual file tree or faking out .exists? - shutup do - zap_artifact.zap_phase + Hbc::FakeSystemCommand.expects_command( + sudo(%W[/sbin/kextunload -b #{kext_id}])) + + subject + end + end + + describe 'when using quit' do + let(:cask) { Hbc.load('with-zap-quit') } + let(:bundle_id) { 'my.fancy.package.app' } + let(:count_processes_script) { + 'tell application "System Events" to count processes ' + + %Q{whose bundle identifier is "#{bundle_id}"} + } + let(:quit_application_script) { + %Q{tell application id "#{bundle_id}" to quit} + } + + it 'can zap' do + Hbc::FakeSystemCommand.stubs_command( + sudo(%W[/usr/bin/osascript -e #{count_processes_script}]), '1') + + Hbc::FakeSystemCommand.stubs_command( + sudo(%W[/usr/bin/osascript -e #{quit_application_script}])) + + subject + end + end + + describe 'when using signal' do + let(:cask) { Hbc.load('with-zap-signal') } + let(:bundle_id) { 'my.fancy.package.app' } + let(:signals) { %w[TERM KILL] } + let(:unix_pids) { [12345, 67890] } + let(:get_unix_pids_script) { + 'tell application "System Events" to get the unix id of every process ' + + %Q{whose bundle identifier is "#{bundle_id}"} + } + + it 'can zap' do + Hbc::FakeSystemCommand.stubs_command( + sudo(%W[/usr/bin/osascript -e #{get_unix_pids_script}]), unix_pids.join(', ')) + + signals.each do |signal| + Process.expects(:kill).with(signal, *unix_pids) + end + + subject + end + end + + describe 'when using delete' do + let(:cask) { Hbc.load('with-zap-delete') } + + it 'can zap' do + Hbc::FakeSystemCommand.expects_command( + sudo(%w[/bin/rm -rf --], + Pathname.new('/permissible/absolute/path'), + Pathname.new('~/permissible/path/with/tilde').expand_path)) + + subject + end + end + + describe 'when using trash' do + let(:cask) { Hbc.load('with-zap-trash') } + + it 'can zap' do + Hbc::FakeSystemCommand.expects_command( + sudo(%w[/bin/rm -rf --], + Pathname.new('/permissible/absolute/path'), + Pathname.new('~/permissible/path/with/tilde').expand_path)) + + subject + end + end + + describe 'when using rmdir' do + let(:cask) { Hbc.load('with-zap-rmdir') } + let(:dir_pathname) { Pathname(TestHelper.local_binary_path('empty_directory')) } + + it 'can zap' do + Hbc::FakeSystemCommand.expects_command( + sudo(%w[/bin/rm -f --], dir_pathname.join('.DS_Store'))) + + Hbc::FakeSystemCommand.expects_command( + sudo(%w[/bin/rmdir --], dir_pathname)) + + subject + end + end + + describe 'when using script' do + let(:cask) { Hbc.load('with-zap-script') } + let(:script_pathname) { cask.staged_path.join('MyFancyPkg','FancyUninstaller.tool') } + + it 'can zap' do + Hbc::FakeSystemCommand.expects_command(%w[/bin/chmod +x --] + [script_pathname]) + + Hbc::FakeSystemCommand.expects_command( + sudo(cask.staged_path.join('MyFancyPkg','FancyUninstaller.tool'), '--please')) + + subject + end + end + + describe 'when using early_script' do + let(:cask) { Hbc.load('with-zap-early-script') } + let(:script_pathname) { cask.staged_path.join('MyFancyPkg','FancyUninstaller.tool') } + + it 'can zap' do + Hbc::FakeSystemCommand.expects_command(%w[/bin/chmod +x --] + [script_pathname]) + + Hbc::FakeSystemCommand.expects_command( + sudo(cask.staged_path.join('MyFancyPkg','FancyUninstaller.tool'), '--please')) + + subject + end + end + + describe 'when using login_item' do + let(:cask) { Hbc.load('with-zap-login-item') } + + it 'can zap' do + Hbc::FakeSystemCommand.expects_command( + ['/usr/bin/osascript', '-e', 'tell application "System Events" to delete every login ' \ + 'item whose name is "Fancy"']) + + subject end end end diff --git a/test/support/Casks/with-zap-delete.rb b/test/support/Casks/with-zap-delete.rb new file mode 100644 index 00000000000..3b2a5e8617c --- /dev/null +++ b/test/support/Casks/with-zap-delete.rb @@ -0,0 +1,16 @@ +test_cask 'with-zap-delete' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'Fancy.pkg' + + zap :delete => [ + '/permissible/absolute/path', + '~/permissible/path/with/tilde', + 'impermissible/relative/path', + '/another/impermissible/../relative/path', + ] +end diff --git a/test/support/Casks/with-zap-early-script.rb b/test/support/Casks/with-zap-early-script.rb new file mode 100644 index 00000000000..25655774e9d --- /dev/null +++ b/test/support/Casks/with-zap-early-script.rb @@ -0,0 +1,11 @@ +test_cask 'with-zap-early-script' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'MyFancyPkg/Fancy.pkg' + + zap :early_script => { :executable => 'MyFancyPkg/FancyUninstaller.tool', :args => %w[--please] } +end diff --git a/test/support/Casks/with-zap-kext.rb b/test/support/Casks/with-zap-kext.rb new file mode 100644 index 00000000000..74eb50eec04 --- /dev/null +++ b/test/support/Casks/with-zap-kext.rb @@ -0,0 +1,10 @@ +test_cask 'with-zap-kext' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'Fancy.pkg' + zap :kext => 'my.fancy.package.kernelextension' +end diff --git a/test/support/Casks/with-zap-launchctl.rb b/test/support/Casks/with-zap-launchctl.rb new file mode 100644 index 00000000000..939725ad849 --- /dev/null +++ b/test/support/Casks/with-zap-launchctl.rb @@ -0,0 +1,11 @@ +test_cask 'with-zap-launchctl' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyApp.zip') + homepage 'http://example.com/fancy' + + app 'Fancy.app' + + zap :launchctl => 'my.fancy.package.service' +end diff --git a/test/support/Casks/with-zap-login-item.rb b/test/support/Casks/with-zap-login-item.rb new file mode 100644 index 00000000000..461129c8324 --- /dev/null +++ b/test/support/Casks/with-zap-login-item.rb @@ -0,0 +1,11 @@ +test_cask 'with-zap-login-item' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'MyFancyPkg/Fancy.pkg' + + zap :login_item => 'Fancy' +end diff --git a/test/support/Casks/with-zap-pkgutil.rb b/test/support/Casks/with-zap-pkgutil.rb new file mode 100644 index 00000000000..06dbf7b4663 --- /dev/null +++ b/test/support/Casks/with-zap-pkgutil.rb @@ -0,0 +1,10 @@ +test_cask 'with-zap-pkgutil' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'Fancy.pkg' + zap :pkgutil => 'my.fancy.package.*' +end diff --git a/test/support/Casks/with-zap-quit.rb b/test/support/Casks/with-zap-quit.rb new file mode 100644 index 00000000000..8cdf294ac53 --- /dev/null +++ b/test/support/Casks/with-zap-quit.rb @@ -0,0 +1,11 @@ +test_cask 'with-zap-quit' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'MyFancyPkg/Fancy.pkg' + + zap :quit => 'my.fancy.package.app' +end diff --git a/test/support/Casks/with-zap-rmdir.rb b/test/support/Casks/with-zap-rmdir.rb new file mode 100644 index 00000000000..81ca98704e4 --- /dev/null +++ b/test/support/Casks/with-zap-rmdir.rb @@ -0,0 +1,10 @@ +test_cask 'with-zap-rmdir' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'MyFancyPkg/Fancy.pkg' + zap :rmdir => TestHelper.local_binary_path('empty_directory') +end diff --git a/test/support/Casks/with-zap-script.rb b/test/support/Casks/with-zap-script.rb new file mode 100644 index 00000000000..e77cac3053a --- /dev/null +++ b/test/support/Casks/with-zap-script.rb @@ -0,0 +1,11 @@ +test_cask 'with-zap-script' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'MyFancyPkg/Fancy.pkg' + + zap :script => { :executable => 'MyFancyPkg/FancyUninstaller.tool', :args => %w[--please] } +end diff --git a/test/support/Casks/with-zap-signal.rb b/test/support/Casks/with-zap-signal.rb new file mode 100644 index 00000000000..542e0599776 --- /dev/null +++ b/test/support/Casks/with-zap-signal.rb @@ -0,0 +1,14 @@ +test_cask 'with-zap-signal' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'MyFancyPkg/Fancy.pkg' + + zap :signal => [ + ['TERM', 'my.fancy.package.app'], + ['KILL', 'my.fancy.package.app'] + ] +end diff --git a/test/support/Casks/with-zap-trash.rb b/test/support/Casks/with-zap-trash.rb new file mode 100644 index 00000000000..e315b0a05f0 --- /dev/null +++ b/test/support/Casks/with-zap-trash.rb @@ -0,0 +1,16 @@ +test_cask 'with-zap-trash' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'Fancy.pkg' + + zap :trash => [ + '/permissible/absolute/path', + '~/permissible/path/with/tilde', + 'impermissible/relative/path', + '/another/impermissible/../relative/path', + ] +end