GitLab is used only for code review, issue tracking and project management. Canonical locations for source code are still https://gitweb.torproject.org/ https://git.torproject.org/ and git-rw.torproject.org.

Commit fe257166 authored by Alex Catarineu's avatar Alex Catarineu

Bug 40003: Add test for 'Implement Onion-Location' TB patch

parent a6c55026
...@@ -482,6 +482,12 @@ our @tests = ( ...@@ -482,6 +482,12 @@ our @tests = (
use_net => 1, use_net => 1,
descr => 'Check onion security expectations', descr => 'Check onion security expectations',
}, },
{
name => 'onion_location',
type => 'marionette',
use_net => 1,
descr => 'Check that Onion-Location header handling works correctly',
},
); );
sub set_test_prefs { sub set_test_prefs {
......
from marionette_driver import By, Wait
from marionette_driver.errors import MarionetteException, NoSuchElementException, TimeoutException
from marionette_harness import MarionetteTestCase, WindowManagerMixin
class Test(WindowManagerMixin, MarionetteTestCase):
def test_onion_location(self):
m = self.marionette
m.timeout.implicit = 10
self.assertEqual(None, m.get_pref(
'privacy.prioritizeonions.showNotification'))
with m.using_context('content'):
m.navigate('https://www.torproject.org/')
with m.using_context('chrome'):
# Check whether the urlbar badge is displayed
self.assertTrue(m.find_element(
'id', 'onion-location-box').is_displayed())
# Check whether the notification is displayed the first time
notification = m.find_element('id', 'onion-location-notification')
self.assertTrue(notification.is_displayed())
self.assertFalse(m.get_pref(
'privacy.prioritizeonions.showNotification'))
always_prioritize = notification.find_element(
'css selector', '.popup-notification-primary-button')
self.assertEqual(always_prioritize.get_attribute(
'label'), 'Always Prioritize Onions')
# Check learn more link
notification.find_element(
'css selector', '.popup-notification-learnmore-link').click()
with m.using_context('content'):
Wait(m, timeout=m.timeout.page_load).until(
lambda _: len(m.window_handles) > 1)
m.switch_to_window(m.window_handles[1])
Wait(m, timeout=m.timeout.page_load).until(
lambda _: m.get_url() != "about:blank")
self.assertEqual(
m.get_url(), "https://tb-manual.torproject.org/onion-services/")
m.close()
m.switch_to_window(m.window_handles[0])
with m.using_context('chrome'):
# Close the notification and check that it's not displayed anymore.
notification = m.find_element('id', 'onion-location-notification')
not_now = notification.find_element(
'css selector', '.popup-notification-secondary-button')
self.assertEqual(not_now.get_attribute('label'), 'Not Now')
not_now.click()
try:
self.assertFalse(m.find_element(
'id', 'onion-location-notification').is_displayed())
except NoSuchElementException:
pass
# Show the notification again
m.set_pref('privacy.prioritizeonions.showNotification', None)
new_tab = self.open_tab()
m.switch_to_window(new_tab)
m.close()
m.switch_to_window(self.start_tab)
# Click "Always prioritize" in the notification
notification = m.find_element('id', 'onion-location-notification')
notification.find_element(
'css selector', '.popup-notification-primary-button').click()
self.assertTrue(m.get_pref('privacy.prioritizeonions.enabled'))
with m.using_context('content'):
m.switch_to_window(m.window_handles[1])
self.assertEqual(
m.get_url(), 'about:preferences#privacy-onionservices')
m.close()
m.switch_to_window(self.start_tab)
# Check that the original page is redirected to .onion
Wait(m, timeout=m.timeout.page_load).until(
lambda _: m.get_url() != 'https://www.torproject.org/')
self.assertEqual(
m.get_url(), 'http://expyuzz4wqqyqhjn.onion/index.html')
# Check that auto-redirects work
m.navigate('https://www.torproject.org/')
self.assertEqual(m.get_url(), 'https://www.torproject.org/')
Wait(m, timeout=m.timeout.page_load).until(
lambda _: m.get_url() != 'https://www.torproject.org/')
self.assertEqual(
m.get_url(), 'http://expyuzz4wqqyqhjn.onion/index.html')
# Go to preferences and disable auto-redirects
new_tab = self.open_tab()
m.switch_to_window(new_tab)
m.navigate('about:preferences#privacy-onionservices')
m.find_element('id', 'onionServicesRadioAsk').click()
self.assertFalse(m.get_pref(
'privacy.prioritizeonions.enabled'))
m.close()
m.switch_to_window(self.start_tab)
m.navigate('https://www.torproject.org/')
try:
Wait(m, timeout=5).until(lambda _: m.get_url()
!= 'https://www.torproject.org/')
self.assertTrue(False, "Should not redirect")
except TimeoutException:
pass
# Check that the page is redirected when clicking on the urlbar badge
with m.using_context('chrome'):
self.assertTrue(m.find_element(
'id', 'onion-location-box').is_displayed())
m.find_element('id', 'onion-location-box').click()
with m.using_context('content'):
Wait(m, timeout=5).until(lambda _: m.get_url()
!= 'https://www.torproject.org/')
self.assertEqual(
m.get_url(), 'http://expyuzz4wqqyqhjn.onion/index.html')
# Check learn more link
with m.using_context('content'):
m.navigate('about:preferences#privacy-onionservices')
m.find_element('id', 'onionServicesLearnMore').click()
Wait(m, timeout=m.timeout.page_load).until(
lambda _: len(m.window_handles) > 1)
m.switch_to_window(m.window_handles[1])
Wait(m, timeout=m.timeout.page_load).until(
lambda _: m.get_url() != "about:blank")
self.assertEqual(
m.get_url(), "https://tb-manual.torproject.org/onion-services/")
m.close()
m.switch_to_window(m.window_handles[0])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment