Skip to content

Commit 7ce2c06

Browse files
Merge pull request #7422 from VitaliySerov/master
Change gem login message to clear up that username can be also used (cherry picked from commit 0721762)
1 parent 98b0df1 commit 7ce2c06

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

lib/rubygems/gemcutter_utilities.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@ def update_scope(scope)
130130

131131
say "The existing key doesn't have access of #{scope} on #{pretty_host}. Please sign in to update access."
132132

133-
email = ask " Email: "
134-
password = ask_for_password "Password: "
133+
identifier = ask "Username/email: "
134+
password = ask_for_password " Password: "
135135

136136
response = rubygems_api_request(:put, "api/v1/api_key",
137137
sign_in_host, scope: scope) do |request|
138-
request.basic_auth email, password
138+
request.basic_auth identifier, password
139139
request["OTP"] = otp if otp
140140
request.body = Gem::URI.encode_www_form({ api_key: api_key }.merge(update_scope_params))
141141
end
@@ -159,23 +159,23 @@ def sign_in(sign_in_host = nil, scope: nil)
159159
say "Don't have an account yet? " \
160160
"Create one at #{sign_in_host}/sign_up"
161161

162-
email = ask " Email: "
163-
password = ask_for_password "Password: "
162+
identifier = ask "Username/email: "
163+
password = ask_for_password " Password: "
164164
say "\n"
165165

166166
key_name = get_key_name(scope)
167167
scope_params = get_scope_params(scope)
168-
profile = get_user_profile(email, password)
168+
profile = get_user_profile(identifier, password)
169169
mfa_params = get_mfa_params(profile)
170170
all_params = scope_params.merge(mfa_params)
171171
warning = profile["warning"]
172-
credentials = { email: email, password: password }
172+
credentials = { identifier: identifier, password: password }
173173

174174
say "#{warning}\n" if warning
175175

176176
response = rubygems_api_request(:post, "api/v1/api_key",
177177
sign_in_host, credentials: credentials, scope: scope) do |request|
178-
request.basic_auth email, password
178+
request.basic_auth identifier, password
179179
request["OTP"] = otp if otp
180180
request.body = Gem::URI.encode_www_form({ name: key_name }.merge(all_params))
181181
end
@@ -295,7 +295,7 @@ def webauthn_verification_url(credentials)
295295
if credentials.empty?
296296
request.add_field "Authorization", api_key
297297
else
298-
request.basic_auth credentials[:email], credentials[:password]
298+
request.basic_auth credentials[:identifier], credentials[:password]
299299
end
300300
end
301301
response.is_a?(Gem::Net::HTTPSuccess) ? response.body : nil
@@ -346,11 +346,11 @@ def default_host?
346346
host == Gem::DEFAULT_HOST
347347
end
348348

349-
def get_user_profile(email, password)
349+
def get_user_profile(identifier, password)
350350
return {} unless default_host?
351351

352352
response = rubygems_api_request(:get, "api/v1/profile/me.yaml") do |request|
353-
request.basic_auth email, password
353+
request.basic_auth identifier, password
354354
end
355355

356356
with_response response do |resp|

test/rubygems/test_gem_commands_owner_command.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ def test_remove_owners_unathorized_api_key
471471

472472
access_notice = "The existing key doesn't have access of remove_owner on RubyGems.org. Please sign in to update access."
473473
assert_match access_notice, @stub_ui.output
474-
assert_match "Email:", @stub_ui.output
474+
assert_match "Username/email:", @stub_ui.output
475475
assert_match "Password:", @stub_ui.output
476476
assert_match "Added remove_owner scope to the existing API key", @stub_ui.output
477477
assert_match response_success, @stub_ui.output
@@ -495,7 +495,7 @@ def test_add_owners_unathorized_api_key
495495

496496
access_notice = "The existing key doesn't have access of add_owner on RubyGems.org. Please sign in to update access."
497497
assert_match access_notice, @stub_ui.output
498-
assert_match "Email:", @stub_ui.output
498+
assert_match "Username/email:", @stub_ui.output
499499
assert_match "Password:", @stub_ui.output
500500
assert_match "Added add_owner scope to the existing API key", @stub_ui.output
501501
assert_match response_success, @stub_ui.output

test/rubygems/test_gem_commands_push_command.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ def test_sending_gem_unathorized_api_key_with_mfa_enabled
547547
access_notice = "The existing key doesn't have access of push_rubygem on https://rubygems.example. Please sign in to update access."
548548
assert_match mfa_notice, @ui.output
549549
assert_match access_notice, @ui.output
550-
assert_match "Email:", @ui.output
550+
assert_match "Username/email:", @ui.output
551551
assert_match "Password:", @ui.output
552552
assert_match "Added push_rubygem scope to the existing API key", @ui.output
553553
assert_match response_success, @ui.output
@@ -588,7 +588,7 @@ def test_sending_gem_with_no_local_creds
588588
mfa_notice = "You have enabled multi-factor authentication. Please enter OTP code."
589589
assert_match mfa_notice, @ui.output
590590
assert_match "Enter your https://rubygems.example credentials.", @ui.output
591-
assert_match "Email:", @ui.output
591+
assert_match "Username/email:", @ui.output
592592
assert_match "Password:", @ui.output
593593
assert_match "Signed in with API key:", @ui.output
594594
assert_match response_success, @ui.output

test/rubygems/test_gem_commands_yank_command.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ def test_yank_gem_unathorized_api_key
291291

292292
access_notice = "The existing key doesn't have access of yank_rubygem on http://example. Please sign in to update access."
293293
assert_match access_notice, @ui.output
294-
assert_match "Email:", @ui.output
294+
assert_match "Username/email:", @ui.output
295295
assert_match "Password:", @ui.output
296296
assert_match "Added yank_rubygem scope to the existing API key", @ui.output
297297
assert_match response_success, @ui.output

0 commit comments

Comments
 (0)