Commit b6e6f682 authored by Tails developers's avatar Tails developers
Browse files

Import first POC of cucumber/sikuli tests.

parent eab80705
#!/usr/bin/env bash
# This is an RVM Project .rvmrc file, used to automatically load the ruby
# development environment upon cd'ing into the directory
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
# Only full ruby name is supported here, for short names use:
# echo "rvm use jruby" > .rvmrc
environment_id="jruby-1.6.7.2"
# Uncomment the following lines if you want to verify rvm version per project
# rvmrc_rvm_version="1.14.1 ()" # 1.10.1 seams as a safe start
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
# return 1
# }
# Uncomment following line if you want options to be set only for given project.
PROJECT_JRUBY_OPTS=( --1.9 )
# The variable PROJECT_JRUBY_OPTS requires the following to be run in shell:
# chmod +x ${rvm_path}/hooks/after_use_jruby_opts
# First we attempt to load the desired environment directly from the environment
# file. This is very fast and efficient compared to running through the entire
# CLI and selector. If you want feedback on which environment was used then
# insert the word 'use' after --create as this triggers verbose mode.
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
then
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
[[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
\. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
if [[ $- == *i* ]] # check for interactive shells
then echo "Using: $(tput setaf 2)$GEM_HOME$(tput sgr0)" # show the user the ruby and gemset they are using in green
else echo "Using: $GEM_HOME" # don't use colors in non-interactive shells
fi
else
# If the environment file has not yet been created, use the RVM CLI to select.
rvm --create use "$environment_id" || {
echo "Failed to create RVM environment '${environment_id}'."
return 1
}
fi
Given /^a freshly started Tails$/ do
@vm.start
@screen.wait('WelcometoTai-1.png', 500)
end
When /^I log in a new session$/ do
@screen.click('Logln.png')
end
Then /^I should see YourbrowserT\.png$/ do
@screen.wait('YourbrowserT.png', 300)
end
Feature: Iceweasel must be torified.
In order to be anonymous, the iceweasel web browser must connect through Tor.
Background:
Given a freshly started Tails
Scenario: See check.torproject green page on session startup
When I log in a new session
Then I should see YourbrowserT.png
require 'java'
require 'rubygems'
Dir[File.dirname(__FILE__) + "/features/support/helpers/*.rb"].each do |file|
require file
end
Before do
@vm = VM.new(ENV['VM'])
@display = Display.new(ENV['VM'])
@screen = Sikuli::Screen.new
end
After do
@display.stop
@vm.stop
end
class Display
def initialize(domain)
start_virtviewer(domain)
end
def stop
stop_virtviewer
end
# Self-explainatory TODO item. Xvfb can be told to put screen raw X images
# in a directory. These files are .wxd that can prob. be converted. see Xvfb(1)
def take_screenshot
end
def start_virtviewer(domain)
IO.popen(["virt-viewer", "-d",
"-f",
"-r",
"-c", "qemu+ssh://localhost/system",
["--display=", ENV['DISPLAY']].join(''),
domain,
"&"].join(' '))
end
def stop_virtviewer
system("killall virt-viewer")
end
end
#
# There should be a way to tests against network traffic. Possible pathes
# are the use of the pcap gem, use of iptables, or maybe the most promising:
# use the nfqueue gem to be able to inspect packets directly.
#
# Scenario: Iceweasel should connect only through Tor
# Given I open Iceweasel
# When I browse to http://any.url
# Then the network traffic should flow only through Tor
require 'sikuli'
# Configure sikuli
Sikuli::Config.run do |config|
config.image_path = "#{Dir.pwd}/features/images/"
config.logging = false
config.highlight_on_find = false
end
# Helper to manipulate VM's storages (usb, ide, CD...). Iso management
# might end in there too.
class Storage
end
require 'libvirt'
class VM
def initialize(domain)
@iso = ENV['ISO'] || get_last_iso
@virt = Libvirt::open("qemu:///system")
@dom = @virt.lookup_domain_by_name(domain)
add_iso_to_domain
end
def get_last_iso
Dir.glob("*.iso").sort_by {|f| File.mtime(f)}.last
end
def add_iso_to_domain
xml = <<EOF
<disk>
<source file="#{ENV['PWD']}/#{@iso}"/>
<target dev='hdc' bus='ide'/>
</disk>
EOF
@dom.update_device(xml)
end
def is_running?
@dom.active?
end
def execute
# TODO: could allow to run commands on the tails VM
# Might deserve a whole helper though.
end
def start
@dom.destroy if @dom.active?
@dom.create
end
def stop
@dom.destroy if @dom.active?
end
end
Supports Markdown
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