Skip to content

Commit

Permalink
swapped constants for magic numbers, cleaned up time.sleep()s
Browse files Browse the repository at this point in the history
  • Loading branch information
zenmonkeykstop committed Nov 13, 2019
1 parent c6d78ed commit 118a95b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
23 changes: 14 additions & 9 deletions securedrop/tests/functional/functional_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
FIREFOX = "firefox"
TORBROWSER = "torbrowser"

TBB_SECURITY_HIGH = 1
TBB_SECURITY_MEDIUM = 3 # '2' corresponds to deprecated TBB medium-high setting
TBB_SECURITY_LOW = 4


class FunctionalTest(object):
gpg = None
Expand All @@ -79,7 +83,11 @@ def _unused_port(self):
s.close()
return port

def set_tbb_securitylevel(self, toLevel):
def set_tbb_securitylevel(self, level):

if level not in {TBB_SECURITY_HIGH, TBB_SECURITY_MEDIUM, TBB_SECURITY_LOW}:
raise ValueError("Invalid Tor Brouser security setting: " + str(level))

if self.torbrowser_driver is None:
self.create_torbrowser_driver()
driver = self.torbrowser_driver
Expand All @@ -90,16 +98,13 @@ def set_tbb_securitylevel(self, toLevel):
accept_risk_button.click()
ActionChains(driver).send_keys(Keys.RETURN).\
send_keys("extensions.torbutton.security_slider").perform()
time.sleep(2)
time.sleep(1)
ActionChains(driver).send_keys(Keys.TAB).\
send_keys(Keys.RETURN).perform()
time.sleep(2)
alert = driver.switch_to.alert
time.sleep(2)
alert.send_keys(str(toLevel))
time.sleep(2)
alert.accept()
time.sleep(2)
alert = self.wait_for(lambda: driver.switch_to.alert)
alert.send_keys(str(level))
time.sleep(1)
self.wait_for(lambda: alert.accept())

def create_torbrowser_driver(self):
logging.info("Creating TorBrowserDriver")
Expand Down
9 changes: 5 additions & 4 deletions securedrop/tests/functional/test_journalist.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

from . import functional_test
from . import functional_test as ft
from . import journalist_navigation_steps
from . import source_navigation_steps



class TestJournalist(
functional_test.FunctionalTest,
ft.FunctionalTest,
source_navigation_steps.SourceNavigationStepsMixin,
journalist_navigation_steps.JournalistNavigationStepsMixin,
):
Expand Down Expand Up @@ -66,8 +67,8 @@ def test_journalist_interface_ui_with_modal(self):
self._source_logs_out()

# Toggle security slider to force prefs change
self.set_tbb_securitylevel(1)
self.set_tbb_securitylevel(4)
self.set_tbb_securitylevel(ft.TBB_SECURITY_HIGH)
self.set_tbb_securitylevel(ft.TBB_SECURITY_LOW)

self._journalist_logs_in()
self._journalist_uses_js_filter_by_sources()
Expand Down

0 comments on commit 118a95b

Please sign in to comment.