summaryrefslogtreecommitdiffstats
path: root/features/step_definitions
diff options
context:
space:
mode:
Diffstat (limited to 'features/step_definitions')
-rw-r--r--features/step_definitions/common_steps.rb46
-rw-r--r--features/step_definitions/erase_memory.rb17
-rw-r--r--features/step_definitions/pidgin.rb45
-rw-r--r--features/step_definitions/torified_gnupg.rb106
-rw-r--r--features/step_definitions/torified_misc.rb52
-rw-r--r--features/step_definitions/unsafe_browser.rb28
6 files changed, 124 insertions, 170 deletions
diff --git a/features/step_definitions/common_steps.rb b/features/step_definitions/common_steps.rb
index 733d2e8..0b95714 100644
--- a/features/step_definitions/common_steps.rb
+++ b/features/step_definitions/common_steps.rb
@@ -110,13 +110,9 @@ end
Then /^drive "([^"]+)" is detected by Tails$/ do |name|
next if @skip_steps_while_restoring_background
- if @vm.is_running?
- try_for(10, :msg => "Drive '#{name}' is not detected by Tails") {
- @vm.disk_detected?(name)
- }
- else
- STDERR.puts "Cannot tell if drive '#{name}' is detected by Tails: " +
- "Tails is not running"
+ raise "Tails is not running" unless @vm.is_running?
+ try_for(10, :msg => "Drive '#{name}' is not detected by Tails") do
+ @vm.disk_detected?(name)
end
end
@@ -459,15 +455,6 @@ Then /^all Internet traffic has only flowed through Tor$/ do
leaks.assert_no_leaks
end
-Given /^I enter the sudo password in the gksu prompt$/ do
- next if @skip_steps_while_restoring_background
- @screen.wait('GksuAuthPrompt.png', 60)
- sleep 1 # wait for weird fade-in to unblock the "Ok" button
- @screen.type(@sudo_password)
- @screen.type(Sikuli::Key.ENTER)
- @screen.waitVanish('GksuAuthPrompt.png', 10)
-end
-
Given /^I enter the sudo password in the pkexec prompt$/ do
next if @skip_steps_while_restoring_background
step "I enter the \"#{@sudo_password}\" password in the pkexec prompt"
@@ -652,9 +639,22 @@ When /^I open the address "([^"]*)" in the (.*)$/ do |address, browser|
next if @skip_steps_while_restoring_background
step "I open a new tab in the #{browser}"
info = xul_application_info(browser)
- @screen.click(info[:address_bar_image])
- sleep 0.5
- @screen.type(address + Sikuli::Key.ENTER)
+ open_address = Proc.new do
+ @screen.click(info[:address_bar_image])
+ sleep 0.5
+ @screen.type(address + Sikuli::Key.ENTER)
+ end
+ open_address.call
+ if browser == "Tor Browser"
+ recovery_on_failure = Proc.new do
+ @screen.type(Sikuli::Key.ESC)
+ @screen.waitVanish('BrowserReloadButton.png', 3)
+ open_address.call
+ end
+ retry_tor(recovery_on_failure) do
+ @screen.wait('BrowserReloadButton.png', 120)
+ end
+ end
end
Then /^the (.*) has no plugins installed$/ do |browser|
@@ -1074,16 +1074,13 @@ When /^I open a page on the LAN web server in the (.*)$/ do |browser|
end
def force_new_tor_circuit(with_vidalia=nil)
- assert(!@new_circuit_tries.nil? && @new_circuit_tries >= 0,
- '@new_circuit_tries was not initialized before it was used')
- @new_circuit_tries += 1
- STDERR.puts "Forcing new Tor circuit... (attempt ##{@new_circuit_tries})" if $config["DEBUG"]
+ debug_log("Forcing new Tor circuit...")
if with_vidalia
assert_equal('gnome', @theme, "Vidalia is not available in the #{@theme} theme.")
begin
step 'process "vidalia" is running'
rescue Test::Unit::AssertionFailedError
- STDERR.puts "Vidalia was not running. Attempting to start Vidalia..." if $config["DEBUG"]
+ debug_log("Vidalia was not running. Attempting to start Vidalia...")
@vm.spawn('restart-vidalia')
step 'process "vidalia" is running within 15 seconds'
end
@@ -1160,6 +1157,5 @@ end
Then /^I force Tor to use a new circuit( in Vidalia)?$/ do |with_vidalia|
next if @skip_steps_while_restoring_background
- @new_circuit_tries = 1 if @new_circuit_tries.nil?
force_new_tor_circuit(with_vidalia)
end
diff --git a/features/step_definitions/erase_memory.rb b/features/step_definitions/erase_memory.rb
index f84c801..fdc755b 100644
--- a/features/step_definitions/erase_memory.rb
+++ b/features/step_definitions/erase_memory.rb
@@ -140,18 +140,19 @@ Given /^I fill the guest's memory with a known pattern(| without verifying)$/ do
@vm.pidof("fillram").each do |pid|
@vm.execute_successfully("echo 15 > /proc/#{pid}/oom_adj")
end
- STDERR.print "Memory fill progress: "
- ram_usage = ""
- remove_chars = 0
+ prev_used_ram_ratio = -1
# ... and that it finishes
try_for(instances*2*60, { :msg => "fillram didn't complete, probably the VM crashed" }) do
- used_ram = used_ram_in_MiB
- remove_chars = ram_usage.size
- ram_usage = "%3d%% " % ((used_ram.to_f/@detected_ram_m)*100)
- STDERR.print "\b"*remove_chars + ram_usage
+ used_ram_ratio = (used_ram_in_MiB.to_f/@detected_ram_m)*100
+ # Round down to closest multiple of 10 to limit the logging a bit.
+ used_ram_ratio = (used_ram_ratio/10).round*10
+ if used_ram_ratio - prev_used_ram_ratio >= 10
+ debug_log("Memory fill progress: %3d%%" % used_ram_ratio)
+ prev_used_ram_ratio = used_ram_ratio
+ end
! @vm.has_process?("fillram")
end
- STDERR.print "\b"*remove_chars + "finished.\n"
+ debug_log("Memory fill progress: finished")
if verify
coverage = pattern_coverage_in_guest_ram()
# Let's aim for having the pattern cover at least 80% of the free RAM.
diff --git a/features/step_definitions/pidgin.rb b/features/step_definitions/pidgin.rb
index cbfbea1..7e29bfc 100644
--- a/features/step_definitions/pidgin.rb
+++ b/features/step_definitions/pidgin.rb
@@ -18,19 +18,20 @@ EOF
return account
end
+def wait_and_focus(img, time = 10, window)
+ begin
+ @screen.wait(img, time)
+ rescue FindFailed
+ @vm.focus_window(window)
+ @screen.wait(img, time)
+ end
+end
+
def focus_pidgin_irc_conversation_window(account)
account = account.sub(/^irc\./, '')
@vm.focus_window(".*#{Regexp.escape(account)}$")
end
-def close_pidgin_conversation_window(account)
- focus_pidgin_irc_conversation_window(account)
- @screen.type(Sikuli::Key.F4, Sikuli::KeyModifier.ALT)
- if @screen.exists('PidginConfirmationIcon.png')
- @screen.click('GnomeCloseButton.png')
- end
-end
-
When /^I create my XMPP account$/ do
next if @skip_steps_while_restoring_background
account = xmpp_account("Tails_account")
@@ -296,9 +297,11 @@ end
Then /^Pidgin successfully connects to the "([^"]+)" account$/ do |account|
next if @skip_steps_while_restoring_background
expected_channel_entry = chan_image(account, default_chan(account), 'roster')
- @new_circuit_tries = 0
- until @new_circuit_tries == $config["MAX_NEW_TOR_CIRCUIT_RETRIES"] do
- # Sometimes the OFTC welcome notice window pops up over the buddy list one...
+ reconnect_button = 'PidginReconnect.png'
+ recovery_on_failure = Proc.new do
+ @screen.wait_and_click(reconnect_button, 20)
+ end
+ retry_tor(recovery_on_failure) do
begin
@vm.focus_window('Buddy List')
rescue ExecutionFailedInVM
@@ -307,17 +310,11 @@ Then /^Pidgin successfully connects to the "([^"]+)" account$/ do |account|
# conversation window. At worst, the test will still fail...
close_pidgin_conversation_window(account)
end
-
- # FIXME This should be modified to use waitAny once #9633 is addressed
- begin
- @screen.wait(expected_channel_entry, 60)
- break
- rescue FindFailed
- force_new_tor_circuit
- @screen.wait_and_click('PidginReconnect.png', 20)
+ on_screen, _ = @screen.waitAny([expected_channel_entry, reconnect_button], 60)
+ unless on_screen == expected_channel_entry
+ raise "Connecting to account #{account} failed."
end
end
- @screen.wait(expected_channel_entry, 10)
end
Then /^the "([^"]*)" account only responds to PING and VERSION CTCP requests$/ do |irc_server|
@@ -385,6 +382,7 @@ def pidgin_add_certificate_from (cert_file)
# Here, we need a certificate that is not already in the NSS database
step "I copy \"/usr/share/ca-certificates/spi-inc.org/spi-cacert-2008.crt\" to \"#{cert_file}\" as user \"amnesia\""
+ @vm.focus_window('Buddy List')
@screen.wait_and_click('PidginToolsMenu.png', 10)
@screen.wait_and_click('PidginCertificatesMenuItem.png', 10)
@screen.wait('PidginCertificateManagerDialog.png', 10)
@@ -406,18 +404,19 @@ end
Then /^I can add a certificate from the "([^"]+)" directory to Pidgin$/ do |cert_dir|
next if @skip_steps_while_restoring_background
pidgin_add_certificate_from("#{cert_dir}/test.crt")
- @screen.wait('PidginCertificateAddHostnameDialog.png', 10)
+ wait_and_focus('PidginCertificateAddHostnameDialog.png', 10, 'Certificate Import')
@screen.type("XXX test XXX" + Sikuli::Key.ENTER)
- @screen.wait('PidginCertificateTestItem.png', 10)
+ wait_and_focus('PidginCertificateTestItem.png', 10, 'Certificate Manager')
end
Then /^I cannot add a certificate from the "([^"]+)" directory to Pidgin$/ do |cert_dir|
next if @skip_steps_while_restoring_background
pidgin_add_certificate_from("#{cert_dir}/test.crt")
- @screen.wait('PidginCertificateImportFailed.png', 10)
+ wait_and_focus('PidginCertificateImportFailed.png', 10, 'Import Error')
end
When /^I close Pidgin's certificate manager$/ do
+ wait_and_focus('PidginCertificateManagerDialog.png', 10, 'Certificate Manager')
@screen.type(Sikuli::Key.ESC)
# @screen.wait_and_click('PidginCertificateManagerClose.png', 10)
@screen.waitVanish('PidginCertificateManagerDialog.png', 10)
diff --git a/features/step_definitions/torified_gnupg.rb b/features/step_definitions/torified_gnupg.rb
index 51eb4da..75ec14e 100644
--- a/features/step_definitions/torified_gnupg.rb
+++ b/features/step_definitions/torified_gnupg.rb
@@ -12,7 +12,8 @@ def seahorse_wait_helper(img, time = 20)
@screen.wait(img, time)
rescue FindFailed => e
if @screen.exists('SeahorseKeyserverError.png')
- raise OpenPGPKeyserverCommunicationError
+ raise OpenPGPKeyserverCommunicationError.new(
+ "Could not find 'SeahorseKeyserverError.png'")
else
# Seahorse has been known to segfault during tests
syslog = @vm.file_content('/var/log/syslog')
@@ -50,18 +51,16 @@ When /^I fetch the "([^"]+)" OpenPGP key using the GnuPG CLI( without any signat
else
importopts = ''
end
- @new_circuit_tries = 0
- until @new_circuit_tries == $config["MAX_NEW_TOR_CIRCUIT_RETRIES"] do
- begin
- @gnupg_recv_key_res = @vm.execute_successfully(
+ retry_tor do
+ @gnupg_recv_key_res = @vm.execute_successfully(
"gpg --batch #{importopts} --recv-key '#{keyid}'",
LIVE_USER)
- break
- rescue ExecutionFailedInVM
- force_new_tor_circuit
+ if @gnupg_recv_key_res.failure?
+ raise "Fetching keys with the GnuPG CLI failed with:\n" +
+ "#{@gnupg_recv_key_res.stdout}\n" +
+ "#{@gnupg_recv_key_res.stderr}"
end
end
- assert(@new_circuit_tries < $config["MAX_NEW_TOR_CIRCUIT_RETRIES"], "Fetching keys with the GnuPG CLI did not succeed after retrying #{@new_circuit_tries} times")
end
When /^the GnuPG fetch is successful$/ do
@@ -110,29 +109,26 @@ end
Then /^I synchronize keys in Seahorse$/ do
next if @skip_steps_while_restoring_background
- @new_circuit_tries = 0
- until @new_circuit_tries == $config["MAX_NEW_TOR_CIRCUIT_RETRIES"] do
- begin
- step 'process "seahorse" is running'
- @screen.wait_and_click("SeahorseWindow.png", 10)
- seahorse_menu_click_helper('SeahorseRemoteMenu.png', 'SeahorseRemoteMenuSync.png', 'seahorse')
- seahorse_wait_helper('SeahorseSyncKeys.png')
- @screen.type("s", Sikuli::KeyModifier.ALT) # Button: Sync
- seahorse_wait_helper('SeahorseSynchronizing.png')
- seahorse_wait_helper('SeahorseWindow.png', 5*60)
- break
- rescue OpenPGPKeyserverCommunicationError
- force_new_tor_circuit
- @screen.wait_and_click('GnomeCloseButton.png', 20)
- if @screen.exists('SeahorseSynchronizing.png')
- # Seahorse is likely to segfault if we end up here.
- @screen.click('SeahorseSynchronizing.png')
- @screen.type(Sikuli::Key.ESC)
- end
- seahorse_wait_helper('SeahorseWindow.png')
+ recovery_proc = Proc.new do
+ @screen.wait_and_click('GnomeCloseButton.png', 20)
+ if @screen.exists('SeahorseSynchronizing.png')
+ # Seahorse is likely to segfault if we end up here.
+ @screen.click('SeahorseSynchronizing.png')
+ @screen.type(Sikuli::Key.ESC)
end
+ seahorse_wait_helper('SeahorseWindow.png')
+ end
+ retry_tor(recovery_proc) do
+ step 'process "seahorse" is running'
+ @screen.wait_and_click("SeahorseWindow.png", 10)
+ seahorse_menu_click_helper('SeahorseRemoteMenu.png',
+ 'SeahorseRemoteMenuSync.png',
+ 'seahorse')
+ seahorse_wait_helper('SeahorseSyncKeys.png')
+ @screen.type("s", Sikuli::KeyModifier.ALT) # Button: Sync
+ seahorse_wait_helper('SeahorseSynchronizing.png')
+ seahorse_wait_helper('SeahorseWindow.png', 5*60)
end
- assert(@new_circuit_tries < $config["MAX_NEW_TOR_CIRCUIT_RETRIES"], "Syncing keys in Seahorse did not succeed after retrying #{@new_circuit_tries} times")
end
When /^I fetch the "([^"]+)" OpenPGP key using Seahorse( via the Tails OpenPGP Applet)?$/ do |keyid, withgpgapplet|
@@ -143,35 +139,33 @@ When /^I fetch the "([^"]+)" OpenPGP key using Seahorse( via the Tails OpenPGP A
step "I start Seahorse"
end
step "Seahorse has opened"
- @new_circuit_tries = 0
- until @new_circuit_tries == $config["MAX_NEW_TOR_CIRCUIT_RETRIES"] do
+
+ recovery_proc = Proc.new do
+ @screen.wait_and_click('GnomeCloseButton.png', 20)
+ @screen.type(Sikuli::Key.ESC)
+ @screen.type("w", Sikuli::KeyModifier.CTRL)
+ end
+ retry_tor(recovery_proc) do
+ @screen.wait_and_click("SeahorseWindow.png", 10)
+ seahorse_menu_click_helper('SeahorseRemoteMenu.png',
+ 'SeahorseRemoteMenuFind.png',
+ 'seahorse')
+ seahorse_wait_helper('SeahorseFindKeysWindow.png', 10)
+ # Seahorse doesn't seem to support searching for fingerprints
+ @screen.type(keyid + Sikuli::Key.ENTER)
begin
- @screen.wait_and_click("SeahorseWindow.png", 10)
- seahorse_menu_click_helper('SeahorseRemoteMenu.png', 'SeahorseRemoteMenuFind.png', 'seahorse')
- seahorse_wait_helper('SeahorseFindKeysWindow.png', 10)
- # Seahorse doesn't seem to support searching for fingerprints
- @screen.type(keyid + Sikuli::Key.ENTER)
- begin
- seahorse_wait_helper('SeahorseFoundKeyResult.png', 5*60)
- rescue FindFailed
- # We may end up here if Seahorse appears to be "frozen".
- # Sometimes--but not always--if we click another window
- # the main Seahorse window will unfreeze, allowing us
- # to continue normally.
- @screen.click("SeahorseSearch.png")
- end
- @screen.click("SeahorseKeyResultWindow.png")
- @screen.click("SeahorseFoundKeyResult.png")
- @screen.click("SeahorseImport.png")
- break
- rescue OpenPGPKeyserverCommunicationError
- force_new_tor_circuit
- @screen.wait_and_click('GnomeCloseButton.png', 20)
- @screen.type(Sikuli::Key.ESC)
- @screen.type("w", Sikuli::KeyModifier.CTRL)
+ seahorse_wait_helper('SeahorseFoundKeyResult.png', 5*60)
+ rescue FindFailed
+ # We may end up here if Seahorse appears to be "frozen".
+ # Sometimes--but not always--if we click another window
+ # the main Seahorse window will unfreeze, allowing us
+ # to continue normally.
+ @screen.click("SeahorseSearch.png")
end
+ @screen.click("SeahorseKeyResultWindow.png")
+ @screen.click("SeahorseFoundKeyResult.png")
+ @screen.click("SeahorseImport.png")
end
- assert(@new_circuit_tries < $config["MAX_NEW_TOR_CIRCUIT_RETRIES"], "Fetching keys in Seahorse did not succeed after retrying #{@new_circuit_tries} times")
end
Then /^Seahorse is configured to use the correct keyserver$/ do
diff --git a/features/step_definitions/torified_misc.rb b/features/step_definitions/torified_misc.rb
index eeca163..5d28216 100644
--- a/features/step_definitions/torified_misc.rb
+++ b/features/step_definitions/torified_misc.rb
@@ -1,55 +1,27 @@
-class WhoisLookupFailure < StandardError
-end
-
-class WgetFailure < StandardError
-end
-
When /^I query the whois directory service for "([^"]+)"$/ do |domain|
next if @skip_steps_while_restoring_background
- @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)
- if !@vm_execute_res.success? || @vm_execute_res.stdout['LIMIT EXCEEDED']
- raise WhoisLookupFailure
- end
- break
- rescue WhoisLookupFailure
- if @vm_execute_res.stderr['Timeout'] || \
- @vm_execute_res.stderr['Unable to resolve'] || \
- @vm_execute_res.stdout['LIMIT EXCEEDED']
- force_new_tor_circuit
- end
+ retry_tor do
+ @vm_execute_res = @vm.execute("whois '#{domain}'", LIVE_USER)
+ if @vm_execute_res.failure?
+ raise "Looking up whois info for #{domain} failed with:\n" +
+ "#{@vm_execute_res.stdout}\n" +
+ "#{@vm_execute_res.stderr}"
end
end
- assert(@new_circuit_tries < $config["MAX_NEW_TOR_CIRCUIT_RETRIES"],
- "Looking up whois info for #{domain} did not succeed after retrying #{@new_circuit_tries} times.\n" +
- "The output of the last command contains:\n" +
- "#{@vm_execute_res.stdout}\n" + "#{@vm_execute_res.stderr}")
end
When /^I wget "([^"]+)" to stdout(?:| with the '([^']+)' options)$/ do |url, options|
next if @skip_steps_while_restoring_background
arguments = "-O - '#{url}'"
arguments = "#{options} #{arguments}" if options
-
- @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)
- raise WgetFailure unless @vm_execute_res.success?
- break
- rescue WgetFailure
- if @vm_execute_res.stderr['Timeout'] || @vm_execute_res.stderr['Unable to resolve']
- force_new_tor_circuit
- end
+ retry_tor do
+ @vm_execute_res = @vm.execute("wget #{arguments}", LIVE_USER)
+ if @vm_execute_res.failure?
+ raise "wget:ing #{url} with options #{options} failed with:\n" +
+ "#{@vm_execute_res.stdout}\n" +
+ "#{@vm_execute_res.stderr}"
end
end
- assert(@new_circuit_tries < $config["MAX_NEW_TOR_CIRCUIT_RETRIES"],
- "Fetching from #{url} with options #{options} did not succeed after retrying #{@new_circuit_tries} times.\n" +
- "The output contains:\n" +
- "#{@vm_execute_res.stdout}\n" +
- "#{@vm_execute_res.stderr}")
end
Then /^the (wget|whois) command is successful$/ do |command|
diff --git a/features/step_definitions/unsafe_browser.rb b/features/step_definitions/unsafe_browser.rb
index 9e6cedd..cc06f9e 100644
--- a/features/step_definitions/unsafe_browser.rb
+++ b/features/step_definitions/unsafe_browser.rb
@@ -5,25 +5,17 @@ When /^I see and accept the Unsafe Browser start verification$/ do
end
def supported_torbrowser_languages
- langs = Array.new
- exts = @vm.execute_successfully(
- "find /usr/local/share/tor-browser-extensions -maxdepth 1 -name 'langpack*.xpi' -printf \"%f\n\"").stdout
-
- # Some of the TBB languages are shipped with both a language and country code, e.g. es-ES.
- # We'll only keep track of the language code and let `guess_best_tor_browser_locale`
- # try to get by with our approximated locales.
- supported_langs = exts.scan(/langpack-([a-z]+).*/).flatten
- locales = @vm.execute_successfully(
- "find /usr/lib/locale -maxdepth 1 -name '*.utf8' -printf \"%f\n\"").stdout.split
-
- # Determine a valid locale for each language that we want to test.
- supported_langs.each do |lang|
- # If a language shipped by TBB is not a supported system locale (e.g. 'vi'),
- # 'find(nomatch)' will use the locale xx_XX for language 'xx'.
- nomatch = proc { "#{lang}_#{lang.upcase}.utf8" }
- langs << locales.find(nomatch) { |l| l.match(/^#{lang}/) }
+ localization_descriptions = "#{Dir.pwd}/config/chroot_local-includes/usr/share/tails/browser-localization/descriptions"
+ File.read(localization_descriptions).split("\n").map do |line|
+ # The line will be of the form "xx:YY:..." or "xx-YY:YY:..."
+ first, second = line.sub('-', '_').split(':')
+ candidates = ["#{first}_#{second}.utf8", "#{first}.utf8",
+ "#{first}_#{second}", first]
+ when_not_found = Proc.new { raise "Could not find a locale for '#{line}'" }
+ candidates.find(when_not_found) do |candidate|
+ @vm.directory_exist?("/usr/lib/locale/#{candidate}")
+ end
end
- return langs
end
Then /^I start the Unsafe Browser in the "([^"]+)" locale$/ do |loc|