unsafe_browser.rb 7.98 KB
Newer Older
1
When /^I see and accept the Unsafe Browser start verification(?:| in the "([^"]+)" locale)$/ do |locale|
kytv's avatar
kytv committed
2
  @screen.wait('GnomeQuestionDialogIcon.png', 30)
3 4 5 6 7 8
  if ['ar_EG.utf8', 'fa_IR'].include?(locale)
    # Take into account button ordering in RTL languages
    @screen.type(Sikuli::Key.LEFT + Sikuli::Key.ENTER)
  else
    @screen.type(Sikuli::Key.RIGHT + Sikuli::Key.ENTER)
  end
9 10
end

11
def supported_torbrowser_languages
12 13 14 15
  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(':')
16 17
    candidates = ["#{first}_#{second}.UTF-8", "#{first}_#{second}.utf8",
                  "#{first}.UTF-8", "#{first}.utf8",
18 19 20
                  "#{first}_#{second}", first]
    when_not_found = Proc.new { raise "Could not find a locale for '#{line}'" }
    candidates.find(when_not_found) do |candidate|
21
      $vm.directory_exist?("/usr/lib/locale/#{candidate}")
22
    end
23 24 25
  end
end

26
Then /^I start the Unsafe Browser in the "([^"]+)" locale$/ do |loc|
27
  step "I run \"LANG=#{loc} LC_ALL=#{loc} sudo unsafe-browser\" in GNOME Terminal"
28
  step "I see and accept the Unsafe Browser start verification in the \"#{loc}\" locale"
29 30
end

31
Then /^the Unsafe Browser works in all supported languages$/ do
32
  failed = Array.new
33
  supported_torbrowser_languages.sample(3).each do |lang|
34
    step "I start the Unsafe Browser in the \"#{lang}\" locale"
35 36 37 38 39 40
    begin
      step "the Unsafe Browser has started"
    rescue RuntimeError
      failed << lang
      next
    end
41 42 43
    step "I close the Unsafe Browser"
    step "the Unsafe Browser chroot is torn down"
  end
44
  assert(failed.empty?, "Unsafe Browser failed to launch in the following locale(s): #{failed.join(', ')}")
45 46
end

47
Then /^the Unsafe Browser has no add-ons installed$/ do
48 49
  step "I open the address \"about:addons\" in the Unsafe Browser"
  step "I see \"UnsafeBrowserNoAddons.png\" after at most 30 seconds"
50 51
end

52 53 54 55 56 57 58 59 60 61
Then /^the Unsafe Browser has only Firefox's default bookmarks configured$/ do
  info = xul_application_info("Unsafe Browser")
  # "Show all bookmarks"
  @screen.type("o", Sikuli::KeyModifier.SHIFT + Sikuli::KeyModifier.CTRL)
  @screen.wait_and_click("UnsafeBrowserExportBookmarksButton.png", 20)
  @screen.wait_and_click("UnsafeBrowserExportBookmarksMenuEntry.png", 20)
  @screen.wait("UnsafeBrowserExportBookmarksSavePrompt.png", 20)
  path = "/home/#{info[:user]}/bookmarks"
  @screen.type(path + Sikuli::Key.ENTER)
  chroot_path = "#{info[:chroot]}/#{path}.json"
62 63
  try_for(10) { $vm.file_exist?(chroot_path) }
  dump = JSON.load($vm.file_content(chroot_path))
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93

  def check_bookmarks_helper(a)
    mozilla_uris_counter = 0
    places_uris_counter = 0
    a.each do |h|
      h.each_pair do |k, v|
        if k == "children"
          m, p = check_bookmarks_helper(v)
          mozilla_uris_counter += m
          places_uris_counter += p
        elsif k == "uri"
          uri = v
          if uri.match("^https://www\.mozilla\.org/")
            mozilla_uris_counter += 1
          elsif uri.match("^place:(sort|folder|type)=")
            places_uris_counter += 1
          else
            raise "Unexpected Unsafe Browser bookmark for '#{uri}'"
          end
        end
      end
    end
    return [mozilla_uris_counter, places_uris_counter]
  end

  mozilla_uris_counter, places_uris_counter =
    check_bookmarks_helper(dump["children"])
  assert_equal(5, mozilla_uris_counter,
               "Unexpected number (#{mozilla_uris_counter}) of mozilla " \
               "bookmarks")
94
  assert_equal(2, places_uris_counter,
95 96 97 98 99
               "Unexpected number (#{places_uris_counter}) of places " \
               "bookmarks")
  @screen.type(Sikuli::Key.F4, Sikuli::KeyModifier.ALT)
end

100 101 102 103 104
Then /^the Unsafe Browser has a red theme$/ do
  @screen.wait("UnsafeBrowserRedTheme.png", 10)
end

Then /^the Unsafe Browser shows a warning as its start page$/ do
intrigeri's avatar
intrigeri committed
105
  @screen.wait("UnsafeBrowserStartPage.png", 30)
106 107
end

108 109 110 111
Then /^the Unsafe Browser has started$/ do
  step 'the Unsafe Browser shows a warning as its start page'
end

112 113 114 115 116 117 118 119
Then /^I see a warning about another instance already running$/ do
  @screen.wait('UnsafeBrowserWarnAlreadyRunning.png', 10)
end

Then /^I can start the Unsafe Browser again$/ do
  step "I start the Unsafe Browser"
end

120
Then /^I cannot configure the Unsafe Browser to use any local proxies$/ do
121
  socks_proxy = 'C' # Alt+Shift+c for socks proxy
122
  no_proxy    = 'y' # Alt+y for no proxy
123 124
  proxies = [[no_proxy, nil, nil]]
  socksport_lines =
125
    $vm.execute_successfully('grep -w "^SocksPort" /etc/tor/torrc').stdout
126 127 128 129 130
  assert(socksport_lines.size >= 4, "We got fewer than four Tor SocksPorts")
  socksports = socksport_lines.scan(/^SocksPort\s([^:]+):(\d+)/)
  proxies += socksports.map { |host, port| [socks_proxy, host, port] }

  proxies.each do |proxy_type, proxy_host, proxy_port|
131 132
    @screen.hide_cursor

133
    # Open proxy settings
134 135
    @screen.click('UnsafeBrowserMenuButton.png')
    @screen.wait_and_click('UnsafeBrowserPreferencesButton.png', 10)
136 137 138 139 140
    @screen.wait_and_click('UnsafeBrowserAdvancedSettingsButton.png', 10)
    hit, _ = @screen.waitAny(['UnsafeBrowserNetworkTabAlreadySelected.png',
                              'UnsafeBrowserNetworkTab.png'], 10)
    @screen.click(hit) if hit == 'UnsafeBrowserNetworkTab.png'
    @screen.wait_and_click('UnsafeBrowserNetworkTabSettingsButton.png', 10)
141
    @screen.wait_and_click('UnsafeBrowserProxySettingsWindow.png', 10)
142

143 144 145 146 147 148 149 150 151
    # Ensure the desired proxy configuration
    if proxy_type == no_proxy
      @screen.type(proxy_type, Sikuli::KeyModifier.ALT)
      @screen.wait('UnsafeBrowserNoProxySelected.png', 10)
    else
      @screen.type("M", Sikuli::KeyModifier.ALT)
      @screen.type(proxy_type, Sikuli::KeyModifier.ALT)
      @screen.type(proxy_host + Sikuli::Key.TAB + proxy_port)
    end
152

Tails developers's avatar
Tails developers committed
153
    # Close settings
154
    @screen.click('UnsafeBrowserProxySettingsOkButton.png')
anonym's avatar
anonym committed
155
    @screen.waitVanish('UnsafeBrowserProxySettingsWindow.png', 10)
156 157

    # Test that the proxy settings work as they should
158
    step 'I open Tails homepage in the Unsafe Browser'
159
    if proxy_type == no_proxy
160
      step 'Tails homepage loads in the Unsafe Browser'
161 162 163 164 165
    else
      @screen.wait('UnsafeBrowserProxyRefused.png', 60)
    end
  end
end
166

167 168 169
Then /^the Unsafe Browser has no proxy configured$/ do
  @screen.click('UnsafeBrowserMenuButton.png')
  @screen.wait_and_click('UnsafeBrowserPreferencesButton.png', 10)
170
  @screen.wait_and_click('UnsafeBrowserAdvancedSettingsButton.png', 10)
171
  @screen.wait_and_click('UnsafeBrowserNetworkTab.png', 10)
anonym's avatar
anonym committed
172
  @screen.wait_and_click('UnsafeBrowserNetworkTabSettingsButton.png', 10)
anonym's avatar
anonym committed
173
  @screen.wait('UnsafeBrowserProxySettingsWindow.png', 10)
174 175
  @screen.wait('UnsafeBrowserNoProxySelected.png', 10)
  @screen.type(Sikuli::Key.F4, Sikuli::KeyModifier.ALT)
176
  @screen.type("w", Sikuli::KeyModifier.CTRL)
177 178
end

179
Then /^the Unsafe Browser complains that no DNS server is configured$/ do
180 181 182 183 184
  assert_not_nil(
    Dogtail::Application.new('zenity')
    .child(roleName: 'label')
    .text['No DNS server was obtained']
  )
185
end
186 187

Then /^I configure the Unsafe Browser to check for updates more frequently$/ do
anonym's avatar
anonym committed
188
  prefs = '/usr/share/tails/chroot-browsers/unsafe-browser/prefs.js'
189 190 191
  $vm.file_append(prefs, 'pref("app.update.idletime", 1);')
  $vm.file_append(prefs, 'pref("app.update.promptWaitTime", 1);')
  $vm.file_append(prefs, 'pref("app.update.interval", 5);')
192
end
193 194

But /^checking for updates is disabled in the Unsafe Browser's configuration$/ do
anonym's avatar
anonym committed
195
  prefs = '/usr/share/tails/chroot-browsers/common/prefs.js'
196
  assert($vm.file_content(prefs).include?('pref("app.update.enabled", false)'))
197
end
198 199

Then /^the clearnet user has (|not )sent packets out to the Internet$/ do |sent|
200
  uid = $vm.execute_successfully("id -u clearnet").stdout.chomp.to_i
201
  pkts = ip4tables_packet_counter_sum(:tables => ['OUTPUT'], :uid => uid)
202 203 204 205 206 207 208
  case sent
  when ''
    assert(pkts > 0, "Packets have not gone out to the internet.")
  when 'not'
    assert_equal(pkts, 0, "Packets have gone out to the internet.")
  end
end