Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Review and revise accessibility methods in postflight mini-DSL #7684

Merged
merged 1 commit into from
Dec 2, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions lib/cask/dsl/postflight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ def suppress_move_to_applications(options = {})
end

def enable_accessibility_access
if MacOS.version < :mavericks
system_command("touch", :args => ["/private/var/db/.AccessibilityAPIEnabled"])
if MacOS.version >= :mavericks
@command.run!('/usr/bin/sqlite3',
:args => [
Cask.tcc_db,
"INSERT INTO access VALUES('kTCCServiceAccessibility','#{bundle_identifier}',0,1,1,NULL);",
],
:sudo => true)
else
system_command("sqlite3", :args => [
"/Library/Application\ Support/com.apple.TCC/TCC.db",
"INSERT INTO access VALUES('kTCCServiceAccessibility','#{bundle_identifier}',0,1,1,NULL);"
], :sudo => true)
@command.run!('/usr/bin/touch',
:args => [Cask.pre_mavericks_accessibility_dotfile],
:sudo => true)
end
end

Expand Down
17 changes: 12 additions & 5 deletions lib/cask/dsl/uninstall_preflight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@
class Cask::DSL::UninstallPreflight < Cask::DSL::Base
include Cask::Staged

def remove_accessibility_access
def disable_accessibility_access
if MacOS.version >= :mavericks
system_command("sqlite3", :args => [
"/Library/Application\ Support/com.apple.TCC/TCC.db",
"DELETE FROM access WHERE client='#{bundle_identifier}';"
], :sudo => true)
@command.run!('/usr/bin/sqlite3',
:args => [
Cask.tcc_db,
"DELETE FROM access WHERE client='#{bundle_identifier}';",
],
:sudo => true)
else
opoo <<-EOS.undent
Accessibility access was enabled for #{@cask}, but it is not safe to disable
automatically on this version of OS X. See System Preferences.
EOS
end
end

Expand Down
8 changes: 8 additions & 0 deletions lib/cask/locations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,13 @@ def path(cask_title)
tapspath.join(default_tap, 'Casks', "#{cask_title}.rb")
end
end

def tcc_db
@tcc_db ||= Pathname.new('/Library/Application Support/com.apple.TCC/TCC.db')
end

def pre_mavericks_accessibility_dotfile
@pre_mavericks_accessibility_dotfile ||= Pathname.new('/private/var/db/.AccessibilityAPIEnabled')
end
end
end
4 changes: 2 additions & 2 deletions test/cask/dsl/postflight_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
@dsl.stubs(:bundle_identifier => 'com.example.BasicCask')

Cask::FakeSystemCommand.expects_command(
["/usr/bin/sudo", "-E", "--", "sqlite3", "/Library/Application Support/com.apple.TCC/TCC.db", "INSERT INTO access VALUES('kTCCServiceAccessibility','com.example.BasicCask',0,1,1,NULL);"]
['/usr/bin/sudo', '-E', '--', '/usr/bin/sqlite3', Cask.tcc_db, %q{INSERT INTO access VALUES('kTCCServiceAccessibility','com.example.BasicCask',0,1,1,NULL);}]
)
@dsl.enable_accessibility_access
end
Expand All @@ -72,7 +72,7 @@
MacOS.stubs(:version => OS::Mac::Version.new('10.8'))

Cask::FakeSystemCommand.expects_command(
['touch', '/private/var/db/.AccessibilityAPIEnabled']
['/usr/bin/sudo', '-E', '--', '/usr/bin/touch', Cask.pre_mavericks_accessibility_dotfile]
)
@dsl.enable_accessibility_access
end
Expand Down
17 changes: 14 additions & 3 deletions test/cask/dsl/uninstall_preflight_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,25 @@
@dsl = Cask::DSL::UninstallPreflight.new(cask, Cask::FakeSystemCommand)
end

it "can remove accessibility access" do
it "can disable accessibility access" do
MacOS.stubs(:version => OS::Mac::Version.new('10.9'))

@dsl.stubs(:bundle_identifier => 'com.example.BasicCask')

Cask::FakeSystemCommand.expects_command(
["/usr/bin/sudo", "-E", "--", "sqlite3", "/Library/Application Support/com.apple.TCC/TCC.db", "DELETE FROM access WHERE client='com.example.BasicCask';"]
['/usr/bin/sudo', '-E', '--', '/usr/bin/sqlite3', Cask.tcc_db, %q{DELETE FROM access WHERE client='com.example.BasicCask';}]
)
@dsl.remove_accessibility_access
@dsl.disable_accessibility_access
end

it "warns about disabling accessibility access on old OS X versions" do
MacOS.stubs(:version => OS::Mac::Version.new('10.8'))

@dsl.stubs(:bundle_identifier => 'com.example.BasicCask')

out, err = capture_io do
@dsl.disable_accessibility_access
end
err.must_match('Warning: Accessibility access was enabled for basic-cask, but it is not safe to disable')
end
end