From 32ab477a4dd3270c806466ec56e96c629ff6fd35 Mon Sep 17 00:00:00 2001 From: DrGFreeman Date: Wed, 18 Dec 2019 21:36:29 -0500 Subject: [PATCH] Add functional test for refreshing /generate page Add a functional test to verify the behavior when refreshing the /generate page when multiple instance of /generate are open simultaneously. --- .../functional/source_navigation_steps.py | 10 ++++ securedrop/tests/functional/test_source.py | 48 +++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/securedrop/tests/functional/source_navigation_steps.py b/securedrop/tests/functional/source_navigation_steps.py index dc5733a8a3..3778c30dc0 100644 --- a/securedrop/tests/functional/source_navigation_steps.py +++ b/securedrop/tests/functional/source_navigation_steps.py @@ -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() @@ -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 diff --git a/securedrop/tests/functional/test_source.py b/securedrop/tests/functional/test_source.py index e3e89b8f2f..8063d12a5e 100644 --- a/securedrop/tests/functional/test_source.py +++ b/securedrop/tests/functional/test_source.py @@ -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()