Skip to content

Commit a002e35

Browse files
committed
Correct mfa level name
1 parent e787f7f commit a002e35

File tree

2 files changed

+29
-27
lines changed

2 files changed

+29
-27
lines changed

lib/rubygems/gemcutter_utilities.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,9 @@ def get_scope_params(scope)
272272
def get_mfa_params(email, password)
273273
mfa_level = get_user_mfa_level(email, password)
274274
params = {}
275-
if mfa_level == "ui_only" || mfa_level == "ui_and_gem_sign"
275+
if mfa_level == "ui_only" || mfa_level == "ui_and_gem_signin"
276276
selected = ask "Would you like to enable MFA for this key? [y/N]"
277277
params["mfa"] = true if selected =~ /^[yY](es)?$/
278-
elsif mfa_level == "ui_and_api"
279-
params["mfa"] = true
280278
end
281279
params
282280
end

test/rubygems/test_gem_commands_signin_command.rb

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,15 @@ def test_execute_with_key_name_and_scope
105105
assert_equal api_key, credentials[:rubygems_api_key]
106106
end
107107

108-
def test_execute_with_key_name_scope_and_mfa
108+
def test_execute_with_key_name_scope_and_mfa_level_of_ui_only
109109
email = 'you@example.com'
110110
password = 'secret'
111111
api_key = '1234'
112112
fetcher = Gem::RemoteFetcher.fetcher
113+
mfa_level = "ui_only"
113114

114115
key_name_ui = Gem::MockGemUi.new "#{email}\n#{password}\ntest-key\n\ny\n\n\n\n\n\ny"
115-
util_capture_with_mfa_enabled(key_name_ui, nil, api_key, fetcher) { @cmd.execute }
116+
util_capture(key_name_ui, nil, api_key, fetcher, mfa_level) { @cmd.execute }
116117

117118
user = ENV["USER"] || ENV["USERNAME"]
118119

@@ -131,36 +132,39 @@ def test_execute_with_key_name_scope_and_mfa
131132
assert_equal api_key, credentials[:rubygems_api_key]
132133
end
133134

134-
# Utility method to capture IO/UI within the block passed
135-
136-
def util_capture(ui_stub = nil, host = nil, api_key = nil, fetcher = Gem::FakeFetcher.new)
137-
api_key ||= 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903'
138-
response = [api_key, 200, 'OK']
139-
profile_response =[{"mfa" => "disabled"}.to_json, 200, 'OK']
140-
email = 'you@example.com'
141-
password = 'secret'
135+
def test_execute_with_key_name_scope_and_mfa_level_of_gem_signin
136+
email = 'you@example.com'
137+
password = 'secret'
138+
api_key = '1234'
139+
fetcher = Gem::RemoteFetcher.fetcher
140+
mfa_level = "ui_and_gem_signin"
142141

143-
# Set the expected response for the Web-API supplied
144-
ENV['RUBYGEMS_HOST'] = host || Gem::DEFAULT_HOST
145-
data_key = "#{ENV['RUBYGEMS_HOST']}/api/v1/api_key"
146-
fetcher.data[data_key] = response
147-
profile = "#{ENV['RUBYGEMS_HOST']}/api/v1/profile"
148-
fetcher.data[profile] = profile_response
149-
Gem::RemoteFetcher.fetcher = fetcher
142+
key_name_ui = Gem::MockGemUi.new "#{email}\n#{password}\ntest-key\n\ny\n\n\n\n\n\ny"
143+
util_capture(key_name_ui, nil, api_key, fetcher, mfa_level) { @cmd.execute }
150144

151-
sign_in_ui = ui_stub || Gem::MockGemUi.new("#{email}\n#{password}\n\n\n\n\n\n\n\n\n")
145+
user = ENV["USER"] || ENV["USERNAME"]
152146

153-
use_ui sign_in_ui do
154-
yield
155-
end
147+
assert_match "API Key name [#{Socket.gethostname}-#{user}", key_name_ui.output
148+
assert_match "index_rubygems [y/N]", key_name_ui.output
149+
assert_match "push_rubygem [y/N]", key_name_ui.output
150+
assert_match "yank_rubygem [y/N]", key_name_ui.output
151+
assert_match "add_owner [y/N]", key_name_ui.output
152+
assert_match "remove_owner [y/N]", key_name_ui.output
153+
assert_match "access_webhooks [y/N]", key_name_ui.output
154+
assert_match "show_dashboard [y/N]", key_name_ui.output
155+
assert_match "Would you like to enable MFA for this key? [y/N]", key_name_ui.output
156+
assert_equal "name=test-key&push_rubygem=true&mfa=true", fetcher.last_request.body
156157

157-
sign_in_ui
158+
credentials = load_yaml_file Gem.configuration.credentials_path
159+
assert_equal api_key, credentials[:rubygems_api_key]
158160
end
159161

160-
def util_capture_with_mfa_enabled(ui_stub = nil, host = nil, api_key = nil, fetcher = Gem::FakeFetcher.new)
162+
# Utility method to capture IO/UI within the block passed
163+
164+
def util_capture(ui_stub = nil, host = nil, api_key = nil, fetcher = Gem::FakeFetcher.new, mfa_level = "disabled")
161165
api_key ||= 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903'
162166
response = [api_key, 200, 'OK']
163-
profile_response =[{"mfa" => "ui_only"}.to_json, 200, 'OK']
167+
profile_response =[{"mfa" => mfa_level}.to_json, 200, 'OK']
164168
email = 'you@example.com'
165169
password = 'secret'
166170

0 commit comments

Comments
 (0)