Merge branch 'stable' into devel
[tails.git] / features / step_definitions / torified_misc.rb
blobdaf228179edadf2dab2d70cf0677756b03a36351
1 require 'resolv'
3 When /^I (wget|curl) "([^"]+)" to stdout(?:| with the '([^']+)' options)$/ do |cmd, target, options|
4   retry_tor do
5     if target == 'some Tails mirror'
6       host = 'dl.amnesia.boum.org'
7       address = Resolv.new.getaddresses(host).sample
8       puts "Resolved #{host} to #{address}"
9       url = "http://#{address}/tails/stable/"
10     else
11       url = target
12     end
13     arguments = if cmd == 'wget'
14                   "-O - '#{url}'"
15                 else
16                   "-s '#{url}'"
17                 end
18     arguments = "#{options} #{arguments}" if options
19     @vm_execute_res = $vm.execute("#{cmd} #{arguments}", user: LIVE_USER)
20     if @vm_execute_res.failure?
21       raise "#{cmd}:ing #{url} with options #{options} failed with:\n" \
22             "#{@vm_execute_res.stdout}\n" +
23             @vm_execute_res.stderr.to_s
24     end
25   end
26 end
28 Then /^the (wget|curl) command is successful$/ do |cmd|
29   assert(
30     @vm_execute_res.success?,
31     "#{cmd} failed:\n" \
32     "#{@vm_execute_res.stdout}\n" +
33     @vm_execute_res.stderr.to_s
34   )
35 end
37 Then /^the (wget|curl) standard output contains "([^"]+)"$/ do |cmd, text|
38   assert(
39     @vm_execute_res.stdout[text],
40     "The #{cmd} standard output does not contain #{text}:\n" \
41     "#{@vm_execute_res.stdout}\n" +
42     @vm_execute_res.stderr.to_s
43   )
44 end