diff options
author | Joel Koglin <JoelKoglin@gmail.com> | 2015-07-22 00:03:26 +0300 |
---|---|---|
committer | Joel Koglin <Joel.Koglin@concur.com> | 2015-08-21 19:36:27 +0300 |
commit | 4d2f36118a3b21b6bb4ee702b98d032967ba463a (patch) | |
tree | d2e2093d48b7bc5a38a9c3d1ea85ad7a5904c492 /spec/lib/gitlab/ldap/user_spec.rb | |
parent | f5b3bf84ad10a03c58c161e84ef919661c84267c (diff) |
Issue #993: Fixed login failure when extern_uid changes
Diffstat (limited to 'spec/lib/gitlab/ldap/user_spec.rb')
-rw-r--r-- | spec/lib/gitlab/ldap/user_spec.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/spec/lib/gitlab/ldap/user_spec.rb b/spec/lib/gitlab/ldap/user_spec.rb index 7cfca96f4e0..84d9fb54b61 100644 --- a/spec/lib/gitlab/ldap/user_spec.rb +++ b/spec/lib/gitlab/ldap/user_spec.rb @@ -47,6 +47,28 @@ describe Gitlab::LDAP::User do expect(existing_user.ldap_identity.provider).to eql 'ldapmain' end + it 'connects to existing ldap user if the extern_uid changes' do + existing_user = create(:omniauth_user, email: 'john@example.com', extern_uid: 'old-uid', provider: 'ldapmain') + expect{ ldap_user.save }.not_to change{ User.count } + + existing_user.reload + expect(existing_user.ldap_identity.extern_uid).to eql 'my-uid' + expect(existing_user.ldap_identity.provider).to eql 'ldapmain' + expect(existing_user.id).to eql ldap_user.gl_user.id + end + + it 'maintains an identity per provider' do + existing_user = create(:omniauth_user, email: 'john@example.com', provider: 'twitter') + expect(existing_user.identities.count).to eql(1) + + ldap_user.save + expect(ldap_user.gl_user.identities.count).to eql(2) + + # Expect that find_by provider only returns a single instance of an identity and not an Enumerable + expect(ldap_user.gl_user.identities.find_by(provider: 'twitter')).to be_instance_of Identity + expect(ldap_user.gl_user.identities.find_by(provider: auth_hash.provider)).to be_instance_of Identity + end + it "creates a new user if not found" do expect{ ldap_user.save }.to change{ User.count }.by(1) end |