Fix failure on blank image URLs passed from oauth (#12390)
This commit is contained in:
parent
f9f6be2ca7
commit
bb59e4b869
5 changed files with 34 additions and 3 deletions
|
|
@ -6,10 +6,11 @@ module Authentication
|
|||
SETTINGS_URL = "https://www.facebook.com/settings?tab=applications".freeze
|
||||
|
||||
def new_user_data
|
||||
image_url = @info.image.gsub("http://", "https://")
|
||||
{
|
||||
name: @info.name,
|
||||
email: @info.email || "",
|
||||
remote_profile_image_url: @info.image.gsub("http://", "https://"),
|
||||
remote_profile_image_url: Users::SafeRemoteProfileImageUrl.call(image_url),
|
||||
facebook_username: user_nickname,
|
||||
facebook_created_at: Time.zone.now
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ module Authentication
|
|||
github_created_at: raw_info.created_at,
|
||||
github_username: info.nickname,
|
||||
name: name,
|
||||
remote_profile_image_url: info.image.to_s
|
||||
remote_profile_image_url: Users::SafeRemoteProfileImageUrl.call(info.image.to_s)
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ module Authentication
|
|||
{
|
||||
email: info.email.to_s,
|
||||
name: name,
|
||||
remote_profile_image_url: remote_profile_image_url,
|
||||
remote_profile_image_url: Users::SafeRemoteProfileImageUrl.call(remote_profile_image_url),
|
||||
twitter_created_at: raw_info.created_at,
|
||||
twitter_followers_count: raw_info.followers_count.to_i,
|
||||
twitter_following_count: raw_info.friends_count.to_i,
|
||||
|
|
|
|||
10
app/services/users/safe_remote_profile_image_url.rb
Normal file
10
app/services/users/safe_remote_profile_image_url.rb
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
module Users
|
||||
module SafeRemoteProfileImageUrl
|
||||
# Basic check for nil and blank URLs, alongside likely incomplete URLs, such as just "image.jpg".
|
||||
def self.call(url)
|
||||
return url if url.to_s.start_with?("https")
|
||||
|
||||
Users::ProfileImageGenerator.call
|
||||
end
|
||||
end
|
||||
end
|
||||
20
spec/services/users/safe_remote_profile_image_url_spec.rb
Normal file
20
spec/services/users/safe_remote_profile_image_url_spec.rb
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe Users::SafeRemoteProfileImageUrl, type: :service do
|
||||
it "returns the url if passed for proper URLs" do
|
||||
url = "https://image.com/image.png"
|
||||
expect(described_class.call(url)).to eq(url)
|
||||
end
|
||||
|
||||
it "returns fallback image if passed nil" do
|
||||
expect(described_class.call(nil)).to start_with("https://emojipedia-us.s3")
|
||||
end
|
||||
|
||||
it "returns fallback image if passed blank" do
|
||||
expect(described_class.call("")).to start_with("https://emojipedia-us.s3")
|
||||
end
|
||||
|
||||
it "returns fallback image if passed non-URL" do
|
||||
expect(described_class.call("image")).to start_with("https://emojipedia-us.s3")
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Reference in a new issue