diff options
author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2020-12-18 12:13:33 +0900 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2020-12-18 13:33:18 +0900 |
commit | 0e40cc9b194a5e46024d32b85a61e651372a65cb (patch) | |
tree | d91f781ca34d78897d8cea9fb3403e47f891df5a /test/rubygems/test_gem_commands_push_command.rb | |
parent | 34f06062174882a98ebef998c50ad8d4f7fc0f2e (diff) | |
download | ruby-0e40cc9b194a5e46024d32b85a61e651372a65cb.tar.gz |
Merge RubyGems 3.2.2 and Bundler 2.2.2
Diffstat (limited to 'test/rubygems/test_gem_commands_push_command.rb')
-rw-r--r-- | test/rubygems/test_gem_commands_push_command.rb | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/test/rubygems/test_gem_commands_push_command.rb b/test/rubygems/test_gem_commands_push_command.rb index 68681af22f..55dd51e6ad 100644 --- a/test/rubygems/test_gem_commands_push_command.rb +++ b/test/rubygems/test_gem_commands_push_command.rb @@ -404,11 +404,13 @@ class TestGemCommandsPushCommand < Gem::TestCase assert_equal '111111', @fetcher.last_request['OTP'] end - def test_sending_gem_unathorized_api_key + def test_sending_gem_unathorized_api_key_with_mfa_enabled + response_mfa_enabled = "You have enabled multifactor authentication but your request doesn't have the correct OTP code. Please check it and retry." response_forbidden = "The API key doesn't have access" response_success = 'Successfully registered gem: freewill (1.0.0)' @fetcher.data["#{@host}/api/v1/gems"] = [ + [response_mfa_enabled, 401, 'Unauthorized'], [response_forbidden, 403, 'Forbidden'], [response_success, 200, "OK"], ] @@ -417,17 +419,54 @@ class TestGemCommandsPushCommand < Gem::TestCase @cmd.instance_variable_set :@host, @host @cmd.instance_variable_set :@scope, :push_rubygem - @ui = Gem::MockGemUi.new "some@mail.com\npass\n" + @ui = Gem::MockGemUi.new "11111\nsome@mail.com\npass\n" use_ui @ui do @cmd.send_gem(@path) end + mfa_notice = "You have enabled multi-factor authentication. Please enter OTP code." access_notice = "The existing key doesn't have access of push_rubygem on https://rubygems.example. Please sign in to update access." + assert_match mfa_notice, @ui.output assert_match access_notice, @ui.output assert_match "Email:", @ui.output assert_match "Password:", @ui.output assert_match "Added push_rubygem scope to the existing API key", @ui.output assert_match response_success, @ui.output + assert_equal '11111', @fetcher.last_request['OTP'] + end + + def test_sending_gem_with_no_local_creds + Gem.configuration.rubygems_api_key = nil + + response_mfa_enabled = "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["#{@host}/api/v1/gems"] = [ + [response_success, 200, "OK"], + ] + + @fetcher.data["#{@host}/api/v1/api_key"] = [ + [response_mfa_enabled, 401, 'Unauthorized'], + ["", 200, "OK"], + ] + + @cmd.instance_variable_set :@scope, :push_rubygem + @cmd.options[:args] = [@path] + @cmd.options[:host] = @host + + @ui = Gem::MockGemUi.new "some@mail.com\npass\n11111\n" + use_ui @ui do + @cmd.execute + end + + mfa_notice = "You have enabled multi-factor authentication. Please enter OTP code." + assert_match mfa_notice, @ui.output + assert_match "Enter your https://rubygems.example credentials.", @ui.output + assert_match "Email:", @ui.output + assert_match "Password:", @ui.output + assert_match "Signed in with API key:", @ui.output + assert_match response_success, @ui.output + assert_equal '11111', @fetcher.last_request['OTP'] end private |