Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed time.sleep()s, updated TBB version in Dockerfile #3870

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions securedrop/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ RUN gem install sass -v 3.4.23
ENV FF_ESR_VER 60.2.0esr
RUN curl -LO https://ftp.mozilla.org/pub/firefox/releases/${FF_ESR_VER}/linux-x86_64/en-US/firefox-${FF_ESR_VER}.tar.bz2 && \
curl -LO https://ftp.mozilla.org/pub/firefox/releases/${FF_ESR_VER}/linux-x86_64/en-US/firefox-${FF_ESR_VER}.tar.bz2.asc && \
gpg --recv-key --keyserver keys.gnupg.net 0x61B7B526D98F0353 && \
gpg --recv-key --keyserver gpg.mozilla.org 0x61B7B526D98F0353 && \
gpg --verify firefox-${FF_ESR_VER}.tar.bz2.asc && \
tar xjf firefox-*.tar.bz2 && \
mv firefox /usr/bin && \
paxctl -cm /usr/bin/firefox/firefox

COPY ./tor_project_public.pub /opt/

ENV TBB_VERSION 8.0.1
ENV TBB_VERSION 8.0.3
RUN gpg --import /opt/tor_project_public.pub && \
wget https://www.torproject.org/dist/torbrowser/${TBB_VERSION}/tor-browser-linux64-${TBB_VERSION}_en-US.tar.xz && \
wget https://www.torproject.org/dist/torbrowser/${TBB_VERSION}/tor-browser-linux64-${TBB_VERSION}_en-US.tar.xz.asc && \
Expand Down
2 changes: 1 addition & 1 deletion securedrop/requirements/test-requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ py
pytest
pytest-cov
pytest-mock
requests[socks]
requests[socks]>2.19.1
selenium
tbselenium
pyvirtualdisplay
2 changes: 1 addition & 1 deletion securedrop/requirements/test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pytest-cov==2.5.1
pytest-mock==1.7.1
pytest==3.3.2
pyvirtualdisplay==0.2.1
requests[socks]==2.19.1
requests[socks]==2.21.0
selenium==3.13.0
six==1.11.0 # via mock, pip-tools, pytest
werkzeug==0.14.1 # via flask
Expand Down
52 changes: 45 additions & 7 deletions securedrop/tests/functional/functional_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@

from db import db

TBB_PATH = abspath(join(expanduser('~'), '.local/tbb/tor-browser_en-US/'))
os.environ['TBB_PATH'] = TBB_PATH
TBBRC = join(TBB_PATH, 'Browser/TorBrowser/Data/Tor/torrc')

os.environ['SECUREDROP_ENV'] = 'test' # noqa

FUNCTIONAL_TEST_DIR = abspath(dirname(__file__))
LOGFILE_PATH = abspath(join(FUNCTIONAL_TEST_DIR, 'firefox.log'))
FILES_DIR = abspath(join(dirname(realpath(__file__)), '../..', 'tests/files'))
Expand Down Expand Up @@ -203,7 +209,6 @@ def init_gpg(self):
return gpg

def setup(self, session_expiration=30):

self.localtesting = False
self.driver = None
self.second_driver = None
Expand All @@ -223,7 +228,7 @@ def setup(self, session_expiration=30):
self.hidservauth = data.get('hidserv_token', '')
self.admin_user = data.get('user')
self.admin_user['totp'] = pyotp.TOTP(self.admin_user['secret'])
self.sleep_time = data.get('sleep_time', 10)
self.sleep_time = data.get('sleep_time', 20)
if self.hidservauth:
if self.journalist_location.startswith('http://'):
location = self.journalist_location[7:]
Expand Down Expand Up @@ -271,7 +276,7 @@ def setup(self, session_expiration=30):
" profanity oil chewy"),
"secret": "JHCOGO7VCER3EJ4L"}
self.admin_user['totp'] = pyotp.TOTP(self.admin_user['secret'])
self.sleep_time = 2
self.sleep_time = 10

def start_source_server(app):
config.SESSION_EXPIRATION_MINUTES = self.session_expiration
Expand Down Expand Up @@ -359,10 +364,13 @@ def teardown(self):
def create_new_totp(self, secret):
self.new_totp = pyotp.TOTP(secret)

def wait_for(self, function_with_assertion, timeout=5):
def wait_for(self, function_with_assertion, timeout=None):
"""Polling wait for an arbitrary assertion."""
# Thanks to
# http://chimera.labs.oreilly.com/books/1234000000754/ch20.html#_a_common_selenium_problem_race_conditions
if not timeout:
timeout = self.sleep_time

start_time = time.time()
while time.time() - start_time < timeout:
try:
Expand All @@ -372,19 +380,49 @@ def wait_for(self, function_with_assertion, timeout=5):
# one more try, which will raise any errors if they are outstanding
return function_with_assertion()

def safe_click_by_id(self, id):
self.wait_for(lambda: self.driver.find_element_by_id(id))

el = self.driver.find_element_by_id(id)

self.wait_for(lambda: el.is_enabled() and
el.is_displayed)

el.location_once_scrolled_into_view
actions = ActionChains(self.driver)
actions.move_to_element(el)
actions.perform()

el.click()

def safe_click_by_css_selector(self, selector):
self.wait_for(lambda:
self.driver.find_element_by_css_selector(selector))

el = self.driver.find_element_by_css_selector(selector)

self.wait_for(lambda: el.is_enabled() and
el.is_displayed)

el.location_once_scrolled_into_view
actions = ActionChains(self.driver)
actions.move_to_element(el).perform()

el.click()

def _alert_wait(self):
WebDriverWait(self.driver, 10).until(
WebDriverWait(self.driver, self.sleep_time * 6).until(
expected_conditions.alert_is_present(),
'Timed out waiting for confirmation popup.')

def _alert_accept(self):
self.driver.switch_to.alert.accept()
WebDriverWait(self.driver, 10).until(
WebDriverWait(self.driver, self.sleep_time).until(
alert_is_not_present(),
'Timed out waiting for confirmation popup to disappear.')

def _alert_dismiss(self):
self.driver.switch_to.alert.dismiss()
WebDriverWait(self.driver, 10).until(
WebDriverWait(self.driver, self.sleep_time).until(
alert_is_not_present(),
'Timed out waiting for confirmation popup to disappear.')
Loading