2013-09-03 21:53:13 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::OAuth::User do
|
|
|
|
let(:gl_auth) { Gitlab::OAuth::User }
|
2014-09-01 10:59:04 +00:00
|
|
|
let(:info) do
|
|
|
|
double(
|
2014-04-07 13:03:05 +00:00
|
|
|
nickname: 'john',
|
2013-09-03 21:53:13 +00:00
|
|
|
name: 'John',
|
|
|
|
email: 'john@mail.com'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2014-09-01 10:59:04 +00:00
|
|
|
before do
|
|
|
|
Gitlab.config.stub(omniauth: {})
|
|
|
|
end
|
|
|
|
|
|
|
|
describe :find do
|
|
|
|
let!(:existing_user) { create(:user, extern_uid: 'my-uid', provider: 'my-provider') }
|
|
|
|
|
|
|
|
it "finds an existing user based on uid and provider (facebook)" do
|
|
|
|
auth = double(info: double(name: 'John'), uid: 'my-uid', provider: 'my-provider')
|
|
|
|
assert gl_auth.find(auth)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "finds an existing user based on nested uid and provider" do
|
2014-09-01 14:31:27 +00:00
|
|
|
auth = double(info: info, uid: 'my-uid', provider: 'my-provider')
|
2014-09-01 10:59:04 +00:00
|
|
|
assert gl_auth.find(auth)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-09-03 21:53:13 +00:00
|
|
|
describe :create do
|
|
|
|
it "should create user from LDAP" do
|
2014-09-01 14:31:27 +00:00
|
|
|
auth = double(info: info, uid: 'my-uid', provider: 'ldap')
|
2014-09-01 11:02:41 +00:00
|
|
|
user = gl_auth.create(auth)
|
2013-09-03 21:53:13 +00:00
|
|
|
|
|
|
|
user.should be_valid
|
2014-09-01 14:31:27 +00:00
|
|
|
user.extern_uid.should == auth.uid
|
2013-09-03 21:53:13 +00:00
|
|
|
user.provider.should == 'ldap'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should create user from Omniauth" do
|
2014-09-01 14:31:27 +00:00
|
|
|
auth = double(info: info, uid: 'my-uid', provider: 'twitter')
|
2014-09-01 11:02:41 +00:00
|
|
|
user = gl_auth.create(auth)
|
2013-09-03 21:53:13 +00:00
|
|
|
|
|
|
|
user.should be_valid
|
2014-09-01 14:31:27 +00:00
|
|
|
user.extern_uid.should == auth.uid
|
2013-09-03 21:53:13 +00:00
|
|
|
user.provider.should == 'twitter'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should apply defaults to user" do
|
2014-09-01 14:31:27 +00:00
|
|
|
auth = double(info: info, uid: 'my-uid', provider: 'ldap')
|
2014-09-01 11:02:41 +00:00
|
|
|
user = gl_auth.create(auth)
|
2013-09-03 21:53:13 +00:00
|
|
|
|
|
|
|
user.should be_valid
|
|
|
|
user.projects_limit.should == Gitlab.config.gitlab.default_projects_limit
|
|
|
|
user.can_create_group.should == Gitlab.config.gitlab.default_can_create_group
|
|
|
|
end
|
2014-09-01 11:48:17 +00:00
|
|
|
|
|
|
|
it "Set a temp email address if not provided (like twitter does)" do
|
|
|
|
info = double(
|
|
|
|
uid: 'my-uid',
|
|
|
|
nickname: 'john',
|
|
|
|
name: 'John'
|
|
|
|
)
|
2014-09-01 14:31:27 +00:00
|
|
|
auth = double(info: info, uid: 'my-uid', provider: 'my-provider')
|
2014-09-01 11:48:17 +00:00
|
|
|
|
|
|
|
user = gl_auth.create(auth)
|
|
|
|
expect(user.email).to_not be_empty
|
|
|
|
end
|
2014-09-01 12:26:10 +00:00
|
|
|
|
|
|
|
it 'generates a username if non provided (google)' do
|
|
|
|
info = double(
|
|
|
|
uid: 'my-uid',
|
|
|
|
name: 'John',
|
|
|
|
email: 'john@example.com'
|
|
|
|
)
|
2014-09-01 14:31:27 +00:00
|
|
|
auth = double(info: info, uid: 'my-uid', provider: 'my-provider')
|
2014-09-01 12:26:10 +00:00
|
|
|
|
|
|
|
user = gl_auth.create(auth)
|
|
|
|
expect(user.username).to eql 'john'
|
|
|
|
end
|
2013-09-03 21:53:13 +00:00
|
|
|
end
|
|
|
|
end
|