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.type(password, ['Return'])
27 try_for(10, msg: 'su did not return an authentication failure') do
28 terminal.text['su: Authentication failure']
30 # Ensure the previous authentication failure does not taint the next tests
31 $vm.execute('pkill -u amnesia gnome-terminal')
35 When /^running a command as root with pkexec requires PolicyKit administrator privileges$/ do
36 action = 'org.freedesktop.policykit.exec'
37 action_details = $vm.execute("pkaction --verbose --action-id #{action}")
39 assert(action_details[/\s+implicit any:\s+auth_admin$/],
40 "Expected 'auth_admin' for 'any':\n#{action_details}")
41 assert(action_details[/\s+implicit inactive:\s+auth_admin$/],
42 "Expected 'auth_admin' for 'inactive':\n#{action_details}")
43 assert(action_details[/\s+implicit active:\s+auth_admin$/],
44 "Expected 'auth_admin' for 'active':\n#{action_details}")
47 Then /^I can run a command as root with pkexec$/ do
48 step 'I run "pkexec touch /root/pkexec-test" in GNOME Terminal'
49 step 'I enter the sudo password in the pkexec prompt'
50 try_for(10, msg: 'The /root/pkexec-test file was not created.') do
51 $vm.file_exist?('/root/pkexec-test')
55 Then /^I cannot run a command as root with pkexec and the standard passwords$/ do
56 step 'I run "pkexec touch /root/pkexec-test" in GNOME Terminal'
57 ['', 'live', 'amnesia'].each do |password|
58 deal_with_polkit_prompt(password, expect_success: false)
60 @screen.press('Escape')
61 @screen.wait('PolicyKitAuthCompleteFailure.png', 20)
62 # Ensure we don't taint the next tests
63 $vm.execute('pkill -u amnesia gnome-terminal')