Skip to content

Commit 6e5cb05

Browse files
fixed tests in functional/test_source.py
1 parent 459893f commit 6e5cb05

File tree

2 files changed

+24
-99
lines changed

2 files changed

+24
-99
lines changed

securedrop/tests/functional/app_navigators.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,11 @@ def source_clicks_submit_documents_on_homepage(self) -> None:
178178
assert self._is_on_lookup_page()
179179

180180
def source_continues_to_submit_page(self) -> None:
181-
self.nav_helper.safe_click_by_css_selector("#create-form button")
182181

183182
def submit_page_loaded() -> None:
184183
if not self.accept_languages:
185-
headline = self.driver.find_element_by_id("submit-heading")
186-
assert "Submit Files or Messages" == headline.text
184+
headline = self.driver.find_element_by_id("welcome-heading")
185+
assert "Welcome!" == headline.text
187186

188187
self.nav_helper.wait_for(submit_page_loaded)
189188

@@ -198,11 +197,11 @@ def source_logs_out(self) -> None:
198197

199198
def source_retrieves_codename_from_hint(self) -> str:
200199
# We use inputs to change CSS states for subsequent elements in the DOM, if it is unchecked
201-
# the codename is hidden
202200
content = self.driver.find_element_by_id("codename-show-checkbox")
203-
assert content.get_attribute("checked") is None
204201

205-
self.nav_helper.safe_click_by_id("codename-show")
202+
# TODO: should the codename be hidden by default under inverted flow?
203+
# assert content.get_attribute("checked") is None
204+
# self.nav_helper.safe_click_by_id("codename-show")
206205

207206
assert content.get_attribute("checked") is not None
208207
content_content = self.driver.find_element_by_css_selector("#codename span")
@@ -218,7 +217,7 @@ def _is_logged_in(self) -> WebElement:
218217
return self.nav_helper.wait_for(lambda: self.driver.find_element_by_id("logout"))
219218

220219
def source_proceeds_to_login(self, codename: str) -> None:
221-
self.nav_helper.safe_send_keys_by_id("codename", codename)
220+
self.nav_helper.safe_send_keys_by_id("passphrase", codename)
222221
self.nav_helper.safe_click_by_css_selector(".form-controls button")
223222

224223
# Check that we've logged in
Lines changed: 18 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import requests
2-
import werkzeug
32

43
from tests.functional.app_navigators import SourceAppNagivator
5-
from ..test_journalist import VALID_PASSWORD
64
from tests.functional import tor_utils
75

86

@@ -17,10 +15,11 @@ def test_no_codename_hint_on_second_login(self, sd_servers_v2, tor_browser_web_d
1715
)
1816

1917
# Given a source user who creates an account
20-
# When they first login
18+
# When they first submit a message
2119
navigator.source_visits_source_homepage()
2220
navigator.source_clicks_submit_documents_on_homepage()
2321
navigator.source_continues_to_submit_page()
22+
navigator.source_submits_a_message("they're here")
2423

2524
# Then they are able to retrieve their codename from the UI
2625
source_codename = navigator.source_retrieves_codename_from_hint()
@@ -72,10 +71,16 @@ def test_submission_notifications_on_second_login(self, sd_servers_v2, tor_brows
7271
web_driver=tor_browser_web_driver,
7372
)
7473

75-
# Given a source user who creates an account
74+
# Given a source user who creates an account by submitting a
75+
# message on first login
7676
navigator.source_visits_source_homepage()
7777
navigator.source_clicks_submit_documents_on_homepage()
7878
navigator.source_continues_to_submit_page()
79+
confirmation_text_first_submission = navigator.source_submits_a_message()
80+
81+
# And they see the expected confirmation messages for a first submission on second login
82+
assert self.FIRST_SUBMISSION_TEXT in confirmation_text_first_submission
83+
7984
source_codename = navigator.source_retrieves_codename_from_hint()
8085
assert source_codename
8186

@@ -85,12 +90,6 @@ def test_submission_notifications_on_second_login(self, sd_servers_v2, tor_brows
8590
navigator.source_chooses_to_login()
8691
navigator.source_proceeds_to_login(codename=source_codename)
8792

88-
# Then it succeeds
89-
confirmation_text_first_submission = navigator.source_submits_a_message()
90-
91-
# And they see the expected confirmation messages for a first submission on second login
92-
assert self.FIRST_SUBMISSION_TEXT in confirmation_text_first_submission
93-
9493
# And when they submit a second message
9594
confirmation_text_second_submission = navigator.source_submits_a_message()
9695

@@ -127,110 +126,37 @@ def test_generate_codenames_in_multiple_tabs(self, sd_servers_v2, tor_browser_we
127126
web_driver=tor_browser_web_driver,
128127
)
129128

130-
# Given a user who generated a codename in Tab A
129+
# Given a user who opens /lookup in tab A
131130
tab_a = navigator.driver.window_handles[0]
132131
navigator.source_visits_source_homepage()
133132
navigator.source_clicks_submit_documents_on_homepage()
134-
codename_a = self._extract_generated_codename(navigator)
133+
navigator.source_continues_to_submit_page()
135134

136135
# And they then opened a new tab, Tab B
137136
navigator.driver.execute_script("window.open('about:blank', '_blank')")
138137
tab_b = navigator.driver.window_handles[1]
139138
navigator.driver.switch_to.window(tab_b)
140139
assert tab_a != tab_b
141140

142-
# And they also generated another codename in Tab B
141+
# And they also opened /lookup in Tab B
143142
navigator.source_visits_source_homepage()
144143
navigator.source_clicks_submit_documents_on_homepage()
145-
codename_b = self._extract_generated_codename(navigator)
146-
assert codename_a != codename_b
144+
navigator.source_continues_to_submit_page()
147145

148146
# And they ended up creating their account and submitting documents in Tab A
149147
navigator.driver.switch_to.window(tab_a)
150148
navigator.source_continues_to_submit_page()
151149
self._assert_is_on_lookup_page(navigator)
152-
assert navigator.source_retrieves_codename_from_hint() == codename_a
153150
navigator.source_submits_a_message()
151+
passphrase_a = navigator.source_retrieves_codename_from_hint()
154152

155153
# When the user tries to create an account and submit documents in Tab B
156154
navigator.driver.switch_to.window(tab_b)
157-
navigator.source_continues_to_submit_page()
158-
159-
# Then the submission fails and the user sees the corresponding flash message in Tab B
160-
self._assert_is_on_lookup_page(navigator)
161-
notification = navigator.source_sees_flash_message()
162-
if not navigator.accept_languages:
163-
assert "You are already logged in." in notification.text
164-
165-
# And the user's actual codename is the one initially generated in Tab A
166-
assert navigator.source_retrieves_codename_from_hint() == codename_a
167-
168-
def test_generate_and_refresh_codenames_in_multiple_tabs(
169-
self, sd_servers_v2, tor_browser_web_driver
170-
):
171-
navigator = SourceAppNagivator(
172-
source_app_base_url=sd_servers_v2.source_app_base_url,
173-
web_driver=tor_browser_web_driver,
174-
)
175-
176-
# Given a user who generated a codename in Tab A
177-
tab_a = navigator.driver.window_handles[0]
178-
navigator.source_visits_source_homepage()
179-
navigator.source_clicks_submit_documents_on_homepage()
180-
codename_a1 = self._extract_generated_codename(navigator)
181-
182-
# And they then re-generated their codename in Tab
183-
navigator.source_visits_source_homepage()
184-
navigator.source_clicks_submit_documents_on_homepage()
185-
codename_a2 = self._extract_generated_codename(navigator)
186-
assert codename_a1 != codename_a2
187-
188-
# And they then opened a new tab, Tab B
189-
navigator.driver.execute_script("window.open('about:blank', '_blank')")
190-
tab_b = navigator.driver.window_handles[1]
191-
navigator.driver.switch_to.window(tab_b)
192-
assert tab_a != tab_b
193-
194-
# And they also generated another codename in Tab B
195-
navigator.source_visits_source_homepage()
196-
navigator.source_clicks_submit_documents_on_homepage()
197-
codename_b = self._extract_generated_codename(navigator)
198-
assert codename_a2 != codename_b
199-
200-
# And they ended up creating their account and submitting documents in Tab A
201-
navigator.driver.switch_to.window(tab_a)
202-
navigator.source_continues_to_submit_page()
203-
self._assert_is_on_lookup_page(navigator)
204-
assert navigator.source_retrieves_codename_from_hint() == codename_a2
205155
navigator.source_submits_a_message()
156+
passphrase_b = navigator.source_retrieves_codename_from_hint()
206157

207-
# When they try to re-generate a codename in Tab B
208-
navigator.driver.switch_to.window(tab_b)
209-
navigator.source_visits_source_homepage()
210-
navigator.nav_helper.safe_click_by_css_selector("#started-form button")
211-
212-
# Then they get redirected to /lookup with the corresponding flash message
158+
# Then the submission succeeds
213159
self._assert_is_on_lookup_page(navigator)
214-
notification = navigator.source_sees_flash_message()
215-
if not navigator.accept_languages:
216-
assert "You were redirected because you are already logged in." in notification.text
217-
218-
# And the user's actual codename is the expected one
219-
assert navigator.source_retrieves_codename_from_hint() == codename_a2
220-
221-
# TODO(AD): This test takes ~50s ; we could refactor it to speed it up
222-
def test_codenames_exceed_max_cookie_size(self, sd_servers_v2, tor_browser_web_driver):
223-
"""Test generation of enough codenames that the resulting cookie exceeds the recommended
224-
`werkzeug.Response.max_cookie_size` = 4093 bytes. (#6043)
225-
"""
226-
navigator = SourceAppNagivator(
227-
source_app_base_url=sd_servers_v2.source_app_base_url,
228-
web_driver=tor_browser_web_driver,
229-
)
230160

231-
too_many = 2 * (werkzeug.Response.max_cookie_size // len(VALID_PASSWORD))
232-
for _ in range(too_many):
233-
navigator.source_visits_source_homepage()
234-
navigator.source_clicks_submit_documents_on_homepage()
235-
236-
navigator.source_continues_to_submit_page()
161+
# And the user's actual codename is the one initially generated in Tab A
162+
assert passphrase_b == passphrase_a

0 commit comments

Comments
 (0)