summaryrefslogtreecommitdiff
path: root/test/rubygems/test_gem_commands_signin_command.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/rubygems/test_gem_commands_signin_command.rb')
-rw-r--r--test/rubygems/test_gem_commands_signin_command.rb61
1 files changed, 57 insertions, 4 deletions
diff --git a/test/rubygems/test_gem_commands_signin_command.rb b/test/rubygems/test_gem_commands_signin_command.rb
index 0f856a53ba..b1493fb137 100644
--- a/test/rubygems/test_gem_commands_signin_command.rb
+++ b/test/rubygems/test_gem_commands_signin_command.rb
@@ -105,18 +105,71 @@ class TestGemCommandsSigninCommand < Gem::TestCase
assert_equal api_key, credentials[:rubygems_api_key]
end
+ def test_execute_with_key_name_scope_and_mfa
+ email = 'you@example.com'
+ password = 'secret'
+ api_key = '1234'
+ fetcher = Gem::RemoteFetcher.fetcher
+
+ 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 }
+
+ user = ENV["USER"] || ENV["USERNAME"]
+
+ 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
+
+ credentials = load_yaml_file Gem.configuration.credentials_path
+ 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']
- email = 'you@example.com'
- password = 'secret'
+ api_key ||= 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903'
+ response = [api_key, 200, 'OK']
+ profile_response =[{"mfa" => "disabled"}.to_json, 200, 'OK']
+ email = 'you@example.com'
+ password = 'secret'
+
+ # 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
+
+ sign_in_ui = ui_stub || Gem::MockGemUi.new("#{email}\n#{password}\n\n\n\n\n\n\n\n\n")
+
+ use_ui sign_in_ui do
+ yield
+ end
+
+ sign_in_ui
+ end
+
+ def util_capture_with_mfa_enabled(ui_stub = nil, host = nil, api_key = nil, fetcher = Gem::FakeFetcher.new)
+ api_key ||= 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903'
+ response = [api_key, 200, 'OK']
+ profile_response =[{"mfa" => "ui_only"}.to_json, 200, 'OK']
+ email = 'you@example.com'
+ password = 'secret'
# 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
sign_in_ui = ui_stub || Gem::MockGemUi.new("#{email}\n#{password}\n\n\n\n\n\n\n\n\n")