diff --git a/app/helpers/profile_helper.rb b/app/helpers/profile_helper.rb index 05a6faed5..34627e4e5 100644 --- a/app/helpers/profile_helper.rb +++ b/app/helpers/profile_helper.rb @@ -6,7 +6,9 @@ module ProfileHelper return {} if user_identities.blank? urls = user_identities.pluck(:auth_data_dump).each_with_object({}) do |data, hash| - if (data_urls = data.dig(:info, :urls)) + # TODO: [@jacobherrington] There are some examples in production of the `auth_data_dump` value being + # `nil`. This appears to be the case around ~0.6% of the time. + if (data_urls = data&.dig(:info, :urls)) hash.merge!(data_urls) end end diff --git a/spec/factories/users.rb b/spec/factories/users.rb index 2419d898a..369271161 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -36,6 +36,21 @@ FactoryBot.define do end end + trait :with_broken_identity do + # Mimics a situation that can occur in production + transient { identities { Authentication::Providers.available } } + + after(:create) do |user, options| + options.identities.each do |provider| + auth = OmniAuth.config.mock_auth.fetch(provider.to_sym) + create( + :identity, + user: user, provider: provider, uid: auth.uid, auth_data_dump: nil, + ) + end + end + end + trait :super_admin do after(:build) { |user| user.add_role(:super_admin) } end diff --git a/spec/helpers/profile_helper_spec.rb b/spec/helpers/profile_helper_spec.rb index f56e4125e..6d45b9d63 100644 --- a/spec/helpers/profile_helper_spec.rb +++ b/spec/helpers/profile_helper_spec.rb @@ -28,6 +28,16 @@ describe ProfileHelper do end end + context "when a user has a broken social authentication provider linked" do + let(:user) do + create(:user, :with_broken_identity, identities: ["github"]) + end + + it "ignores that auth provider" do + expect(actual).to eq({}) + end + end + context "when a user has multiple social authentication providers linked" do let(:user) do omniauth_mock_github_payload