Skip to content

Commit

Permalink
Add functional test for refreshing /generate page
Browse files Browse the repository at this point in the history
Add a functional test to verify the behavior when refreshing the
/generate page when multiple instance of /generate are open
simultaneously.
  • Loading branch information
DrGFreeman committed Dec 19, 2019
1 parent 925dee3 commit 32ab477
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
10 changes: 10 additions & 0 deletions securedrop/tests/functional/source_navigation_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def _source_clicks_submit_documents_on_homepage(self):
# a diceware codename they can use for subsequent logins
assert self._is_on_generate_page()

def _source_regenerates_codename(self):
self.safe_click_by_id("regenerate-submit")

def _source_chooses_to_submit_documents(self):
self._source_clicks_submit_documents_on_homepage()

Expand Down Expand Up @@ -231,3 +234,10 @@ def _source_sees_already_logged_in_in_other_tab_message(self):
if not hasattr(self, "accepted_languages"):
expected_text = "You are already logged in."
assert expected_text in notification.text

def _source_sees_redirect_already_logged_in_message(self):
notification = self.driver.find_element_by_css_selector(".notification")

if not hasattr(self, "accepted_languages"):
expected_text = "You were redirected because you are already logged in."
assert expected_text in notification.text
48 changes: 48 additions & 0 deletions securedrop/tests/functional/test_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,51 @@ def test_duplicate_generate_pages(self):
# We expect the codename to be the one from Tab A
assert codename_lookup_b == codename_a
self._source_submits_a_message()

def test_duplicate_generate_pages_with_refresh(self):
# Test generation of multiple codenames in different browser tabs, including behavior
# of refreshing the codemae in each tab. Ref. issue 4458.

# Generate a codename in Tab A
assert len(self.driver.window_handles) == 1
tab_a = self.driver.current_window_handle
self._source_visits_source_homepage()
self._source_chooses_to_submit_documents()
codename_a1 = self.get_codename_generate()
# Regenerate codename in Tab A
self._source_regenerates_codename()
codename_a2 = self.get_codename_generate()
assert codename_a1 != codename_a2

# Generate a different codename in Tab B
self.driver.execute_script("window.open()")
tab_b = self.driver.window_handles[1]
self.driver.switch_to.window(tab_b)
assert self.driver.current_window_handle == tab_b
self._source_visits_source_homepage()
self._source_chooses_to_submit_documents()
codename_b = self.get_codename_generate()
assert codename_b != codename_a1 != codename_a2

# Proceed to submit documents in Tab A
self.driver.switch_to.window(tab_a)
assert self.driver.current_window_handle == tab_a
self._source_continues_to_submit_page()
assert self._is_on_lookup_page()
self._source_shows_codename(verify_source_name=False)
codename_lookup_a = self.get_codename_lookup()
assert codename_lookup_a == codename_a2
self._source_submits_a_message()

# Regenerate codename in Tab B
self.driver.switch_to.window(tab_b)
assert self.driver.current_window_handle == tab_b
self._source_regenerates_codename()
# We expect the source to be directed to /lookup with a flash message
assert self._is_on_lookup_page()
self._source_sees_redirect_already_logged_in_message()
# Check codename
self._source_shows_codename(verify_source_name=False)
codename_lookup_b = self.get_codename_lookup()
assert codename_lookup_b == codename_a2
self._source_submits_a_message()

0 comments on commit 32ab477

Please sign in to comment.