summaryrefslogtreecommitdiff
path: root/spec/lib/auth_spec.rb
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2012-09-12 09:23:16 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2012-09-12 09:23:16 +0300
commit048d47e6266b5b078a169f1657d07883e86f169b (patch)
tree156a31fbe9a69fcca1504df83a5313df5a32e15f /spec/lib/auth_spec.rb
parentfa4150d47d88b85d6027729844480a3e7c71d3cd (diff)
downloadgitlab-ce-048d47e6266b5b078a169f1657d07883e86f169b.tar.gz
Refactorn oauth & ldap
Diffstat (limited to 'spec/lib/auth_spec.rb')
-rw-r--r--spec/lib/auth_spec.rb93
1 files changed, 93 insertions, 0 deletions
diff --git a/spec/lib/auth_spec.rb b/spec/lib/auth_spec.rb
new file mode 100644
index 00000000000..5faf1307ed2
--- /dev/null
+++ b/spec/lib/auth_spec.rb
@@ -0,0 +1,93 @@
+require 'spec_helper'
+
+describe Gitlab::Auth do
+ let(:gl_auth) { Gitlab::Auth.new }
+
+ before do
+ @info = mock(
+ uid: '12djsak321',
+ name: 'John',
+ email: 'john@mail.com'
+ )
+ end
+
+ describe :find_for_ldap_auth do
+ before do
+ @auth = mock(
+ uid: '12djsak321',
+ info: @info,
+ provider: 'ldap'
+ )
+ end
+
+ it "should find by uid & provider" do
+ User.should_receive :find_by_extern_uid_and_provider
+ gl_auth.find_for_ldap_auth(@auth)
+ end
+
+ it "should update credentials by email if missing uid" do
+ user = double('User')
+ User.stub find_by_extern_uid_and_provider: nil
+ User.stub find_by_email: user
+ user.should_receive :update_attributes
+ gl_auth.find_for_ldap_auth(@auth)
+ end
+
+
+ it "should create from auth if user doesnot exist"do
+ User.stub find_by_extern_uid_and_provider: nil
+ User.stub find_by_email: nil
+ gl_auth.should_receive :create_from_omniauth
+ gl_auth.find_for_ldap_auth(@auth)
+ end
+ end
+
+ describe :find_or_new_for_omniauth do
+ before do
+ @auth = mock(
+ info: @info,
+ provider: 'twitter',
+ uid: '12djsak321',
+ )
+ end
+
+ it "should find user"do
+ User.should_receive :find_by_provider_and_extern_uid
+ gl_auth.should_not_receive :create_from_omniauth
+ gl_auth.find_or_new_for_omniauth(@auth)
+ end
+
+ it "should not create user"do
+ User.stub find_by_provider_and_extern_uid: nil
+ gl_auth.should_not_receive :create_from_omniauth
+ gl_auth.find_or_new_for_omniauth(@auth)
+ end
+
+ it "should create user if single_sing_on"do
+ Gitlab.config.omniauth.stub allow_single_sign_on: true
+ User.stub find_by_provider_and_extern_uid: nil
+ gl_auth.should_receive :create_from_omniauth
+ gl_auth.find_or_new_for_omniauth(@auth)
+ end
+ end
+
+ describe :create_from_omniauth do
+ it "should create user from LDAP" do
+ @auth = mock(info: @info, provider: 'ldap')
+ user = gl_auth.create_from_omniauth(@auth, true)
+
+ user.should be_valid
+ user.extern_uid.should == @info.uid
+ user.provider.should == 'ldap'
+ end
+
+ it "should create user from Omniauth" do
+ @auth = mock(info: @info, provider: 'twitter')
+ user = gl_auth.create_from_omniauth(@auth, false)
+
+ user.should be_valid
+ user.extern_uid.should == @info.uid
+ user.provider.should == 'twitter'
+ end
+ end
+end