From 5755d3886f1abf805e4ca535f24dc5bd1635b255 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Wed, 14 Aug 2019 12:08:59 +0100 Subject: [PATCH] FIX: Do not raise exception if the authenticator email is missing Followup to 296cdc53ee41bb58d0fe5c56df6fc1f7100dd7d4 --- lib/auth/result.rb | 2 +- spec/components/auth/managed_authenticator_spec.rb | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/auth/result.rb b/lib/auth/result.rb index d825758433f..0e715bd6758 100644 --- a/lib/auth/result.rb +++ b/lib/auth/result.rb @@ -19,7 +19,7 @@ class Auth::Result end def email - @email.downcase + @email&.downcase end def failed? diff --git a/spec/components/auth/managed_authenticator_spec.rb b/spec/components/auth/managed_authenticator_spec.rb index 84889de712f..ad1ac40a00f 100644 --- a/spec/components/auth/managed_authenticator_spec.rb +++ b/spec/components/auth/managed_authenticator_spec.rb @@ -140,6 +140,17 @@ describe Auth::ManagedAuthenticator do result = authenticator.after_authenticate(hash) expect(result.user.id).to eq(user.id) end + + it 'works if there is no email' do + expect { + result = authenticator.after_authenticate(hash.deep_merge(info: { email: nil })) + expect(result.user).to eq(nil) + expect(result.username).to eq("IAmGroot") + expect(result.email).to eq(nil) + }.to change { UserAssociatedAccount.count }.by(1) + expect(UserAssociatedAccount.last.user).to eq(nil) + expect(UserAssociatedAccount.last.info["nickname"]).to eq("IAmGroot") + end end describe "avatar on update" do