unsafe_browser.rb 8.63 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 7 8 9 10
  @screen.type(Sikuli::Key.ESC)
end

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

13 14 15 16 17 18
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

19
Then /^the Unsafe Browser has started$/ do
20
  next if @skip_steps_while_restoring_background
21
  @screen.wait("UnsafeBrowserHomepage.png", 360)
22 23
end

24 25 26 27 28 29
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

30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
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

79
Then /^the Unsafe Browser has a red theme$/ do
80
  next if @skip_steps_while_restoring_background
81 82 83 84
  @screen.wait("UnsafeBrowserRedTheme.png", 10)
end

Then /^the Unsafe Browser shows a warning as its start page$/ do
85
  next if @skip_steps_while_restoring_background
86 87 88 89
  @screen.wait("UnsafeBrowserStartPage.png", 10)
end

When /^I start the Unsafe Browser$/ do
90
  next if @skip_steps_while_restoring_background
91
  step 'I start "UnsafeBrowser" via the GNOME "Internet" applications menu'
92 93 94 95 96
end

When /^I successfully start the Unsafe Browser$/ do
  next if @skip_steps_while_restoring_background
  step "I start the Unsafe Browser"
97
  step "I see and accept the Unsafe Browser start verification"
98
  step "I see the Unsafe Browser start notification and wait for it to close"
99
  step "the Unsafe Browser has started"
100 101 102
end

Then /^I see a warning about another instance already running$/ do
103
  next if @skip_steps_while_restoring_background
104 105 106
  @screen.wait('UnsafeBrowserWarnAlreadyRunning.png', 10)
end

Tails developers's avatar
Tails developers committed
107
When /^I close the Unsafe Browser$/ do
108
  next if @skip_steps_while_restoring_background
109
  @screen.type("q", Sikuli::KeyModifier.CTRL)
110 111
end

112 113 114 115 116 117
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

118
Then /^I can start the Unsafe Browser again$/ do
119
  next if @skip_steps_while_restoring_background
120 121 122
  step "I start the Unsafe Browser"
end

123
Then /^I cannot configure the Unsafe Browser to use any local proxies$/ do
124
  next if @skip_steps_while_restoring_background
125
  @screen.wait_and_click("UnsafeBrowserWindow.png", 10)
126 127
  # First we open the proxy settings page to prepare it with the
  # correct open tabs for the loop below.
128 129
  @screen.click('UnsafeBrowserMenuButton.png')
  @screen.wait_and_click('UnsafeBrowserPreferencesButton.png', 10)
130
  @screen.wait('UnsafeBrowserPreferencesWindow.png', 10)
131 132
  @screen.wait_and_click('UnsafeBrowserAdvancedSettings.png', 10)
  @screen.wait_and_click('UnsafeBrowserNetworkTab.png', 10)
133
  sleep 0.5
134
  @screen.type(Sikuli::Key.ESC)
135 136
#  @screen.waitVanish('UnsafeBrowserPreferences.png', 10)
  sleep 0.5
137 138 139 140 141 142 143

  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],
144
             [socks_proxy, 9150],
145 146 147 148 149 150
             [no_proxy,       0]]

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

151 152
    @screen.hide_cursor

153
    # Open proxy settings and select manual proxy configuration
154 155
    @screen.click('UnsafeBrowserMenuButton.png')
    @screen.wait_and_click('UnsafeBrowserPreferencesButton.png', 10)
156
    @screen.wait('UnsafeBrowserPreferencesWindow.png', 10)
157
    @screen.type("e", Sikuli::KeyModifier.ALT)
158
    @screen.wait('UnsafeBrowserProxySettings.png', 10)
159
    @screen.type("m", Sikuli::KeyModifier.ALT)
160 161

    # Configure the proxy
162 163
    @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
164

Tails developers's avatar
Tails developers committed
165
    # Close settings
166
    @screen.type(Sikuli::Key.ENTER)
167 168
#    @screen.waitVanish('UnsafeBrowserProxySettings.png', 10)
    sleep 0.5
169
    @screen.type(Sikuli::Key.ESC)
170 171
#    @screen.waitVanish('UnsafeBrowserPreferences.png', 10)
    sleep 0.5
172 173 174 175 176 177 178 179 180 181

    # 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
182

183 184 185 186 187 188 189 190 191 192 193 194 195 196
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

197 198 199 200
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
201 202 203 204 205 206 207 208

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
209 210 211 212 213 214

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
215 216 217 218 219 220 221 222

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
223
    if /owner UID match \b#{uid}\b/.match(rule["extra"])
224
      pkts += rule["pkts"]
225 226 227 228 229 230 231 232 233 234
    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