2013-09-12 20:27:51 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2014-08-29 15:29:42 +00:00
|
|
|
describe Gitlab::LDAP::User do
|
2014-10-10 10:03:32 +00:00
|
|
|
let(:gl_user) { Gitlab::LDAP::User.new(auth_hash) }
|
2014-09-01 13:30:46 +00:00
|
|
|
let(:info) do
|
2014-10-10 10:03:32 +00:00
|
|
|
{
|
2013-09-12 20:27:51 +00:00
|
|
|
name: 'John',
|
2014-09-01 13:30:46 +00:00
|
|
|
email: 'john@example.com',
|
2014-03-10 17:16:43 +00:00
|
|
|
nickname: 'john'
|
2014-10-10 10:03:32 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
let(:auth_hash) do
|
2014-10-13 15:33:44 +00:00
|
|
|
double(uid: 'my-uid', provider: 'ldapmain', info: double(info))
|
2013-09-12 20:27:51 +00:00
|
|
|
end
|
2014-09-01 13:30:46 +00:00
|
|
|
|
2015-01-29 21:28:41 +00:00
|
|
|
describe :changed? do
|
|
|
|
it "marks existing ldap user as changed" do
|
|
|
|
existing_user = create(:omniauth_user, extern_uid: 'my-uid', provider: 'ldapmain')
|
2015-02-12 18:17:35 +00:00
|
|
|
expect(gl_user.changed?).to be_truthy
|
2015-01-29 21:28:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "marks existing non-ldap user if the email matches as changed" do
|
|
|
|
existing_user = create(:user, email: 'john@example.com')
|
2015-02-12 18:17:35 +00:00
|
|
|
expect(gl_user.changed?).to be_truthy
|
2015-01-29 21:28:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "dont marks existing ldap user as changed" do
|
|
|
|
existing_user = create(:omniauth_user, email: 'john@example.com', extern_uid: 'my-uid', provider: 'ldapmain')
|
2015-02-12 18:17:35 +00:00
|
|
|
expect(gl_user.changed?).to be_falsey
|
2015-01-29 21:28:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-09-01 13:30:46 +00:00
|
|
|
describe :find_or_create do
|
|
|
|
it "finds the user if already existing" do
|
2014-11-27 11:34:39 +00:00
|
|
|
existing_user = create(:omniauth_user, extern_uid: 'my-uid', provider: 'ldapmain')
|
2013-09-12 20:27:51 +00:00
|
|
|
|
2014-10-10 10:03:32 +00:00
|
|
|
expect{ gl_user.save }.to_not change{ User.count }
|
2013-09-12 20:27:51 +00:00
|
|
|
end
|
|
|
|
|
2014-09-01 13:30:46 +00:00
|
|
|
it "connects to existing non-ldap user if the email matches" do
|
2014-12-04 11:43:08 +00:00
|
|
|
existing_user = create(:omniauth_user, email: 'john@example.com', provider: "twitter")
|
2014-10-10 10:03:32 +00:00
|
|
|
expect{ gl_user.save }.to_not change{ User.count }
|
2014-09-01 13:30:46 +00:00
|
|
|
|
|
|
|
existing_user.reload
|
2014-11-27 11:34:39 +00:00
|
|
|
expect(existing_user.ldap_identity.extern_uid).to eql 'my-uid'
|
|
|
|
expect(existing_user.ldap_identity.provider).to eql 'ldapmain'
|
2013-09-12 20:27:51 +00:00
|
|
|
end
|
|
|
|
|
2014-09-01 13:30:46 +00:00
|
|
|
it "creates a new user if not found" do
|
2014-10-10 10:03:32 +00:00
|
|
|
expect{ gl_user.save }.to change{ User.count }.by(1)
|
2013-09-12 20:27:51 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|