Add tests for finding an oauth authenticated user

parent 4198b58a
...@@ -67,7 +67,7 @@ module Gitlab ...@@ -67,7 +67,7 @@ module Gitlab
end end
def uid def uid
uid = auth.info.uid || auth.uid uid = auth.info.try(:uid) || auth.uid
uid = uid.to_s unless uid.nil? uid = uid.to_s unless uid.nil?
uid uid
end end
......
...@@ -2,39 +2,54 @@ require 'spec_helper' ...@@ -2,39 +2,54 @@ require 'spec_helper'
describe Gitlab::OAuth::User do describe Gitlab::OAuth::User do
let(:gl_auth) { Gitlab::OAuth::User } let(:gl_auth) { Gitlab::OAuth::User }
let(:info) do
before do double(
Gitlab.config.stub(omniauth: {}) uid: 'my-uid',
@info = double(
uid: '12djsak321',
nickname: 'john', nickname: 'john',
name: 'John', name: 'John',
email: 'john@mail.com' email: 'john@mail.com'
) )
end end
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
auth = double(info: info, provider: 'my-provider')
assert gl_auth.find(auth)
end
end
describe :create do describe :create do
it "should create user from LDAP" do it "should create user from LDAP" do
@auth = double(info: @info, provider: 'ldap') @auth = double(info: info, provider: 'ldap')
user = gl_auth.create(@auth) user = gl_auth.create(@auth)
user.should be_valid user.should be_valid
user.extern_uid.should == @info.uid user.extern_uid.should == info.uid
user.provider.should == 'ldap' user.provider.should == 'ldap'
end end
it "should create user from Omniauth" do it "should create user from Omniauth" do
@auth = double(info: @info, provider: 'twitter') @auth = double(info: info, provider: 'twitter')
user = gl_auth.create(@auth) user = gl_auth.create(@auth)
user.should be_valid user.should be_valid
user.extern_uid.should == @info.uid user.extern_uid.should == info.uid
user.provider.should == 'twitter' user.provider.should == 'twitter'
end end
it "should apply defaults to user" do it "should apply defaults to user" do
@auth = double(info: @info, provider: 'ldap') @auth = double(info: info, provider: 'ldap')
user = gl_auth.create(@auth) user = gl_auth.create(@auth)
user.should be_valid user.should be_valid
......
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