Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix for missing UID issue

In some cases, where Users and Identities are 
manually created, we will have these records in 
the system without a valid UID. This presents a
problem with logging in as the #create method
of RegistrationsController ends up calling
`Identity.find_omniauth` which will find an 
identity - which is invalid. 

By checking for a missing uid we return a nil
from `find_omniauth` which allows the rest of
the logic to take over.

P.S. There are tests for this.
  • Loading branch information...
commit 182ba062bfcc6ef46d271de9f426bafc8a115938 1 parent 70c67a3
@elskwid elskwid authored
View
4 app/models/thincloud/authentication/identity.rb
@@ -30,7 +30,9 @@ def self.human_attribute_name(attr, options={})
#
# Returns: An instance of `Identity` or `nil`.
def self.find_omniauth(omniauth)
- find_by_provider_and_uid omniauth["provider"], omniauth["uid"]
+ if omniauth["uid"].present?
+ find_by_provider_and_uid omniauth["provider"], omniauth["uid"]
+ end
end
# Public: Mark the `Identity` as having been verified.
View
36 test/models/identity_test.rb
@@ -16,15 +16,41 @@ module Thincloud::Authentication
it { identity.must_respond_to(:verified_at) }
describe "self.find_omniauth(omniauth)" do
- let(:auth_hash) do
- OmniAuth::AuthHash.new(provider: "identity", uid: "123")
+ describe "with valid uid" do
+ let(:auth_hash) do
+ OmniAuth::AuthHash.new(provider: "identity", uid: "123")
+ end
+
+ before do
+ Identity.expects(:find_by_provider_and_uid).with("identity", "123")
+ end
+
+ it { Identity.find_omniauth(auth_hash) }
end
- before do
- Identity.expects(:find_by_provider_and_uid).with("identity", "123")
+ describe "with nil uid" do
+ let(:auth_hash) do
+ OmniAuth::AuthHash.new(provider: "identity", uid: nil)
+ end
+
+ before do
+ Identity.expects(:find_by_provider_and_uid).never
+ end
+
+ it { Identity.find_omniauth(auth_hash).must_be_nil }
end
- it { Identity.find_omniauth(auth_hash) }
+ describe "with empty uid" do
+ let(:auth_hash) do
+ OmniAuth::AuthHash.new(provider: "identity", uid: "")
+ end
+
+ before do
+ Identity.expects(:find_by_provider_and_uid).never
+ end
+
+ it { Identity.find_omniauth(auth_hash).must_be_nil }
+ end
end
describe "self.verify!(token)" do
Please sign in to comment.
Something went wrong with that request. Please try again.