unsafe_browser.rb 9.95 KB
Newer Older
1
When /^I see and accept the Unsafe Browser start verification$/ do
2
  next if @skip_steps_while_restoring_background
Tails developers's avatar
Tails developers committed
3
  @screen.wait("UnsafeBrowserStartVerification.png", 30)
4 5 6
  @screen.type(Sikuli::Key.ESC)
end

7 8 9 10
def supported_torbrowser_languages
  langs = []
  exts = @vm.execute_successfully(
    "find /usr/local/share/tor-browser-extensions -maxdepth 1 -name 'langpack*.xpi' -printf \"%f\n\"").stdout
11 12 13 14 15

  # Some of the TBB languages are shipped with both a language and country code, e.g. es-ES.
  # We'll only keep track of the language code and let `guess_best_tor_browser_locale`
  # try to get by with our approximated locales.
  supported_langs = exts.scan(/langpack-([a-z]+).*/).flatten
16
  locales = @vm.execute_successfully(
kytv's avatar
kytv committed
17
    "find /usr/lib/locale -maxdepth 1 -name '*.utf8' -printf \"%f\n\"").stdout.split
18 19 20

  # Determine a valid locale for each language that we want to test.
  supported_langs.each do |lang|
kytv's avatar
kytv committed
21 22
    # If a language shipped by TBB is not a supported system locale (e.g. 'vi'),
    # 'find(nomatch)' will use the locale xx_XX for language 'xx'.
kytv's avatar
kytv committed
23
    nomatch = proc { "#{lang}_#{lang.upcase}.utf8" }
24
    langs << locales.find(nomatch) { |l| l.match(/^#{lang}/) }
25 26 27 28
  end
  return langs
end

29 30
Then /^I start the Unsafe Browser in the "([^"]+)" locale$/ do |loc|
  next if @skip_steps_while_restoring_background
31
  step "I run \"LANG=#{loc} LC_ALL=#{loc} sudo unsafe-browser\" in GNOME Terminal"
32
  step "I see and accept the Unsafe Browser start verification"
33 34
end

35 36
Then /^the Unsafe Browser works in all supported languages$/ do
  next if @skip_steps_while_restoring_background
kytv's avatar
kytv committed
37
  supported_torbrowser_languages.each do |lang|
38 39 40 41 42 43 44
    step "I start the Unsafe Browser in the \"#{lang}\" locale"
    step "the Unsafe Browser has started"
    step "I close the Unsafe Browser"
    step "the Unsafe Browser chroot is torn down"
  end
end

45 46 47 48 49 50
Then /^I see the Unsafe Browser start notification and wait for it to close$/ do
  next if @skip_steps_while_restoring_background
  @screen.wait("UnsafeBrowserStartNotification.png", 30)
  @screen.waitVanish("UnsafeBrowserStartNotification.png", 10)
end

51
Then /^the Unsafe Browser has started$/ do
52
  next if @skip_steps_while_restoring_background
53
  @screen.wait("UnsafeBrowserHomepage.png", 360)
54 55
end

56 57 58 59 60 61
Then /^the Unsafe Browser has no add-ons installed$/ do
  next if @skip_steps_while_restoring_background
  step "I open the address \"about:addons\" in the Unsafe Browser"
  step "I see \"UnsafeBrowserNoAddons.png\" after at most 30 seconds"
end

62 63 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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
Then /^the Unsafe Browser has only Firefox's default bookmarks configured$/ do
  next if @skip_steps_while_restoring_background
  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"
  try_for(10) { @vm.file_exist?(chroot_path) }
  dump = JSON.load(@vm.file_content(chroot_path))

  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")
  assert_equal(3, places_uris_counter,
               "Unexpected number (#{places_uris_counter}) of places " \
               "bookmarks")
  @screen.type(Sikuli::Key.F4, Sikuli::KeyModifier.ALT)
end

111
Then /^the Unsafe Browser has a red theme$/ do
112
  next if @skip_steps_while_restoring_background
113 114 115 116
  @screen.wait("UnsafeBrowserRedTheme.png", 10)
end

Then /^the Unsafe Browser shows a warning as its start page$/ do
117
  next if @skip_steps_while_restoring_background
118 119 120 121
  @screen.wait("UnsafeBrowserStartPage.png", 10)
end

When /^I start the Unsafe Browser$/ do
122
  next if @skip_steps_while_restoring_background
123
  step 'I start "UnsafeBrowser" via the GNOME "Internet" applications menu'
124 125 126 127 128
end

When /^I successfully start the Unsafe Browser$/ do
  next if @skip_steps_while_restoring_background
  step "I start the Unsafe Browser"
129
  step "I see and accept the Unsafe Browser start verification"
130
  step "I see the Unsafe Browser start notification and wait for it to close"
131
  step "the Unsafe Browser has started"
132 133 134
end

Then /^I see a warning about another instance already running$/ do
135
  next if @skip_steps_while_restoring_background
136 137 138
  @screen.wait('UnsafeBrowserWarnAlreadyRunning.png', 10)
end

Tails developers's avatar
Tails developers committed
139
When /^I close the Unsafe Browser$/ do
140
  next if @skip_steps_while_restoring_background
141
  @screen.type("q", Sikuli::KeyModifier.CTRL)
142 143
end

144 145 146 147 148 149
Then /^I see the Unsafe Browser stop notification$/ do
  next if @skip_steps_while_restoring_background
  @screen.wait('UnsafeBrowserStopNotification.png', 20)
  @screen.waitVanish('UnsafeBrowserStopNotification.png', 10)
end

150
Then /^I can start the Unsafe Browser again$/ do
151
  next if @skip_steps_while_restoring_background
152 153 154
  step "I start the Unsafe Browser"
end

155
Then /^I cannot configure the Unsafe Browser to use any local proxies$/ do
156
  next if @skip_steps_while_restoring_background
157
  @screen.wait_and_click("UnsafeBrowserWindow.png", 10)
158 159
  # First we open the proxy settings page to prepare it with the
  # correct open tabs for the loop below.
160 161
  @screen.click('UnsafeBrowserMenuButton.png')
  @screen.wait_and_click('UnsafeBrowserPreferencesButton.png', 10)
162
  @screen.wait('UnsafeBrowserPreferencesWindow.png', 10)
163 164
  @screen.wait_and_click('UnsafeBrowserAdvancedSettings.png', 10)
  @screen.wait_and_click('UnsafeBrowserNetworkTab.png', 10)
165
  sleep 0.5
166
  @screen.type(Sikuli::Key.ESC)
167 168
#  @screen.waitVanish('UnsafeBrowserPreferences.png', 10)
  sleep 0.5
169 170 171 172 173 174 175

  socks_proxy = 'c' # Alt+c for socks proxy
  no_proxy    = 'y' # Alt+y for no proxy

  proxies = [[socks_proxy, 9050],
             [socks_proxy, 9061],
             [socks_proxy, 9062],
176
             [socks_proxy, 9150],
177 178 179 180 181 182
             [no_proxy,       0]]

  proxies.each do |proxy|
    proxy_type = proxy[0]
    proxy_port = proxy[1]

183 184
    @screen.hide_cursor

185
    # Open proxy settings and select manual proxy configuration
186 187
    @screen.click('UnsafeBrowserMenuButton.png')
    @screen.wait_and_click('UnsafeBrowserPreferencesButton.png', 10)
188
    @screen.wait('UnsafeBrowserPreferencesWindow.png', 10)
189
    @screen.type("e", Sikuli::KeyModifier.ALT)
190
    @screen.wait('UnsafeBrowserProxySettings.png', 10)
191
    @screen.type("m", Sikuli::KeyModifier.ALT)
192 193

    # Configure the proxy
194 195
    @screen.type(proxy_type, Sikuli::KeyModifier.ALT)  # Select correct proxy type
    @screen.type("127.0.0.1" + Sikuli::Key.TAB + "#{proxy_port}") if proxy_type != no_proxy
196

Tails developers's avatar
Tails developers committed
197
    # Close settings
198
    @screen.type(Sikuli::Key.ENTER)
199 200
#    @screen.waitVanish('UnsafeBrowserProxySettings.png', 10)
    sleep 0.5
201
    @screen.type(Sikuli::Key.ESC)
202 203
#    @screen.waitVanish('UnsafeBrowserPreferences.png', 10)
    sleep 0.5
204 205 206 207 208 209 210 211 212 213

    # Test that the proxy settings work as they should
    step "I open the address \"https://check.torproject.org\" in the Unsafe Browser"
    if proxy_type == no_proxy
      @screen.wait('UnsafeBrowserTorCheckFail.png', 60)
    else
      @screen.wait('UnsafeBrowserProxyRefused.png', 60)
    end
  end
end
214

215 216 217 218 219 220 221 222 223 224 225 226 227 228
Then /^the Unsafe Browser has no proxy configured$/ do
  next if @skip_steps_while_restoring_background
  @screen.click('UnsafeBrowserMenuButton.png')
  @screen.wait_and_click('UnsafeBrowserPreferencesButton.png', 10)
  @screen.wait('UnsafeBrowserPreferencesWindow.png', 10)
  @screen.wait_and_click('UnsafeBrowserAdvancedSettings.png', 10)
  @screen.wait_and_click('UnsafeBrowserNetworkTab.png', 10)
  @screen.type("e", Sikuli::KeyModifier.ALT)
  @screen.wait('UnsafeBrowserProxySettings.png', 10)
  @screen.wait('UnsafeBrowserNoProxySelected.png', 10)
  @screen.type(Sikuli::Key.F4, Sikuli::KeyModifier.ALT)
  @screen.type(Sikuli::Key.F4, Sikuli::KeyModifier.ALT)
end

229 230 231 232
Then /^the Unsafe Browser complains that no DNS server is configured$/ do
  next if @skip_steps_while_restoring_background
  @screen.wait("UnsafeBrowserDNSError.png", 30)
end
233 234 235 236 237 238 239 240

Then /^I configure the Unsafe Browser to check for updates more frequently$/ do
  next if @skip_steps_while_restoring_background
  prefs = '/usr/share/tails/unsafe-browser/prefs.js'
  @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);')
end
241 242 243 244 245 246

But /^checking for updates is disabled in the Unsafe Browser's configuration$/ do
  next if @skip_steps_while_restoring_background
  prefs = '/usr/share/tails/unsafe-browser/prefs.js'
  assert(@vm.file_content(prefs).include?('pref("app.update.enabled", false)'))
end
247 248 249 250 251 252 253 254

Then /^the clearnet user has (|not )sent packets out to the Internet$/ do |sent|
  next if @skip_steps_while_restoring_background
  pkts = 0
  uid = @vm.execute_successfully("id -u clearnet").stdout.chomp.to_i
  iptables_output = @vm.execute_successfully("iptables -vnL").stdout.chomp
  output_chain = iptables_parse(iptables_output)["OUTPUT"]
  output_chain["rules"].each do |rule|
Tails developers's avatar
Tails developers committed
255
    if /owner UID match \b#{uid}\b/.match(rule["extra"])
256
      pkts += rule["pkts"]
257 258 259 260 261 262 263 264 265 266
    end
  end

  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