1 Then /^I can run a command as root with sudo$/ do
2 stdout = $vm.execute("echo #{@sudo_password} | sudo -S whoami",
3 user: LIVE_USER).stdout
4 actual_user = stdout.sub(/^\[sudo\] password for #{LIVE_USER}: /, '').chomp
5 assert_equal('root', actual_user, 'Could not use sudo')
8 Then /^I cannot run a command as root with sudo and the standard passwords$/ do
9 ['', 'live', 'amnesia'].each do |password|
10 stderr = $vm.execute("echo #{password} | sudo -S whoami",
11 user: LIVE_USER).stderr
12 sudo_failed = stderr.include?('The administration password is disabled') \
13 || stderr.include?('is not allowed to execute')
14 assert(sudo_failed, 'The administration password is not disabled:' + stderr)
18 Then /^I cannot login as root using su with the standard passwords$/ do
19 ['', 'live', 'amnesia'].each do |password|
20 # We use /bin/su because Tails' bash has its own su() function,
21 # which merely prints instructions.
22 step 'I run "/bin/su" in GNOME Terminal'
23 terminal = Dogtail::Application.new('gnome-terminal-server')
24 .child('Terminal', roleName: 'terminal')
25 terminal.text['Password:']
26 @screen.paste(password, app: :terminal)
27 @screen.press('Return')
28 try_for(10, msg: 'su did not return an authentication failure') do
29 terminal.text['su: Authentication failure']
31 # Ensure the previous authentication failure does not taint the next tests
32 $vm.execute('pkill -u amnesia gnome-terminal')
36 When /^running a command as root with pkexec requires PolicyKit administrator privileges$/ do
37 action = 'org.freedesktop.policykit.exec'
38 action_details = $vm.execute("pkaction --verbose --action-id #{action}")
40 assert(action_details[/\s+implicit any:\s+auth_admin$/],
41 "Expected 'auth_admin' for 'any':\n#{action_details}")
42 assert(action_details[/\s+implicit inactive:\s+auth_admin$/],
43 "Expected 'auth_admin' for 'inactive':\n#{action_details}")
44 assert(action_details[/\s+implicit active:\s+auth_admin$/],
45 "Expected 'auth_admin' for 'active':\n#{action_details}")
48 Then /^I can run a command as root with pkexec$/ do
49 step 'I run "pkexec touch /root/pkexec-test" in GNOME Terminal'
50 step 'I enter the sudo password in the pkexec prompt'
51 try_for(10, msg: 'The /root/pkexec-test file was not created.') do
52 $vm.file_exist?('/root/pkexec-test')
56 Then /^I cannot run a command as root with pkexec and the standard passwords$/ do
57 step 'I run "pkexec touch /root/pkexec-test" in GNOME Terminal'
58 ['live', 'amnesia'].each do |password|
59 deal_with_polkit_prompt(password, expect_success: false)
62 @screen.press('Escape')
63 @screen.wait('PolicyKitAuthCompleteFailure.png', 20)
64 # Ensure we don't taint the next tests
65 $vm.execute('pkill -u amnesia gnome-terminal')