Add basic find / create specs for LDAP user

parent ca17e4b7
...@@ -2,45 +2,37 @@ require 'spec_helper' ...@@ -2,45 +2,37 @@ require 'spec_helper'
describe Gitlab::LDAP::User do describe Gitlab::LDAP::User do
let(:gl_auth) { Gitlab::LDAP::User } let(:gl_auth) { Gitlab::LDAP::User }
let(:info) do
before do double(
Gitlab.config.stub(omniauth: {})
@info = double(
uid: '12djsak321',
name: 'John', name: 'John',
email: 'john@mail.com', email: 'john@example.com',
nickname: 'john' nickname: 'john'
) )
end end
before { Gitlab.config.stub(omniauth: {}) }
describe :find_or_create do
let(:auth) do
double(info: info, provider: 'ldap', uid: 'my-uid')
end
it "finds the user if already existing" do
existing_user = create(:user, extern_uid: 'my-uid', provider: 'ldap')
describe :find_for_ldap_auth do expect{ gl_auth.find_or_create(auth) }.to_not change{ User.count }
before do
@auth = double(
uid: '12djsak321',
info: @info,
provider: 'ldap'
)
end end
it "should update credentials by email if missing uid" do it "connects to existing non-ldap user if the email matches" do
user = double('User') existing_user = create(:user, email: 'john@example.com')
User.stub find_by_extern_uid_and_provider: nil expect{ gl_auth.find_or_create(auth) }.to_not change{ User.count }
User.stub(:find_by).with(hash_including(email: anything())) { user }
user.should_receive :update_attributes existing_user.reload
gl_auth.find_or_create(@auth) expect(existing_user.extern_uid).to eql 'my-uid'
expect(existing_user.provider).to eql 'ldap'
end end
it "should not update credentials by username if missing uid and Gitlab.config.ldap.allow_username_or_email_login is false" do it "creates a new user if not found" do
user = double('User') expect{ gl_auth.find_or_create(auth) }.to change{ User.count }.by(1)
value = Gitlab.config.ldap.allow_username_or_email_login
Gitlab.config.ldap['allow_username_or_email_login'] = false
User.stub find_by_extern_uid_and_provider: nil
User.stub(:find_by).with(hash_including(email: anything())) { nil }
User.stub(:find_by).with(hash_including(username: anything())) { user }
user.should_not_receive :update_attributes
gl_auth.find_or_create(@auth)
Gitlab.config.ldap['allow_username_or_email_login'] = value
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment