Skip to content

Commit e5015bc

Browse files
simideivid-rodriguez
authored andcommitted
Merge pull request #8663 from mperham/patch-1
Smoother authentication experience (cherry picked from commit fc0c28a)
1 parent 3a82e22 commit e5015bc

File tree

5 files changed

+38
-19
lines changed

5 files changed

+38
-19
lines changed

lib/rubygems/gemcutter_utilities.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,10 @@ def fetch_otp(credentials)
263263
port = server.addr[1].to_s
264264

265265
url_with_port = "#{webauthn_url}?port=#{port}"
266-
say "You have enabled multi-factor authentication. Please visit #{url_with_port} to authenticate via security device. If you can't verify using WebAuthn but have OTP enabled, you can re-run the gem signin command with the `--otp [your_code]` option."
266+
say "You have enabled multi-factor authentication. Please visit the following URL to authenticate via security device. If you can't verify using WebAuthn but have OTP enabled, you can re-run the gem signin command with the `--otp [your_code]` option."
267+
say ""
268+
say url_with_port
269+
say ""
267270

268271
threads = [WebauthnListener.listener_thread(host, server), WebauthnPoller.poll_thread(options, host, webauthn_url, credentials)]
269272
otp_thread = wait_for_otp_thread(*threads)

test/rubygems/test_gem_commands_owner_command.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,10 @@ def test_with_webauthn_enabled_success
386386
end
387387
end
388388

389-
assert_match "You have enabled multi-factor authentication. Please visit #{@stub_fetcher.webauthn_url_with_port(server.port)} " \
389+
assert_match "You have enabled multi-factor authentication. Please visit the following URL " \
390390
"to authenticate via security device. If you can't verify using WebAuthn but have OTP enabled, " \
391391
"you can re-run the gem signin command with the `--otp [your_code]` option.", @stub_ui.output
392+
assert_match @stub_fetcher.webauthn_url_with_port(server.port), @stub_ui.output
392393
assert_match "You are verified with a security device. You may close the browser window.", @stub_ui.output
393394
assert_equal "Uvh6T57tkWuUnWYo", @stub_fetcher.last_request["OTP"]
394395
assert_match response_success, @stub_ui.output
@@ -413,9 +414,10 @@ def test_with_webauthn_enabled_failure
413414
end
414415

415416
assert_match @stub_fetcher.last_request["Authorization"], Gem.configuration.rubygems_api_key
416-
assert_match "You have enabled multi-factor authentication. Please visit #{@stub_fetcher.webauthn_url_with_port(server.port)} " \
417+
assert_match "You have enabled multi-factor authentication. Please visit the following URL " \
417418
"to authenticate via security device. If you can't verify using WebAuthn but have OTP enabled, " \
418419
"you can re-run the gem signin command with the `--otp [your_code]` option.", @stub_ui.output
420+
assert_match @stub_fetcher.webauthn_url_with_port(server.port), @stub_ui.output
419421
assert_match "ERROR: Security device verification failed: Something went wrong", @stub_ui.error
420422
refute_match "You are verified with a security device. You may close the browser window.", @stub_ui.output
421423
refute_match response_success, @stub_ui.output
@@ -435,9 +437,10 @@ def test_with_webauthn_enabled_success_with_polling
435437
end
436438
end
437439

438-
assert_match "You have enabled multi-factor authentication. Please visit #{@stub_fetcher.webauthn_url_with_port(server.port)} " \
440+
assert_match "You have enabled multi-factor authentication. Please visit the following URL " \
439441
"to authenticate via security device. If you can't verify using WebAuthn but have OTP enabled, you can re-run the gem signin " \
440442
"command with the `--otp [your_code]` option.", @stub_ui.output
443+
assert_match @stub_fetcher.webauthn_url_with_port(server.port), @stub_ui.output
441444
assert_match "You are verified with a security device. You may close the browser window.", @stub_ui.output
442445
assert_equal "Uvh6T57tkWuUnWYo", @stub_fetcher.last_request["OTP"]
443446
assert_match response_success, @stub_ui.output
@@ -463,9 +466,10 @@ def test_with_webauthn_enabled_failure_with_polling
463466
end
464467

465468
assert_match @stub_fetcher.last_request["Authorization"], Gem.configuration.rubygems_api_key
466-
assert_match "You have enabled multi-factor authentication. Please visit #{@stub_fetcher.webauthn_url_with_port(server.port)} " \
469+
assert_match "You have enabled multi-factor authentication. Please visit the following URL " \
467470
"to authenticate via security device. If you can't verify using WebAuthn but have OTP enabled, you can re-run the gem signin " \
468471
"command with the `--otp [your_code]` option.", @stub_ui.output
472+
assert_match @stub_fetcher.webauthn_url_with_port(server.port), @stub_ui.output
469473
assert_match "ERROR: Security device verification failed: The token in the link you used has either expired " \
470474
"or been used already.", @stub_ui.error
471475
refute_match "You are verified with a security device. You may close the browser window.", @stub_ui.output

test/rubygems/test_gem_commands_push_command.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -477,9 +477,10 @@ def test_with_webauthn_enabled_success
477477
end
478478
end
479479

480-
assert_match "You have enabled multi-factor authentication. Please visit #{@fetcher.webauthn_url_with_port(server.port)} " \
480+
assert_match "You have enabled multi-factor authentication. Please visit the following URL " \
481481
"to authenticate via security device. If you can't verify using WebAuthn but have OTP enabled, " \
482482
"you can re-run the gem signin command with the `--otp [your_code]` option.", @ui.output
483+
assert_match @fetcher.webauthn_url_with_port(server.port), @ui.output
483484
assert_match "You are verified with a security device. You may close the browser window.", @ui.output
484485
assert_equal "Uvh6T57tkWuUnWYo", @fetcher.last_request["OTP"]
485486
assert_match response_success, @ui.output
@@ -505,9 +506,10 @@ def test_with_webauthn_enabled_failure
505506
assert_equal 1, error.exit_code
506507

507508
assert_match @fetcher.last_request["Authorization"], Gem.configuration.rubygems_api_key
508-
assert_match "You have enabled multi-factor authentication. Please visit #{@fetcher.webauthn_url_with_port(server.port)} " \
509+
assert_match "You have enabled multi-factor authentication. Please visit the following URL " \
509510
"to authenticate via security device. If you can't verify using WebAuthn but have OTP enabled, " \
510511
"you can re-run the gem signin command with the `--otp [your_code]` option.", @ui.output
512+
assert_match @fetcher.webauthn_url_with_port(server.port), @ui.output
511513
assert_match "ERROR: Security device verification failed: Something went wrong", @ui.error
512514
refute_match "You are verified with a security device. You may close the browser window.", @ui.output
513515
refute_match response_success, @ui.output
@@ -527,9 +529,10 @@ def test_with_webauthn_enabled_success_with_polling
527529
end
528530
end
529531

530-
assert_match "You have enabled multi-factor authentication. Please visit #{@fetcher.webauthn_url_with_port(server.port)} " \
532+
assert_match "You have enabled multi-factor authentication. Please visit the following URL " \
531533
"to authenticate via security device. If you can't verify using WebAuthn but have OTP enabled, " \
532534
"you can re-run the gem signin command with the `--otp [your_code]` option.", @ui.output
535+
assert_match @fetcher.webauthn_url_with_port(server.port), @ui.output
533536
assert_match "You are verified with a security device. You may close the browser window.", @ui.output
534537
assert_equal "Uvh6T57tkWuUnWYo", @fetcher.last_request["OTP"]
535538
assert_match response_success, @ui.output
@@ -553,9 +556,10 @@ def test_with_webauthn_enabled_failure_with_polling
553556
assert_equal 1, error.exit_code
554557

555558
assert_match @fetcher.last_request["Authorization"], Gem.configuration.rubygems_api_key
556-
assert_match "You have enabled multi-factor authentication. Please visit #{@fetcher.webauthn_url_with_port(server.port)} " \
557-
"to authenticate via security device. If you can't verify using WebAuthn but have OTP enabled, you can re-run the gem signin " \
558-
"command with the `--otp [your_code]` option.", @ui.output
559+
assert_match "You have enabled multi-factor authentication. Please visit the following URL " \
560+
"to authenticate via security device. If you can't verify using WebAuthn but have OTP enabled, " \
561+
"you can re-run the gem signin command with the `--otp [your_code]` option.", @ui.output
562+
assert_match @fetcher.webauthn_url_with_port(server.port), @ui.output
559563
assert_match "ERROR: Security device verification failed: The token in the link you used has either expired " \
560564
"or been used already.", @ui.error
561565
refute_match "You are verified with a security device. You may close the browser window.", @ui.output

test/rubygems/test_gem_commands_yank_command.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,10 @@ def test_with_webauthn_enabled_success
131131
end
132132

133133
assert_match %r{Yanking gem from http://example}, @ui.output
134-
assert_match "You have enabled multi-factor authentication. Please visit #{@fetcher.webauthn_url_with_port(server.port)} " \
134+
assert_match "You have enabled multi-factor authentication. Please visit the following URL " \
135135
"to authenticate via security device. If you can't verify using WebAuthn but have OTP enabled, " \
136136
"you can re-run the gem signin command with the `--otp [your_code]` option.", @ui.output
137+
assert_match @fetcher.webauthn_url_with_port(server.port), @ui.output
137138
assert_match "You are verified with a security device. You may close the browser window.", @ui.output
138139
assert_equal "Uvh6T57tkWuUnWYo", @fetcher.last_request["OTP"]
139140
assert_match "Successfully yanked", @ui.output
@@ -163,9 +164,10 @@ def test_with_webauthn_enabled_failure
163164

164165
assert_match @fetcher.last_request["Authorization"], Gem.configuration.rubygems_api_key
165166
assert_match %r{Yanking gem from http://example}, @ui.output
166-
assert_match "You have enabled multi-factor authentication. Please visit #{@fetcher.webauthn_url_with_port(server.port)} " \
167+
assert_match "You have enabled multi-factor authentication. Please visit the following URL " \
167168
"to authenticate via security device. If you can't verify using WebAuthn but have OTP enabled, " \
168169
"you can re-run the gem signin command with the `--otp [your_code]` option.", @ui.output
170+
assert_match @fetcher.webauthn_url_with_port(server.port), @ui.output
169171
assert_match "ERROR: Security device verification failed: Something went wrong", @ui.error
170172
refute_match "You are verified with a security device. You may close the browser window.", @ui.output
171173
refute_match "Successfully yanked", @ui.output
@@ -189,9 +191,10 @@ def test_with_webauthn_enabled_success_with_polling
189191
end
190192

191193
assert_match %r{Yanking gem from http://example}, @ui.output
192-
assert_match "You have enabled multi-factor authentication. Please visit #{@fetcher.webauthn_url_with_port(server.port)} " \
194+
assert_match "You have enabled multi-factor authentication. Please visit the following URL " \
193195
"to authenticate via security device. If you can't verify using WebAuthn but have OTP enabled, " \
194196
"you can re-run the gem signin command with the `--otp [your_code]` option.", @ui.output
197+
assert_match @fetcher.webauthn_url_with_port(server.port), @ui.output
195198
assert_match "You are verified with a security device. You may close the browser window.", @ui.output
196199
assert_equal "Uvh6T57tkWuUnWYo", @fetcher.last_request["OTP"]
197200
assert_match "Successfully yanked", @ui.output
@@ -219,9 +222,10 @@ def test_with_webauthn_enabled_failure_with_polling
219222

220223
assert_match @fetcher.last_request["Authorization"], Gem.configuration.rubygems_api_key
221224
assert_match %r{Yanking gem from http://example}, @ui.output
222-
assert_match "You have enabled multi-factor authentication. Please visit #{@fetcher.webauthn_url_with_port(server.port)} " \
225+
assert_match "You have enabled multi-factor authentication. Please visit the following URL " \
223226
"to authenticate via security device. If you can't verify using WebAuthn but have OTP enabled, " \
224227
"you can re-run the gem signin command with the `--otp [your_code]` option.", @ui.output
228+
assert_match @fetcher.webauthn_url_with_port(server.port), @ui.output
225229
assert_match "ERROR: Security device verification failed: The token in the link you used has either expired " \
226230
"or been used already.", @ui.error
227231
refute_match "You are verified with a security device. You may close the browser window.", @ui.output

test/rubygems/test_gem_gemcutter_utilities.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,10 @@ def test_sign_in_with_webauthn_enabled
233233
end
234234
end
235235

236-
assert_match "You have enabled multi-factor authentication. Please visit #{@fetcher.webauthn_url_with_port(server.port)} " \
236+
assert_match "You have enabled multi-factor authentication. Please visit the following URL " \
237237
"to authenticate via security device. If you can't verify using WebAuthn but have OTP enabled, " \
238238
"you can re-run the gem signin command with the `--otp [your_code]` option.", @sign_in_ui.output
239+
assert_match @fetcher.webauthn_url_with_port(server.port), @sign_in_ui.output
239240
assert_match "You are verified with a security device. You may close the browser window.", @sign_in_ui.output
240241
assert_equal "Uvh6T57tkWuUnWYo", @fetcher.last_request["OTP"]
241242
end
@@ -255,9 +256,10 @@ def test_sign_in_with_webauthn_enabled_with_error
255256
end
256257
assert_equal 1, error.exit_code
257258

258-
assert_match "You have enabled multi-factor authentication. Please visit #{@fetcher.webauthn_url_with_port(server.port)} " \
259+
assert_match "You have enabled multi-factor authentication. Please visit the following URL " \
259260
"to authenticate via security device. If you can't verify using WebAuthn but have OTP enabled, " \
260261
"you can re-run the gem signin command with the `--otp [your_code]` option.", @sign_in_ui.output
262+
assert_match @fetcher.webauthn_url_with_port(server.port), @sign_in_ui.output
261263
assert_match "ERROR: Security device verification failed: Something went wrong", @sign_in_ui.error
262264
refute_match "You are verified with a security device. You may close the browser window.", @sign_in_ui.output
263265
refute_match "Signed in with API key:", @sign_in_ui.output
@@ -273,9 +275,10 @@ def test_sign_in_with_webauthn_enabled_with_polling
273275
util_sign_in
274276
end
275277

276-
assert_match "You have enabled multi-factor authentication. Please visit #{@fetcher.webauthn_url_with_port(server.port)} " \
278+
assert_match "You have enabled multi-factor authentication. Please visit the following URL " \
277279
"to authenticate via security device. If you can't verify using WebAuthn but have OTP enabled, " \
278280
"you can re-run the gem signin command with the `--otp [your_code]` option.", @sign_in_ui.output
281+
assert_match @fetcher.webauthn_url_with_port(server.port), @sign_in_ui.output
279282
assert_match "You are verified with a security device. You may close the browser window.", @sign_in_ui.output
280283
assert_equal "Uvh6T57tkWuUnWYo", @fetcher.last_request["OTP"]
281284
end
@@ -292,9 +295,10 @@ def test_sign_in_with_webauthn_enabled_with_polling_failure
292295
end
293296
end
294297

295-
assert_match "You have enabled multi-factor authentication. Please visit #{@fetcher.webauthn_url_with_port(server.port)} " \
298+
assert_match "You have enabled multi-factor authentication. Please visit the following URL " \
296299
"to authenticate via security device. If you can't verify using WebAuthn but have OTP enabled, " \
297300
"you can re-run the gem signin command with the `--otp [your_code]` option.", @sign_in_ui.output
301+
assert_match @fetcher.webauthn_url_with_port(server.port), @sign_in_ui.output
298302
assert_match "ERROR: Security device verification failed: " \
299303
"The token in the link you used has either expired or been used already.", @sign_in_ui.error
300304
end

0 commit comments

Comments
 (0)