PageRenderTime 40ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/features/step_definitions/firewall_leaks.rb

https://gitlab.com/JesseW/tails
Ruby | 61 lines | 60 code | 1 blank | 0 comment | 3 complexity | 43757d7e57deb75a52d7499a663dfd93 MD5 | raw file
Possible License(s): GPL-3.0, CC-BY-3.0
  1. Then(/^the firewall leak detector has detected (.*?) leaks$/) do |type|
  2. next if @skip_steps_while_restoring_background
  3. leaks = FirewallLeakCheck.new(@sniffer.pcap_file,
  4. :accepted_hosts => get_all_tor_nodes)
  5. case type.downcase
  6. when 'ipv4 tcp'
  7. if leaks.ipv4_tcp_leaks.empty?
  8. leaks.save_pcap_file
  9. raise "Couldn't detect any IPv4 TCP leaks"
  10. end
  11. when 'ipv4 non-tcp'
  12. if leaks.ipv4_nontcp_leaks.empty?
  13. leaks.save_pcap_file
  14. raise "Couldn't detect any IPv4 non-TCP leaks"
  15. end
  16. when 'ipv6'
  17. if leaks.ipv6_leaks.empty?
  18. leaks.save_pcap_file
  19. raise "Couldn't detect any IPv6 leaks"
  20. end
  21. when 'non-ip'
  22. if leaks.nonip_leaks.empty?
  23. leaks.save_pcap_file
  24. raise "Couldn't detect any non-IP leaks"
  25. end
  26. else
  27. raise "Incorrect packet type '#{type}'"
  28. end
  29. end
  30. Given(/^I disable Tails' firewall$/) do
  31. next if @skip_steps_while_restoring_background
  32. @vm.execute("do_not_ever_run_me")
  33. iptables = @vm.execute("iptables -L -n -v").stdout.chomp.split("\n")
  34. for line in iptables do
  35. if !line[/Chain (INPUT|OUTPUT|FORWARD) \(policy ACCEPT/] and
  36. !line[/pkts[[:blank:]]+bytes[[:blank:]]+target/] and
  37. !line.empty?
  38. raise "The Tails firewall was not successfully disabled:\n#{iptables}"
  39. end
  40. end
  41. end
  42. When(/^I do a TCP DNS lookup of "(.*?)"$/) do |host|
  43. next if @skip_steps_while_restoring_background
  44. lookup = @vm.execute("host -T #{host} #{SOME_DNS_SERVER}", LIVE_USER)
  45. assert(lookup.success?, "Failed to resolve #{host}:\n#{lookup.stdout}")
  46. end
  47. When(/^I do a UDP DNS lookup of "(.*?)"$/) do |host|
  48. next if @skip_steps_while_restoring_background
  49. lookup = @vm.execute("host #{host} #{SOME_DNS_SERVER}", LIVE_USER)
  50. assert(lookup.success?, "Failed to resolve #{host}:\n#{lookup.stdout}")
  51. end
  52. When(/^I send some ICMP pings$/) do
  53. next if @skip_steps_while_restoring_background
  54. # We ping an IP address to avoid a DNS lookup
  55. ping = @vm.execute("ping -c 5 #{SOME_DNS_SERVER}", LIVE_USER)
  56. assert(ping.success?, "Failed to ping #{SOME_DNS_SERVER}:\n#{ping.stderr}")
  57. end