Commit 75b2ff8f43d52c76d4d4eaac37618295b5046cc6

Authored by Izaak Alpert
1 parent 4fcc17e6

Added ldap tests

Change-Id: Ifd77615b3b92d7d8bca92b8875aa8204356cfd85
spec/lib/auth_oauth_spec.rb
@@ -1,98 +0,0 @@ @@ -1,98 +0,0 @@
1 -require 'spec_helper'  
2 -  
3 -describe Gitlab::Auth do  
4 - let(:gl_auth) { Gitlab::Auth.new }  
5 -  
6 - before do  
7 - Gitlab.config.stub(omniauth: {})  
8 -  
9 - @info = mock(  
10 - uid: '12djsak321',  
11 - name: 'John',  
12 - email: 'john@mail.com'  
13 - )  
14 - end  
15 -  
16 - describe :find_for_ldap_auth do  
17 - before do  
18 - @auth = mock(  
19 - uid: '12djsak321',  
20 - info: @info,  
21 - provider: 'ldap'  
22 - )  
23 - end  
24 -  
25 - it "should find by uid & provider" do  
26 - User.should_receive :find_by_extern_uid_and_provider  
27 - gl_auth.find_for_ldap_auth(@auth)  
28 - end  
29 -  
30 - it "should update credentials by email if missing uid" do  
31 - user = double('User')  
32 - User.stub find_by_extern_uid_and_provider: nil  
33 - User.stub find_by_email: user  
34 - user.should_receive :update_attributes  
35 - gl_auth.find_for_ldap_auth(@auth)  
36 - end  
37 -  
38 - it "should update credentials by username if missing uid and Gitlab.config.ldap.allow_username_or_email_login is true" do  
39 - user = double('User')  
40 - value = Gitlab.config.ldap.allow_username_or_email_login  
41 - Gitlab.config.ldap['allow_username_or_email_login'] = true  
42 - User.stub find_by_extern_uid_and_provider: nil  
43 - User.stub find_by_email: nil  
44 - User.stub find_by_username: user  
45 - user.should_receive :update_attributes  
46 - gl_auth.find_for_ldap_auth(@auth)  
47 - Gitlab.config.ldap['allow_username_or_email_login'] = value  
48 - end  
49 -  
50 - it "should not update credentials by username if missing uid and Gitlab.config.ldap.allow_username_or_email_login is false" do  
51 - user = double('User')  
52 - value = Gitlab.config.ldap.allow_username_or_email_login  
53 - Gitlab.config.ldap['allow_username_or_email_login'] = false  
54 - User.stub find_by_extern_uid_and_provider: nil  
55 - User.stub find_by_email: nil  
56 - User.stub find_by_username: user  
57 - user.should_not_receive :update_attributes  
58 - gl_auth.find_for_ldap_auth(@auth)  
59 - Gitlab.config.ldap['allow_username_or_email_login'] = value  
60 - end  
61 -  
62 - it "should create from auth if user does not exist"do  
63 - User.stub find_by_extern_uid_and_provider: nil  
64 - User.stub find_by_email: nil  
65 - gl_auth.should_receive :create_from_omniauth  
66 - gl_auth.find_for_ldap_auth(@auth)  
67 - end  
68 - end  
69 -  
70 - describe :find_or_new_for_omniauth do  
71 - before do  
72 - @auth = mock(  
73 - info: @info,  
74 - provider: 'twitter',  
75 - uid: '12djsak321',  
76 - )  
77 - end  
78 -  
79 - it "should find user"do  
80 - User.should_receive :find_by_provider_and_extern_uid  
81 - gl_auth.should_not_receive :create_from_omniauth  
82 - gl_auth.find_or_new_for_omniauth(@auth)  
83 - end  
84 -  
85 - it "should not create user"do  
86 - User.stub find_by_provider_and_extern_uid: nil  
87 - gl_auth.should_not_receive :create_from_omniauth  
88 - gl_auth.find_or_new_for_omniauth(@auth)  
89 - end  
90 -  
91 - it "should create user if single_sing_on"do  
92 - Gitlab.config.omniauth['allow_single_sign_on'] = true  
93 - User.stub find_by_provider_and_extern_uid: nil  
94 - gl_auth.should_receive :create_from_omniauth  
95 - gl_auth.find_or_new_for_omniauth(@auth)  
96 - end  
97 - end  
98 -end  
spec/lib/gitlab/ldap/ldap_user_auth_spec.rb 0 → 100644
@@ -0,0 +1,57 @@ @@ -0,0 +1,57 @@
  1 +require 'spec_helper'
  2 +
  3 +describe Gitlab::LDAP do
  4 + let(:gl_auth) { Gitlab::LDAP::User }
  5 +
  6 + before do
  7 + Gitlab.config.stub(omniauth: {})
  8 +
  9 + @info = mock(
  10 + uid: '12djsak321',
  11 + name: 'John',
  12 + email: 'john@mail.com'
  13 + )
  14 + end
  15 +
  16 + describe :find_for_ldap_auth do
  17 + before do
  18 + @auth = mock(
  19 + uid: '12djsak321',
  20 + info: @info,
  21 + provider: 'ldap'
  22 + )
  23 + end
  24 +
  25 + it "should update credentials by email if missing uid" do
  26 + user = double('User')
  27 + User.stub find_by_extern_uid_and_provider: nil
  28 + User.stub find_by_email: user
  29 + user.should_receive :update_attributes
  30 + gl_auth.find_or_create(@auth)
  31 + end
  32 +
  33 + it "should update credentials by username if missing uid and Gitlab.config.ldap.allow_username_or_email_login is true" do
  34 + user = double('User')
  35 + value = Gitlab.config.ldap.allow_username_or_email_login
  36 + Gitlab.config.ldap['allow_username_or_email_login'] = true
  37 + User.stub find_by_extern_uid_and_provider: nil
  38 + User.stub find_by_email: nil
  39 + User.stub find_by_username: user
  40 + user.should_receive :update_attributes
  41 + gl_auth.find_or_create(@auth)
  42 + Gitlab.config.ldap['allow_username_or_email_login'] = value
  43 + end
  44 +
  45 + it "should not update credentials by username if missing uid and Gitlab.config.ldap.allow_username_or_email_login is false" do
  46 + user = double('User')
  47 + value = Gitlab.config.ldap.allow_username_or_email_login
  48 + Gitlab.config.ldap['allow_username_or_email_login'] = false
  49 + User.stub find_by_extern_uid_and_provider: nil
  50 + User.stub find_by_email: nil
  51 + User.stub find_by_username: user
  52 + user.should_not_receive :update_attributes
  53 + gl_auth.find_or_create(@auth)
  54 + Gitlab.config.ldap['allow_username_or_email_login'] = value
  55 + end
  56 + end
  57 +end