[前][次][番号順一覧][スレッド一覧]

ruby-changes:71639

From: Ashley <ko1@a...>
Date: Wed, 6 Apr 2022 08:55:15 +0900 (JST)
Subject: [ruby-changes:71639] 4ae3b78c95 (master): [rubygems/rubygems] Correct mfa level name

https://git.ruby-lang.org/ruby.git/commit/?id=4ae3b78c95

From 4ae3b78c9510d5bd0cf8465bcbf125ae96a9e5bf Mon Sep 17 00:00:00 2001
From: Ashley Ellis Pierce <anellis12@g...>
Date: Mon, 24 Jan 2022 16:13:20 -0500
Subject: [rubygems/rubygems] Correct mfa level name

https://github.com/rubygems/rubygems/commit/a002e351ae
---
 lib/rubygems/gemcutter_utilities.rb               |  4 +-
 test/rubygems/test_gem_commands_signin_command.rb | 52 ++++++++++++-----------
 2 files changed, 29 insertions(+), 27 deletions(-)

diff --git a/lib/rubygems/gemcutter_utilities.rb b/lib/rubygems/gemcutter_utilities.rb
index adf85d1b6c..895caf57e7 100644
--- a/lib/rubygems/gemcutter_utilities.rb
+++ b/lib/rubygems/gemcutter_utilities.rb
@@ -272,11 +272,9 @@ module Gem::GemcutterUtilities https://github.com/ruby/ruby/blob/trunk/lib/rubygems/gemcutter_utilities.rb#L272
   def get_mfa_params(email, password)
     mfa_level = get_user_mfa_level(email, password)
     params = {}
-    if mfa_level == "ui_only" || mfa_level == "ui_and_gem_sign"
+    if mfa_level == "ui_only" || mfa_level == "ui_and_gem_signin"
       selected = ask "Would you like to enable MFA for this key? [y/N]"
       params["mfa"] = true if selected =~ /^[yY](es)?$/
-    elsif mfa_level == "ui_and_api"
-      params["mfa"] = true
     end
     params
   end
diff --git a/test/rubygems/test_gem_commands_signin_command.rb b/test/rubygems/test_gem_commands_signin_command.rb
index b1493fb137..ea10bb0fb2 100644
--- a/test/rubygems/test_gem_commands_signin_command.rb
+++ b/test/rubygems/test_gem_commands_signin_command.rb
@@ -105,14 +105,15 @@ class TestGemCommandsSigninCommand < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_commands_signin_command.rb#L105
     assert_equal api_key, credentials[:rubygems_api_key]
   end
 
-  def test_execute_with_key_name_scope_and_mfa
+  def test_execute_with_key_name_scope_and_mfa_level_of_ui_only
     email     = 'you@e...'
     password  = 'secret'
     api_key   = '1234'
     fetcher   = Gem::RemoteFetcher.fetcher
+    mfa_level = "ui_only"
 
     key_name_ui = Gem::MockGemUi.new "#{email}\n#{password}\ntest-key\n\ny\n\n\n\n\n\ny"
-    util_capture_with_mfa_enabled(key_name_ui, nil, api_key, fetcher) { @cmd.execute }
+    util_capture(key_name_ui, nil, api_key, fetcher, mfa_level) { @cmd.execute }
 
     user = ENV["USER"] || ENV["USERNAME"]
 
@@ -131,36 +132,39 @@ class TestGemCommandsSigninCommand < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_commands_signin_command.rb#L132
     assert_equal api_key, credentials[:rubygems_api_key]
   end
 
-  # Utility method to capture IO/UI within the block passed
-
-  def util_capture(ui_stub = nil, host = nil, api_key = nil, fetcher = Gem::FakeFetcher.new)
-    api_key        ||= 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903'
-    response         = [api_key, 200, 'OK']
-    profile_response =[{"mfa" => "disabled"}.to_json, 200, 'OK']
-    email            = 'you@e...'
-    password         = 'secret'
+  def test_execute_with_key_name_scope_and_mfa_level_of_gem_signin
+    email     = 'you@e...'
+    password  = 'secret'
+    api_key   = '1234'
+    fetcher   = Gem::RemoteFetcher.fetcher
+    mfa_level = "ui_and_gem_signin"
 
-    # Set the expected response for the Web-API supplied
-    ENV['RUBYGEMS_HOST']       = host || Gem::DEFAULT_HOST
-    data_key                   = "#{ENV['RUBYGEMS_HOST']}/api/v1/api_key"
-    fetcher.data[data_key]     = response
-    profile                    = "#{ENV['RUBYGEMS_HOST']}/api/v1/profile"
-    fetcher.data[profile]      = profile_response
-    Gem::RemoteFetcher.fetcher = fetcher
+    key_name_ui = Gem::MockGemUi.new "#{email}\n#{password}\ntest-key\n\ny\n\n\n\n\n\ny"
+    util_capture(key_name_ui, nil, api_key, fetcher, mfa_level) { @cmd.execute }
 
-    sign_in_ui = ui_stub || Gem::MockGemUi.new("#{email}\n#{password}\n\n\n\n\n\n\n\n\n")
+    user = ENV["USER"] || ENV["USERNAME"]
 
-    use_ui sign_in_ui do
-      yield
-    end
+    assert_match "API Key name [#{Socket.gethostname}-#{user}", key_name_ui.output
+    assert_match "index_rubygems [y/N]", key_name_ui.output
+    assert_match "push_rubygem [y/N]", key_name_ui.output
+    assert_match "yank_rubygem [y/N]", key_name_ui.output
+    assert_match "add_owner [y/N]", key_name_ui.output
+    assert_match "remove_owner [y/N]", key_name_ui.output
+    assert_match "access_webhooks [y/N]", key_name_ui.output
+    assert_match "show_dashboard [y/N]", key_name_ui.output
+    assert_match "Would you like to enable MFA for this key? [y/N]", key_name_ui.output
+    assert_equal "name=test-key&push_rubygem=true&mfa=true", fetcher.last_request.body
 
-    sign_in_ui
+    credentials = load_yaml_file Gem.configuration.credentials_path
+    assert_equal api_key, credentials[:rubygems_api_key]
   end
 
-  def util_capture_with_mfa_enabled(ui_stub = nil, host = nil, api_key = nil, fetcher = Gem::FakeFetcher.new)
+  # Utility method to capture IO/UI within the block passed
+
+  def util_capture(ui_stub = nil, host = nil, api_key = nil, fetcher = Gem::FakeFetcher.new, mfa_level = "disabled")
     api_key        ||= 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903'
     response         = [api_key, 200, 'OK']
-    profile_response =[{"mfa" => "ui_only"}.to_json, 200, 'OK']
+    profile_response =[{"mfa" => mfa_level}.to_json, 200, 'OK']
     email            = 'you@e...'
     password         = 'secret'
 
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]