Skip to content

Commit e978965

Browse files
committed
Add assertions to tests to ensure previous request finished.
1 parent 8033b1a commit e978965

11 files changed

Lines changed: 78 additions & 56 deletions

test/application_system_test_case.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,20 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
1414
else
1515
driven_by :selenium, using: :headless_chrome, screen_size: [1400, 1400]
1616
end
17+
18+
def sign_in
19+
visit sign_in_path
20+
fill_in "Email or Username", with: @user.reload.email
21+
fill_in "Password", with: @user.password
22+
click_button "Sign in"
23+
24+
assert page.has_content?("Dashboard")
25+
end
26+
27+
def sign_out
28+
reset_session!
29+
visit "/"
30+
31+
assert page.has_content?("Sign in".upcase)
32+
end
1733
end

test/integration/email_confirmation_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ def request_confirmation_mail(email)
1414
click_link "Didn't receive confirmation mail?"
1515
fill_in "Email address", with: email
1616
click_button "Resend Confirmation"
17+
18+
assert page.has_content? "We will email you confirmation link to activate your account if one exists."
1719
end
1820

1921
test "requesting confirmation mail does not tell if a user exists" do

test/integration/password_reset_test.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ def forgot_password_with(email)
1818

1919
click_link "Forgot password?"
2020
fill_in "Email address", with: email
21-
perform_enqueued_jobs { click_button "Reset password" }
21+
perform_enqueued_jobs do
22+
click_button "Reset password"
23+
24+
assert page.has_content? "You will receive an email within the next few minutes."
25+
end
2226
end
2327

2428
test "reset password form does not tell if a user exists" do

test/system/api_keys_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class ApiKeysTest < ApplicationSystemTestCase
99
fill_in "Email or Username", with: @user.email
1010
fill_in "Password", with: @user.password
1111
click_button "Sign in"
12+
13+
assert page.has_content?("Dashboard")
1214
end
1315

1416
test "creating new api key" do
@@ -41,6 +43,8 @@ class ApiKeysTest < ApplicationSystemTestCase
4143
visit_profile_api_keys_path
4244
click_button "New API key"
4345

46+
assert page.has_content?("New API key")
47+
4448
assert_empty URI.parse(page.current_url).query
4549

4650
fill_in "api_key[name]", with: "test"
@@ -194,6 +198,7 @@ class ApiKeysTest < ApplicationSystemTestCase
194198
refute page.has_content? "Enable MFA"
195199
click_button "Update API Key"
196200

201+
assert page.has_content?("Successfully updated API key")
197202
assert_predicate api_key.reload, :can_add_owner?
198203
end
199204

@@ -208,6 +213,7 @@ class ApiKeysTest < ApplicationSystemTestCase
208213
page.select "All Gems"
209214
click_button "Update API Key"
210215

216+
assert page.has_content?("Successfully updated API key")
211217
assert_equal "All Gems", page.find('.owners__cell[data-title="Gem"]').text
212218
assert_nil api_key.reload.rubygem
213219
end
@@ -225,6 +231,7 @@ class ApiKeysTest < ApplicationSystemTestCase
225231
assert page.has_select? "api_key_rubygem_id", selected: "All Gems", disabled: true
226232
click_button "Update API Key"
227233

234+
assert page.has_content?("Successfully updated API key")
228235
assert_nil api_key.reload.rubygem
229236
end
230237

@@ -243,6 +250,7 @@ class ApiKeysTest < ApplicationSystemTestCase
243250
page.select @ownership.rubygem.name
244251
click_button "Update API Key"
245252

253+
assert page.has_content?("Successfully updated API key")
246254
assert_equal api_key.reload.rubygem, @ownership.rubygem
247255
end
248256

@@ -278,6 +286,7 @@ class ApiKeysTest < ApplicationSystemTestCase
278286
check "mfa"
279287
click_button "Update API Key"
280288

289+
assert page.has_content?("Successfully updated API key")
281290
assert_predicate api_key.reload, :can_add_owner?
282291
assert_predicate @user.api_keys.last, :mfa_enabled?
283292
end
@@ -296,6 +305,7 @@ class ApiKeysTest < ApplicationSystemTestCase
296305
refute page.has_content? "Enable MFA"
297306
click_button "Update API Key"
298307

308+
assert page.has_content?("Successfully updated API key")
299309
assert_predicate api_key.reload, :can_add_owner?
300310
assert_predicate @user.api_keys.last, :mfa_enabled?
301311
end

test/system/multifactor_auths_test.rb

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ class MultifactorAuthsTest < ApplicationSystemTestCase
6969
end
7070

7171
should "user with mfa disabled gets redirected back to new api keys pages after setting up mfa" do
72-
redirect_test_mfa_disabled(new_profile_api_key_path) { verify_password }
72+
redirect_test_mfa_disabled(new_profile_api_key_path) do
73+
verify_password
74+
75+
assert page.has_content?("New API key")
76+
end
7377
end
7478

7579
should "user with mfa disabled gets redirected back to notifier pages after setting up mfa" do
@@ -78,7 +82,11 @@ class MultifactorAuthsTest < ApplicationSystemTestCase
7882

7983
should "user with mfa disabled gets redirected back to profile api keys pages after setting up mfa" do
8084
create(:api_key, scopes: %i[push_rubygem], owner: @user, ownership: @ownership)
81-
redirect_test_mfa_disabled(profile_api_keys_path) { verify_password }
85+
redirect_test_mfa_disabled(profile_api_keys_path) do
86+
verify_password
87+
88+
assert page.has_content?("API keys")
89+
end
8290
end
8391

8492
should "user with mfa disabled gets redirected back to verify session pages after setting up mfa" do
@@ -100,7 +108,11 @@ class MultifactorAuthsTest < ApplicationSystemTestCase
100108
end
101109

102110
should "user gets redirected back to new api keys pages after setting up mfa" do
103-
redirect_test_mfa_weak_level(new_profile_api_key_path) { verify_password }
111+
redirect_test_mfa_weak_level(new_profile_api_key_path) do
112+
verify_password
113+
114+
assert page.has_content?("New API key")
115+
end
104116
end
105117

106118
should "user gets redirected back to notifier pages after setting up mfa" do
@@ -109,7 +121,11 @@ class MultifactorAuthsTest < ApplicationSystemTestCase
109121

110122
should "user gets redirected back to profile api keys pages after setting up mfa" do
111123
create(:api_key, scopes: %i[push_rubygem], owner: @user, ownership: @ownership)
112-
redirect_test_mfa_weak_level(profile_api_keys_path) { verify_password }
124+
redirect_test_mfa_weak_level(profile_api_keys_path) do
125+
verify_password
126+
127+
assert page.has_content?("API keys")
128+
end
113129
end
114130

115131
should "user gets redirected back to verify session pages after setting up mfa" do
@@ -157,7 +173,7 @@ class MultifactorAuthsTest < ApplicationSystemTestCase
157173
end
158174

159175
def redirect_test_mfa_disabled(path)
160-
sign_in
176+
sign_in(wait_for: "For protection of your account and your gems, you are required to set up multi-factor authentication.")
161177
visit path
162178

163179
assert(page.has_content?("you are required to set up multi-factor authentication"))
@@ -175,7 +191,7 @@ def redirect_test_mfa_disabled(path)
175191
end
176192

177193
def redirect_test_mfa_weak_level(path)
178-
sign_in
194+
sign_in(wait_for: "For protection of your account and your gems, you are required to set up multi-factor authentication.")
179195
@user.enable_totp!(@seed, :ui_only)
180196
visit path
181197

@@ -186,16 +202,20 @@ def redirect_test_mfa_weak_level(path)
186202

187203
click_button "Authenticate"
188204

205+
assert page.has_content?("You have successfully updated your multi-factor authentication level.")
206+
189207
yield if block_given?
190208

191209
assert_equal path, current_path, "was not redirected back to original destination: #{path}"
192210
end
193211

194-
def sign_in
212+
def sign_in(wait_for: "Dashboard")
195213
visit sign_in_path
196214
fill_in "Email or Username", with: @user.reload.email
197215
fill_in "Password", with: @user.password
198216
click_button "Sign in"
217+
218+
assert page.has_content?(wait_for)
199219
end
200220

201221
def otp_key

test/system/oidc_test.rb

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,6 @@ class OIDCTest < ApplicationSystemTestCase
88
@id_token = create(:oidc_id_token, user: @user, api_key_role: @api_key_role)
99
end
1010

11-
def sign_in # rubocop:disable Minitest/TestMethodName
12-
visit sign_in_path
13-
fill_in "Email or Username", with: @user.reload.email
14-
fill_in "Password", with: @user.password
15-
click_button "Sign in"
16-
17-
# Wait for the reload and confirm the sign in worked
18-
page.assert_selector "h1", text: "Dashboard"
19-
end
20-
2111
def verify_session # rubocop:disable Minitest/TestMethodName
2212
page.assert_title(/^Confirm Password/)
2313
fill_in "Password", with: @user.password

test/system/profile_test.rb

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,6 @@ class ProfileTest < ApplicationSystemTestCase
88
@user = create(:user, email: "[email protected]", password: PasswordHelpers::SECURE_TEST_PASSWORD, handle: "nick1", mail_fails: 1)
99
end
1010

11-
def sign_in
12-
visit sign_in_path
13-
fill_in "Email or Username", with: @user.reload.email
14-
fill_in "Password", with: @user.password
15-
click_button "Sign in"
16-
end
17-
18-
def sign_out
19-
reset_session!
20-
visit "/"
21-
end
22-
2311
test "changing handle" do
2412
sign_in
2513

@@ -181,6 +169,8 @@ def sign_out
181169
click_button "Confirm"
182170
end
183171

172+
assert page.has_content?("Your account deletion request has been enqueued.")
173+
184174
sign_in
185175
visit delete_profile_path
186176

test/system/settings_test.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@ class SettingsTest < ApplicationSystemTestCase
55
@user = create(:user, email: "[email protected]", password: PasswordHelpers::SECURE_TEST_PASSWORD, handle: "nick1", mail_fails: 1)
66
end
77

8-
def sign_in
9-
visit sign_in_path
10-
fill_in "Email or Username", with: @user.reload.email
11-
fill_in "Password", with: @user.password
12-
click_button "Sign in"
13-
end
14-
158
def enable_otp
169
key = ROTP::Base32.random_base32
1710
@user.enable_totp!(key, :ui_only)

test/system/webauthn_credentials_test.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,6 @@ class WebauthnCredentialsTest < ApplicationSystemTestCase
77
@user = create(:user)
88
end
99

10-
def sign_in
11-
visit sign_in_path
12-
fill_in "Email or Username", with: @user.reload.email
13-
fill_in "Password", with: @user.password
14-
click_button "Sign in"
15-
end
16-
1710
should "have security device form" do
1811
sign_in
1912
visit edit_settings_path

test/system/webauthn_verification_test.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ class WebAuthnVerificationTest < ApplicationSystemTestCase
1212
test "when verifying webauthn credential" do
1313
visit webauthn_verification_path(webauthn_token: @verification.path_token, params: { port: @port })
1414

15-
assert_match "Authenticate with Security Device", page.html
16-
assert_match "Authenticating as #{@user.handle}", page.html
15+
assert page.has_content?("Authenticate with Security Device")
16+
assert page.has_content?("Authenticating as #{@user.handle}".upcase)
1717

1818
click_on "Authenticate"
1919

@@ -28,8 +28,8 @@ class WebAuthnVerificationTest < ApplicationSystemTestCase
2828
assert_poll_status("pending")
2929
visit webauthn_verification_path(webauthn_token: @verification.path_token, params: { port: @port })
3030

31-
assert_match "Authenticate with Security Device", page.html
32-
assert_match "Authenticating as #{@user.handle}", page.html
31+
assert page.has_content?("Authenticate with Security Device")
32+
assert page.has_content?("Authenticating as #{@user.handle}".upcase)
3333

3434
click_on "Authenticate"
3535

@@ -46,8 +46,8 @@ class WebAuthnVerificationTest < ApplicationSystemTestCase
4646
test "when client closes connection during verification" do
4747
visit webauthn_verification_path(webauthn_token: @verification.path_token, params: { port: @port })
4848

49-
assert_match "Authenticate with Security Device", page.html
50-
assert_match "Authenticating as #{@user.handle}", page.html
49+
assert page.has_content?("Authenticate with Security Device")
50+
assert page.has_content?("Authenticating as #{@user.handle}".upcase)
5151

5252
@mock_client.kill_server
5353
click_on "Authenticate"
@@ -64,8 +64,8 @@ class WebAuthnVerificationTest < ApplicationSystemTestCase
6464
wrong_port = 1111
6565
visit webauthn_verification_path(webauthn_token: @verification.path_token, params: { port: wrong_port })
6666

67-
assert_match "Authenticate with Security Device", page.html
68-
assert_match "Authenticating as #{@user.handle}", page.html
67+
assert page.has_content?("Authenticate with Security Device")
68+
assert page.has_content?("Authenticating as #{@user.handle}".upcase)
6969

7070
click_on "Authenticate"
7171

@@ -81,8 +81,8 @@ class WebAuthnVerificationTest < ApplicationSystemTestCase
8181
@mock_client.response = @mock_client.bad_request_response
8282
visit webauthn_verification_path(webauthn_token: @verification.path_token, params: { port: @port })
8383

84-
assert_match "Authenticate with Security Device", page.html
85-
assert_match "Authenticating as #{@user.handle}", page.html
84+
assert page.has_content?("Authenticate with Security Device")
85+
assert page.has_content?("Authenticating as #{@user.handle}".upcase)
8686

8787
click_on "Authenticate"
8888

@@ -97,8 +97,8 @@ class WebAuthnVerificationTest < ApplicationSystemTestCase
9797
visit webauthn_verification_path(webauthn_token: @verification.path_token, params: { port: @port })
9898

9999
travel 3.minutes do
100-
assert_match "Authenticate with Security Device", page.html
101-
assert_match "Authenticating as #{@user.handle}", page.html
100+
assert page.has_content?("Authenticate with Security Device")
101+
assert page.has_content?("Authenticating as #{@user.handle}".upcase)
102102

103103
click_on "Authenticate"
104104

0 commit comments

Comments
 (0)