Commit 1439180c authored by anonym's avatar anonym
Browse files

Make execute*'s options more Rubyish.

... and pave the way for adding more options than the user to execute
the command as.
parent 6c484def
......@@ -16,7 +16,7 @@ When /^I update APT using apt-get$/ do
next if @skip_steps_while_restoring_background
Timeout::timeout(30*60) do
@vm.execute_successfully("echo #{@sudo_password} | " +
"sudo -S apt-get update", LIVE_USER)
"sudo -S apt-get update", :user => LIVE_USER)
end
end
......@@ -25,7 +25,8 @@ Then /^I should be able to install a package using apt-get$/ do
package = "cowsay"
Timeout::timeout(120) do
@vm.execute_successfully("echo #{@sudo_password} | " +
"sudo -S apt-get install #{package}", LIVE_USER)
"sudo -S apt-get install #{package}",
:user => LIVE_USER)
end
step "package \"#{package}\" is installed"
end
......
def shipped_openpgp_keys
shipped_gpg_keys = @vm.execute_successfully('gpg --batch --with-colons --fingerprint --list-key', LIVE_USER).stdout
shipped_gpg_keys = @vm.execute_successfully('gpg --batch --with-colons --fingerprint --list-key', :user => LIVE_USER).stdout
openpgp_fingerprints = shipped_gpg_keys.scan(/^fpr:::::::::([A-Z0-9]+):$/).flatten
return openpgp_fingerprints
end
......@@ -28,7 +28,7 @@ Then /^the shipped (?:Debian repository key|OpenPGP key ([A-Z0-9]+)) will be val
cmd = 'apt-key adv'
user = 'root'
end
shipped_sig_key_info = @vm.execute_successfully("#{cmd} --batch --list-key #{fingerprint}", user).stdout
shipped_sig_key_info = @vm.execute_successfully("#{cmd} --batch --list-key #{fingerprint}", :user => user).stdout
m = /\[expire[ds]: ([0-9-]*)\]/.match(shipped_sig_key_info)
if m
expiration_date = Date.parse(m[1])
......@@ -114,7 +114,8 @@ Then /^GNOME Screenshot is configured to save files to the live user's home dire
home = "/home/#{LIVE_USER}"
save_path = @vm.execute_successfully(
"gsettings get org.gnome.gnome-screenshot auto-save-directory",
LIVE_USER).stdout.chomp.tr("'","")
:user => LIVE_USER
).stdout.chomp.tr("'","")
assert_equal("file://#{home}", save_path,
"The GNOME screenshot auto-save-directory is not set correctly.")
end
......@@ -164,12 +165,12 @@ Then /^MAT can clean some sample PDF file$/ do
pdf_on_guest = "/home/#{LIVE_USER}/#{pdf_name}"
step "I copy \"#{@shared_pdf_dir_on_guest}/#{pdf_name}\" to \"#{pdf_on_guest}\" as user \"#{LIVE_USER}\""
check_before = @vm.execute_successfully("mat --check '#{pdf_on_guest}'",
LIVE_USER).stdout
:user => LIVE_USER).stdout
assert(check_before.include?("#{pdf_on_guest} is not clean"),
"MAT failed to see that '#{pdf_on_host}' is dirty")
@vm.execute_successfully("mat '#{pdf_on_guest}'", LIVE_USER)
@vm.execute_successfully("mat '#{pdf_on_guest}'", :user => LIVE_USER)
check_after = @vm.execute_successfully("mat --check '#{pdf_on_guest}'",
LIVE_USER).stdout
:user => LIVE_USER).stdout
assert(check_after.include?("#{pdf_on_guest} is clean"),
"MAT failed to clean '#{pdf_on_host}'")
@vm.execute_successfully("rm '#{pdf_on_guest}'")
......
......@@ -793,7 +793,7 @@ end
When /^I copy "([^"]+)" to "([^"]+)" as user "([^"]+)"$/ do |source, destination, user|
next if @skip_steps_while_restoring_background
c = @vm.execute("cp \"#{source}\" \"#{destination}\"", LIVE_USER)
c = @vm.execute("cp \"#{source}\" \"#{destination}\"", :user => LIVE_USER)
assert(c.success?, "Failed to copy file:\n#{c.stdout}\n#{c.stderr}")
end
......@@ -916,7 +916,7 @@ Then /^there is no GNOME bookmark for the persistent Tor Browser directory$/ do
end
def pulseaudio_sink_inputs
pa_info = @vm.execute_successfully('pacmd info', LIVE_USER).stdout
pa_info = @vm.execute_successfully('pacmd info', :user => LIVE_USER).stdout
sink_inputs_line = pa_info.match(/^\d+ sink input\(s\) available\.$/)[0]
return sink_inputs_line.match(/^\d+/)[0].to_i
end
......@@ -1054,7 +1054,7 @@ EOF
# accessing this server matters, like when testing the Tor Browser..
try_for(30, :msg => "Something is wrong with the LAN web server") do
msg = @vm.execute_successfully("curl #{@web_server_url}",
LIVE_USER).stdout.chomp
:user => LIVE_USER).stdout.chomp
web_server_hello_msg == msg
end
end
......
......@@ -25,9 +25,10 @@ Given /^I generate an OpenPGP key named "([^"]+)" with password "([^"]+)"$/ do |
%commit
EOF
gpg_key_recipie.split("\n").each do |line|
@vm.execute("echo '#{line}' >> /tmp/gpg_key_recipie", LIVE_USER)
@vm.execute("echo '#{line}' >> /tmp/gpg_key_recipie", :user => LIVE_USER)
end
c = @vm.execute("gpg --batch --gen-key < /tmp/gpg_key_recipie", LIVE_USER)
c = @vm.execute("gpg --batch --gen-key < /tmp/gpg_key_recipie",
:user => LIVE_USER)
assert(c.success?, "Failed to generate OpenPGP key:\n#{c.stderr}")
end
......
......@@ -129,7 +129,7 @@ Given /^I fill the guest's memory with a known pattern(| without verifying)$/ do
# unnecessarily.
instances = (@detected_ram_m.to_f/(2**10)).ceil
instances.times do
@vm.spawn('/usr/local/sbin/fillram; killall fillram', LIVE_USER)
@vm.spawn('/usr/local/sbin/fillram; killall fillram', :user => LIVE_USER)
end
# We make sure that all fillram processes have started...
try_for(10, :msg => "all fillram processes didn't start", :delay => 0.1) do
......
......@@ -43,19 +43,19 @@ end
When(/^I do a TCP DNS lookup of "(.*?)"$/) do |host|
next if @skip_steps_while_restoring_background
lookup = @vm.execute("host -T #{host} #{SOME_DNS_SERVER}", LIVE_USER)
lookup = @vm.execute("host -T #{host} #{SOME_DNS_SERVER}", :user => LIVE_USER)
assert(lookup.success?, "Failed to resolve #{host}:\n#{lookup.stdout}")
end
When(/^I do a UDP DNS lookup of "(.*?)"$/) do |host|
next if @skip_steps_while_restoring_background
lookup = @vm.execute("host #{host} #{SOME_DNS_SERVER}", LIVE_USER)
lookup = @vm.execute("host #{host} #{SOME_DNS_SERVER}", :user => LIVE_USER)
assert(lookup.success?, "Failed to resolve #{host}:\n#{lookup.stdout}")
end
When(/^I send some ICMP pings$/) do
next if @skip_steps_while_restoring_background
# We ping an IP address to avoid a DNS lookup
ping = @vm.execute("ping -c 5 #{SOME_DNS_SERVER}", LIVE_USER)
ping = @vm.execute("ping -c 5 #{SOME_DNS_SERVER}", :user => LIVE_USER)
assert(ping.success?, "Failed to ping #{SOME_DNS_SERVER}:\n#{ping.stderr}")
end
......@@ -2,5 +2,6 @@ Then /^the Git repository "([\S]+)" has been cloned successfully$/ do |repo|
next if @skip_steps_while_restoring_background
assert(@vm.directory_exist?("/home/#{LIVE_USER}/#{repo}/.git"))
assert(@vm.file_exist?("/home/#{LIVE_USER}/#{repo}/.git/config"))
@vm.execute_successfully("cd '/home/#{LIVE_USER}/#{repo}/' && git status", LIVE_USER)
@vm.execute_successfully("cd '/home/#{LIVE_USER}/#{repo}/' && git status",
:user => LIVE_USER)
end
......@@ -159,7 +159,7 @@ When /^I join some empty multi-user chat$/ do
@screen.type("a", Sikuli::KeyModifier.CTRL)
@screen.type("c", Sikuli::KeyModifier.CTRL)
conference_server =
@vm.execute_successfully("xclip -o", LIVE_USER).stdout.chomp
@vm.execute_successfully("xclip -o", :user => LIVE_USER).stdout.chomp
@chat_room_jid = chat_room + "@" + conference_server
@screen.click("PidginJoinChatButton.png")
......
Then /^I should be able to run administration commands as the live user$/ do
next if @skip_steps_while_restoring_background
stdout = @vm.execute("echo #{@sudo_password} | sudo -S whoami", LIVE_USER).stdout
stdout = @vm.execute("echo #{@sudo_password} | sudo -S whoami",
:user => LIVE_USER).stdout
actual_user = stdout.sub(/^\[sudo\] password for #{LIVE_USER}: /, "").chomp
assert_equal("root", actual_user, "Could not use sudo")
end
Then /^I should not be able to run administration commands as the live user with the "([^"]*)" password$/ do |password|
next if @skip_steps_while_restoring_background
stderr = @vm.execute("echo #{password} | sudo -S whoami", LIVE_USER).stderr
stderr = @vm.execute("echo #{password} | sudo -S whoami",
:user => LIVE_USER).stderr
sudo_failed = stderr.include?("The administration password is disabled") || stderr.include?("is not allowed to execute")
assert(sudo_failed, "The administration password is not disabled:" + stderr)
end
......
......@@ -35,7 +35,8 @@ end
Given /^I have the SSH key pair for an? (Git|SSH|SFTP) (?:repository|server)$/ do |server_type|
next if @skip_steps_while_restoring_background
@vm.execute_successfully("install -m 0700 -d '/home/#{LIVE_USER}/.ssh/'", LIVE_USER)
@vm.execute_successfully("install -m 0700 -d '/home/#{LIVE_USER}/.ssh/'",
:user => LIVE_USER)
unless server_type == 'Git'
read_and_validate_ssh_config server_type
secret_key = $config[server_type]["private_key"]
......@@ -45,9 +46,12 @@ Given /^I have the SSH key pair for an? (Git|SSH|SFTP) (?:repository|server)$/ d
public_key = $config["Unsafe_SSH_public_key"]
end
@vm.execute_successfully("echo '#{secret_key}' > '/home/#{LIVE_USER}/.ssh/id_rsa'", LIVE_USER)
@vm.execute_successfully("echo '#{public_key}' > '/home/#{LIVE_USER}/.ssh/id_rsa.pub'", LIVE_USER)
@vm.execute_successfully("chmod 0600 '/home/#{LIVE_USER}/.ssh/'id*", LIVE_USER)
@vm.execute_successfully("echo '#{secret_key}' > '/home/#{LIVE_USER}/.ssh/id_rsa'",
:user => LIVE_USER)
@vm.execute_successfully("echo '#{public_key}' > '/home/#{LIVE_USER}/.ssh/id_rsa.pub'",
:user => LIVE_USER)
@vm.execute_successfully("chmod 0600 '/home/#{LIVE_USER}/.ssh/'id*",
:user => LIVE_USER)
end
Given /^I verify the SSH fingerprint for the (?:Git|SSH) (?:repository|server)$/ do
......
......@@ -188,7 +188,7 @@ When /^I open an untorified (TCP|UDP|ICMP) connections to (\S*)(?: on port (\d+)
when "ICMP"
cmd = "ping -c 5 #{host}"
end
@conn_res = @vm.execute(cmd, LIVE_USER)
@conn_res = @vm.execute(cmd, :user => LIVE_USER)
end
Then /^the untorified connection fails$/ do
......@@ -292,7 +292,7 @@ end
And /^I re-run tails-security-check$/ do
next if @skip_steps_while_restoring_background
@vm.execute_successfully("tails-security-check", LIVE_USER)
@vm.execute_successfully("tails-security-check", :user => LIVE_USER)
end
And /^I re-run htpdate$/ do
......@@ -305,7 +305,7 @@ end
And /^I re-run tails-upgrade-frontend-wrapper$/ do
next if @skip_steps_while_restoring_background
@vm.execute_successfully("tails-upgrade-frontend-wrapper", LIVE_USER)
@vm.execute_successfully("tails-upgrade-frontend-wrapper", :user => LIVE_USER)
end
When /^I connect Gobby to "([^"]+)"$/ do |host|
......
......@@ -3,7 +3,7 @@ end
def count_gpg_signatures(key)
output = @vm.execute_successfully("gpg --batch --list-sigs #{key}",
LIVE_USER).stdout
:user => LIVE_USER).stdout
return output.scan(/^sig/).count
end
......@@ -39,7 +39,8 @@ end
When /^the "([^"]+)" OpenPGP key is not in the live user's public keyring$/ do |keyid|
next if @skip_steps_while_restoring_background
assert(!@vm.execute("gpg --batch --list-keys '#{keyid}'", LIVE_USER).success?,
assert(!@vm.execute("gpg --batch --list-keys '#{keyid}'",
:user => LIVE_USER).success?,
"The '#{keyid}' key is in the live user's public keyring.")
end
......@@ -55,7 +56,7 @@ When /^I fetch the "([^"]+)" OpenPGP key using the GnuPG CLI( without any signat
begin
@gnupg_recv_key_res = @vm.execute_successfully(
"gpg --batch #{importopts} --recv-key '#{keyid}'",
LIVE_USER)
:user => LIVE_USER)
break
rescue ExecutionFailedInVM
force_new_tor_circuit
......@@ -79,7 +80,8 @@ end
When /^the "([^"]+)" key is in the live user's public keyring after at most (\d+) seconds$/ do |keyid, delay|
next if @skip_steps_while_restoring_background
try_for(delay.to_f, :msg => "The '#{keyid}' key is not in the live user's public keyring") {
@vm.execute("gpg --batch --list-keys '#{keyid}'", LIVE_USER).success?
@vm.execute("gpg --batch --list-keys '#{keyid}'",
:user => LIVE_USER).success?
}
end
......@@ -177,7 +179,7 @@ end
Then /^Seahorse is configured to use the correct keyserver$/ do
next if @skip_steps_while_restoring_background
@gnome_keyservers = YAML.load(@vm.execute_successfully('gsettings get org.gnome.crypto.pgp keyservers',
LIVE_USER).stdout)
:user => LIVE_USER).stdout)
assert_equal(1, @gnome_keyservers.count, 'Seahorse should only have one keyserver configured.')
# Seahorse doesn't support hkps so that part of the domain is stripped out.
# We also insert hkp:// to the beginning of the domain.
......
......@@ -9,7 +9,7 @@ When /^I query the whois directory service for "([^"]+)"$/ do |domain|
@new_circuit_tries = 0
until @new_circuit_tries == $config["MAX_NEW_TOR_CIRCUIT_RETRIES"] do
begin
@vm_execute_res = @vm.execute("whois '#{domain}'", LIVE_USER)
@vm_execute_res = @vm.execute("whois '#{domain}'", :user => LIVE_USER)
if !@vm_execute_res.success? || @vm_execute_res.stdout['LIMIT EXCEEDED']
raise WhoisLookupFailure
end
......@@ -36,7 +36,7 @@ When /^I wget "([^"]+)" to stdout(?:| with the '([^']+)' options)$/ do |url, opt
@new_circuit_tries = 0
until @new_circuit_tries == $config["MAX_NEW_TOR_CIRCUIT_RETRIES"] do
begin
@vm_execute_res = @vm.execute("wget #{arguments}", LIVE_USER)
@vm_execute_res = @vm.execute("wget #{arguments}", :user => LIVE_USER)
raise WgetFailure unless @vm_execute_res.success?
break
rescue WgetFailure
......
......@@ -510,7 +510,7 @@ When /^I write some files expected to persist$/ do
next if @skip_steps_while_restoring_background
persistent_mounts.each do |_, dir|
owner = @vm.execute("stat -c %U #{dir}").stdout.chomp
assert(@vm.execute("touch #{dir}/XXX_persist", user=owner).success?,
assert(@vm.execute("touch #{dir}/XXX_persist", :user => owner).success?,
"Could not create file in persistent directory #{dir}")
end
end
......@@ -519,7 +519,7 @@ When /^I remove some files expected to persist$/ do
next if @skip_steps_while_restoring_background
persistent_mounts.each do |_, dir|
owner = @vm.execute("stat -c %U #{dir}").stdout.chomp
assert(@vm.execute("rm #{dir}/XXX_persist", user=owner).success?,
assert(@vm.execute("rm #{dir}/XXX_persist", :user => owner).success?,
"Could not remove file in persistent directory #{dir}")
end
end
......@@ -528,7 +528,7 @@ When /^I write some files not expected to persist$/ do
next if @skip_steps_while_restoring_background
persistent_mounts.each do |_, dir|
owner = @vm.execute("stat -c %U #{dir}").stdout.chomp
assert(@vm.execute("touch #{dir}/XXX_gone", user=owner).success?,
assert(@vm.execute("touch #{dir}/XXX_gone", :user => owner).success?,
"Could not create file in persistent directory #{dir}")
end
end
......
......@@ -374,12 +374,14 @@ EOF
end
end
def execute(cmd, user = "root")
return VMCommand.new(self, cmd, { :user => user, :spawn => false })
def execute(cmd, options = {})
options[:user] ||= "root"
options[:spawn] ||= false
return VMCommand.new(self, cmd, options)
end
def execute_successfully(cmd, user = "root")
p = execute(cmd, user)
def execute_successfully(*args)
p = execute(*args)
begin
assert_vmcommand_success(p)
rescue Test::Unit::AssertionFailedError => e
......@@ -388,8 +390,9 @@ EOF
return p
end
def spawn(cmd, user = "root")
return VMCommand.new(self, cmd, { :user => user, :spawn => true })
def spawn(cmd, options = {})
options[:spawn] = true
return execute(cmd, options)
end
def wait_until_remote_shell_is_up(timeout = 30)
......@@ -415,7 +418,8 @@ EOF
def focus_window(window_title, user = LIVE_USER)
execute_successfully(
"xdotool search --name '#{window_title}' windowactivate --sync", user
"xdotool search --name '#{window_title}' windowactivate --sync",
:user => user
)
end
......@@ -430,14 +434,14 @@ EOF
def file_content(file, user = 'root')
# We don't quote #{file} on purpose: we sometimes pass environment variables
# or globs that we want to be interpreted by the shell.
cmd = execute("cat #{file}", user)
cmd = execute("cat #{file}", :user => user)
assert(cmd.success?,
"Could not cat '#{file}':\n#{cmd.stdout}\n#{cmd.stderr}")
return cmd.stdout
end
def file_append(file, line, user = 'root')
cmd = execute("echo '#{line}' >> '#{file}'", user)
cmd = execute("echo '#{line}' >> '#{file}'", :user => user)
assert(cmd.success?,
"Could not append to '#{file}':\n#{cmd.stdout}\n#{cmd.stderr}")
return cmd.stdout
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment