aboutsummaryrefslogtreecommitdiffstats
path: root/test/rubygems/test_gem_commands_yank_command.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/rubygems/test_gem_commands_yank_command.rb')
-rw-r--r--test/rubygems/test_gem_commands_yank_command.rb30
1 files changed, 9 insertions, 21 deletions
diff --git a/test/rubygems/test_gem_commands_yank_command.rb b/test/rubygems/test_gem_commands_yank_command.rb
index dcd7ba1a83..bfa0d6421f 100644
--- a/test/rubygems/test_gem_commands_yank_command.rb
+++ b/test/rubygems/test_gem_commands_yank_command.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
require_relative "helper"
-require_relative "multifactor_auth_fetcher"
+require_relative "multifactor_auth_utilities"
require "rubygems/commands/yank_command"
class TestGemCommandsYankCommand < Gem::TestCase
@@ -113,8 +113,7 @@ class TestGemCommandsYankCommand < Gem::TestCase
end
def test_with_webauthn_enabled_success
- port = 5678
- server = TCPServer.new(port)
+ server = Gem::MockTCPServer.new
@fetcher.respond_with_require_otp("http://example/api/v1/gems/yank", "Successfully yanked")
@fetcher.respond_with_webauthn_url
@@ -129,12 +128,10 @@ class TestGemCommandsYankCommand < Gem::TestCase
@cmd.execute
end
end
- ensure
- server.close
end
assert_match %r{Yanking gem from http://example}, @ui.output
- assert_match "You have enabled multi-factor authentication. Please visit #{@fetcher.webauthn_url_with_port(port)} " \
+ assert_match "You have enabled multi-factor authentication. Please visit #{@fetcher.webauthn_url_with_port(server.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.", @ui.output
assert_match "You are verified with a security device. You may close the browser window.", @ui.output
@@ -143,8 +140,7 @@ class TestGemCommandsYankCommand < Gem::TestCase
end
def test_with_webauthn_enabled_failure
- port = 5678
- server = TCPServer.new(port)
+ server = Gem::MockTCPServer.new
error = Gem::WebauthnVerificationError.new("Something went wrong")
@fetcher.respond_with_require_otp("http://example/api/v1/gems/yank", "Successfully yanked")
@@ -161,15 +157,13 @@ class TestGemCommandsYankCommand < Gem::TestCase
@cmd.execute
end
end
- ensure
- server.close
end
end
assert_equal 1, error.exit_code
assert_match @fetcher.last_request["Authorization"], Gem.configuration.rubygems_api_key
assert_match %r{Yanking gem from http://example}, @ui.output
- assert_match "You have enabled multi-factor authentication. Please visit #{@fetcher.webauthn_url_with_port(port)} " \
+ assert_match "You have enabled multi-factor authentication. Please visit #{@fetcher.webauthn_url_with_port(server.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.", @ui.output
assert_match "ERROR: Security device verification failed: Something went wrong", @ui.error
@@ -178,8 +172,7 @@ class TestGemCommandsYankCommand < Gem::TestCase
end
def test_with_webauthn_enabled_success_with_polling
- port = 5678
- server = TCPServer.new(port)
+ server = Gem::MockTCPServer.new
@fetcher.respond_with_require_otp("http://example/api/v1/gems/yank", "Successfully yanked")
@fetcher.respond_with_webauthn_url
@@ -193,12 +186,10 @@ class TestGemCommandsYankCommand < Gem::TestCase
use_ui @ui do
@cmd.execute
end
- ensure
- server.close
end
assert_match %r{Yanking gem from http://example}, @ui.output
- assert_match "You have enabled multi-factor authentication. Please visit #{@fetcher.webauthn_url_with_port(port)} " \
+ assert_match "You have enabled multi-factor authentication. Please visit #{@fetcher.webauthn_url_with_port(server.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.", @ui.output
assert_match "You are verified with a security device. You may close the browser window.", @ui.output
@@ -207,8 +198,7 @@ class TestGemCommandsYankCommand < Gem::TestCase
end
def test_with_webauthn_enabled_failure_with_polling
- port = 5678
- server = TCPServer.new(port)
+ server = Gem::MockTCPServer.new
@fetcher.respond_with_require_otp("http://example/api/v1/gems/yank", "Successfully yanked")
@fetcher.respond_with_webauthn_url
@@ -223,15 +213,13 @@ class TestGemCommandsYankCommand < Gem::TestCase
use_ui @ui do
@cmd.execute
end
- ensure
- server.close
end
end
assert_equal 1, error.exit_code
assert_match @fetcher.last_request["Authorization"], Gem.configuration.rubygems_api_key
assert_match %r{Yanking gem from http://example}, @ui.output
- assert_match "You have enabled multi-factor authentication. Please visit #{@fetcher.webauthn_url_with_port(port)} " \
+ assert_match "You have enabled multi-factor authentication. Please visit #{@fetcher.webauthn_url_with_port(server.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.", @ui.output
assert_match "ERROR: Security device verification failed: The token in the link you used has either expired " \