Skip to content

Commit

Permalink
[rubygems/rubygems] Rename credential email to identifier in WebAuthn…
Browse files Browse the repository at this point in the history
  • Loading branch information
jenshenny authored and matzbot committed May 3, 2024
1 parent 7662e6f commit c1b11c5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/rubygems/gemcutter_utilities/webauthn_poller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ def webauthn_verification_poll_response(webauthn_url, credentials)
rubygems_api_request(:get, "api/v1/webauthn_verification/#{webauthn_token}/status.json") do |request|
if credentials.empty?
request.add_field "Authorization", api_key
elsif credentials[:identifier] && credentials[:password]
request.basic_auth credentials[:identifier], credentials[:password]
else
request.basic_auth credentials[:email], credentials[:password]
raise Gem::WebauthnVerificationError, "Provided missing credentials"
end
end
end
Expand Down
12 changes: 11 additions & 1 deletion test/rubygems/test_webauthn_poller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def setup
@fetcher = Gem::FakeFetcher.new
Gem::RemoteFetcher.fetcher = @fetcher
@credentials = {
email: "email@example.com",
identifier: "email@example.com",
password: "password",
}
end
Expand Down Expand Up @@ -121,4 +121,14 @@ def test_poll_for_otp_invalid_status
assert_equal error.message,
"Security device verification failed: The token in the link you used has either expired or been used already."
end

def test_poll_for_otp_missing_credentials
@credentials = { password: "password" }

error = assert_raise Gem::WebauthnVerificationError do
Gem::GemcutterUtilities::WebauthnPoller.new({}, @host).poll_for_otp(@webauthn_url, @credentials)
end

assert_equal error.message, "Security device verification failed: Provided missing credentials"
end
end

0 comments on commit c1b11c5

Please sign in to comment.