summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoranonym <anonym@riseup.net>2015-07-17 01:36:30 +0200
committeranonym <anonym@riseup.net>2015-07-17 01:36:30 +0200
commit006c6313110b81e6791b5a0f3f19d91e7d0d5ed5 (patch)
tree6dfa11091c15b35b24afd99d4d92f06f76c995c0
parent1411096873799f6690aad07ba8799f4c7ff9be2b (diff)
parent8e3728505c51ab70e10572d3c14f686d4c14fd63 (diff)
Merge branch 'test/9521-chutney-wip' into test/wip-improved-snapshots+9521-chutney-wip
-rw-r--r--features/chutney.feature18
-rw-r--r--features/chutney/test-network9
-rw-r--r--features/step_definitions/chutney.rb64
-rw-r--r--features/support/helpers/misc_helpers.rb5
4 files changed, 94 insertions, 2 deletions
diff --git a/features/chutney.feature b/features/chutney.feature
new file mode 100644
index 0000000..1695263
--- /dev/null
+++ b/features/chutney.feature
@@ -0,0 +1,18 @@
+@product
+Feature: Simulate the Tor network with chutney
+
+ Background:
+ Given a computer
+ And I start Tails from DVD with network unplugged and I login
+ And Tails is using a simulated Tor network
+ And the network is plugged
+ And Tor is ready
+ And available upgrades have been checked
+ And all notifications have disappeared
+ And I save the state so the background can be restored next scenario
+
+ Scenario: We're not using the real Tor network
+ When I start the Tor Browser
+ And the Tor Browser has started and loaded the startup page
+ And I open the address "https://check.torproject.org" in the Tor Browser
+ Then I see "UnsafeBrowserTorCheckFail.png" after at most 30 seconds
diff --git a/features/chutney/test-network b/features/chutney/test-network
new file mode 100644
index 0000000..01d6bec
--- /dev/null
+++ b/features/chutney/test-network
@@ -0,0 +1,9 @@
+Authority = Node(tag="a", authority=1, relay=1, torrc="authority.tmpl")
+NonExitRelay = Node(tag="m", relay=1, torrc="relay-non-exit.tmpl")
+ExitRelay = Node(tag="r", relay=1, exit=1, torrc="relay.tmpl")
+Client = Node(tag="c", torrc="client.tmpl")
+NODES = Authority.getN(5) + \
+ NonExitRelay.getN(20) + \
+ ExitRelay.getN(10) + \
+ Client.getN(1)
+ConfigureNodes(NODES)
diff --git a/features/step_definitions/chutney.rb b/features/step_definitions/chutney.rb
new file mode 100644
index 0000000..14be394
--- /dev/null
+++ b/features/step_definitions/chutney.rb
@@ -0,0 +1,64 @@
+When /^Tails is using a simulated Tor network$/ do
+ next if @skip_steps_while_restoring_background
+ assert(not(@vm.execute('service tor status').success?),
+ "Running this step when Tor is running is probably not intentional")
+
+ # Ensure that a fresh chutney instnace is running, and that it will
+ # be cleaned upon exit.
+ chutney_listen_address = $config["Chutney"]["listen_address"]
+ chutney_src_dir = $config["Chutney"]["src_dir"]
+ chutney_script = "#{chutney_src_dir}/chutney"
+ network_definition = "#{GIT_DIR}/features/chutney/test-network"
+ env = { 'CHUTNEY_LISTEN_ADDRESS' => chutney_listen_address }
+ chutney_cleanup_hook = Proc.new do
+ Dir.chdir(chutney_src_dir) do
+ cmd_helper([chutney_script, "stop", network_definition], env)
+ FileUtils.rm_r("#{chutney_src_dir}/net")
+ end
+ end
+ Dir.chdir(chutney_src_dir) do
+ begin
+ cmd_helper([chutney_script, "status", network_definition], env)
+ rescue Test::Unit::AssertionFailedError
+ # chutney is not running so we're good to set up a fresh
+ # instance.
+ else
+ # We clean up any previous (aborted/crashed) test suite run's
+ # chutney instance to ensure that we're running the current
+ # defined version of the simulated Tor network.
+ chutney_cleanup_hook.call
+ end
+ cmd_helper([chutney_script, "configure", network_definition], env)
+ cmd_helper([chutney_script, "start", network_definition], env)
+ end
+ # Let's only add this hook once
+ if not($chutney_cleanup_hook_added)
+ at_exit do
+ chutney_cleanup_hook.call
+ end
+ $chutney_cleanup_hook_added = true
+ end
+
+ # Most of these lines are taken from chutney's client template.
+ client_torrc_lines = [
+ 'TestingTorNetwork 1',
+ 'AssumeReachable 1',
+ 'PathsNeededToBuildCircuits 0.25',
+ 'TestingDirAuthVoteExit *',
+ 'TestingDirAuthVoteHSDir *',
+ 'V3AuthNIntervalsValid 2',
+ 'TestingDirAuthVoteGuard *',
+ 'TestingMinExitFlagThreshold 0',
+ 'TestingClientDownloadSchedule 0, 5',
+ 'TestingClientConsensusDownloadSchedule 0, 5',
+ ]
+ # We run one client in chutney so we easily can grep the generated
+ # DirAuthority lines and use them.
+ dir_auth_lines = open("#{chutney_src_dir}/net/nodes/035c/torrc") do |f|
+ f.grep(/^DirAuthority\s/)
+ end
+ client_torrc_lines.concat(dir_auth_lines)
+ client_torrc_lines.each do |line|
+ @vm.file_append('/etc/tor/torrc', line)
+ end
+end
diff --git a/features/support/helpers/misc_helpers.rb b/features/support/helpers/misc_helpers.rb
index 4eccb25..800ecf7 100644
--- a/features/support/helpers/misc_helpers.rb
+++ b/features/support/helpers/misc_helpers.rb
@@ -108,13 +108,14 @@ def convert_from_bytes(size, unit)
return size.to_f/convert_bytes_mod(unit).to_f
end
-def cmd_helper(cmd)
+def cmd_helper(cmd, env = {})
if cmd.instance_of?(Array)
cmd << {:err => [:child, :out]}
elsif cmd.instance_of?(String)
cmd += " 2>&1"
end
- IO.popen(cmd) do |p|
+ env = ENV.to_h.merge(env)
+ IO.popen(env, cmd) do |p|
out = p.readlines.join("\n")
p.close
ret = $?