mirror of
https://github.com/ruby/ruby.git
synced 2025-09-15 16:44:01 +02:00
Merge rubygems-3.0.0.beta3.
* [GSoC] Multi-factor feature for RubyGems https://github.com/rubygems/rubygems/pull/2369 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66118 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
5cae104e51
commit
7a46a3b941
9 changed files with 169 additions and 12 deletions
|
@ -161,6 +161,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
|
|||
|
||||
@response = "Successfully registered gem: freebird (1.0.1)"
|
||||
@fetcher.data["#{@host}/api/v1/gems"] = [@response, 200, 'OK']
|
||||
|
||||
send_battery
|
||||
end
|
||||
|
||||
|
@ -230,6 +231,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
|
|||
spec.metadata['allowed_push_host'] = "https://privategemserver.example"
|
||||
end
|
||||
|
||||
|
||||
response = %{ERROR: "#{@host}" is not allowed by the gemspec, which only allows "https://privategemserver.example"}
|
||||
|
||||
assert_raises Gem::MockGemUi::TermError do
|
||||
|
@ -347,4 +349,41 @@ class TestGemCommandsPushCommand < Gem::TestCase
|
|||
@fetcher.last_request["Authorization"]
|
||||
end
|
||||
|
||||
def test_otp_verified_success
|
||||
response_fail = "You have enabled multifactor authentication but your request doesn't have the correct OTP code. Please check it and retry."
|
||||
response_success = 'Successfully registered gem: freewill (1.0.0)'
|
||||
|
||||
@fetcher.data["#{Gem.host}/api/v1/gems"] = proc do
|
||||
@call_count ||= 0
|
||||
(@call_count += 1).odd? ? [response_fail, 401, 'Unauthorized'] : [response_success, 200, 'OK']
|
||||
end
|
||||
|
||||
@otp_ui = Gem::MockGemUi.new "111111\n"
|
||||
use_ui @otp_ui do
|
||||
@cmd.send_gem(@path)
|
||||
end
|
||||
|
||||
assert_match 'You have enabled multi-factor authentication. Please enter OTP code.', @otp_ui.output
|
||||
assert_match 'Code: ', @otp_ui.output
|
||||
assert_match response_success, @otp_ui.output
|
||||
assert_equal '111111', @fetcher.last_request['OTP']
|
||||
end
|
||||
|
||||
def test_otp_verified_failure
|
||||
response = "You have enabled multifactor authentication but your request doesn't have the correct OTP code. Please check it and retry."
|
||||
@fetcher.data["#{Gem.host}/api/v1/gems"] = [response, 401, 'Unauthorized']
|
||||
|
||||
@otp_ui = Gem::MockGemUi.new "111111\n"
|
||||
assert_raises Gem::MockGemUi::TermError do
|
||||
use_ui @otp_ui do
|
||||
@cmd.send_gem(@path)
|
||||
end
|
||||
end
|
||||
|
||||
assert_match response, @otp_ui.output
|
||||
assert_match 'You have enabled multi-factor authentication. Please enter OTP code.', @otp_ui.output
|
||||
assert_match 'Code: ', @otp_ui.output
|
||||
assert_equal '111111', @fetcher.last_request['OTP']
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue