Commit 7b8bd93e673a6ace673cab00e0cc10489d64437d

Authored by Dmitriy Zaporozhets
1 parent 3832b2aa

Rewrite OAuth specs

Showing 2 changed files with 56 additions and 88 deletions   Show diff stats
spec/lib/auth_spec.rb
@@ -3,102 +3,26 @@ require 'spec_helper' @@ -3,102 +3,26 @@ require 'spec_helper'
3 describe Gitlab::Auth do 3 describe Gitlab::Auth do
4 let(:gl_auth) { Gitlab::Auth.new } 4 let(:gl_auth) { Gitlab::Auth.new }
5 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 6 + describe :find do
17 before do 7 before do
18 - @auth = mock(  
19 - uid: '12djsak321',  
20 - info: @info,  
21 - provider: 'ldap' 8 + @user = create(
  9 + :user,
  10 + username: 'john',
  11 + password: '888777',
  12 + password_confirmation: '888777'
22 ) 13 )
23 end 14 end
24 15
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 -  
39 - it "should create from auth if user does not exist"do  
40 - User.stub find_by_extern_uid_and_provider: nil  
41 - User.stub find_by_email: nil  
42 - gl_auth.should_receive :create_from_omniauth  
43 - gl_auth.find_for_ldap_auth(@auth)  
44 - end  
45 - end  
46 -  
47 - describe :find_or_new_for_omniauth do  
48 - before do  
49 - @auth = mock(  
50 - info: @info,  
51 - provider: 'twitter',  
52 - uid: '12djsak321',  
53 - ) 16 + it "should find user by valid login/password" do
  17 + gl_auth.find('john', '888777').should == @user
54 end 18 end
55 19
56 - it "should find user"do  
57 - User.should_receive :find_by_provider_and_extern_uid  
58 - gl_auth.should_not_receive :create_from_omniauth  
59 - gl_auth.find_or_new_for_omniauth(@auth) 20 + it "should not find user with invalid password" do
  21 + gl_auth.find('john', 'invalid').should_not == @user
60 end 22 end
61 23
62 - it "should not create user"do  
63 - User.stub find_by_provider_and_extern_uid: nil  
64 - gl_auth.should_not_receive :create_from_omniauth  
65 - gl_auth.find_or_new_for_omniauth(@auth)  
66 - end  
67 -  
68 - it "should create user if single_sing_on"do  
69 - Gitlab.config.omniauth['allow_single_sign_on'] = true  
70 - User.stub find_by_provider_and_extern_uid: nil  
71 - gl_auth.should_receive :create_from_omniauth  
72 - gl_auth.find_or_new_for_omniauth(@auth)  
73 - end  
74 - end  
75 -  
76 - describe :create_from_omniauth do  
77 - it "should create user from LDAP" do  
78 - @auth = mock(info: @info, provider: 'ldap')  
79 - user = gl_auth.create_from_omniauth(@auth, true)  
80 -  
81 - user.should be_valid  
82 - user.extern_uid.should == @info.uid  
83 - user.provider.should == 'ldap'  
84 - end  
85 -  
86 - it "should create user from Omniauth" do  
87 - @auth = mock(info: @info, provider: 'twitter')  
88 - user = gl_auth.create_from_omniauth(@auth, false)  
89 -  
90 - user.should be_valid  
91 - user.extern_uid.should == @info.uid  
92 - user.provider.should == 'twitter'  
93 - end  
94 -  
95 - it "should apply defaults to user" do  
96 - @auth = mock(info: @info, provider: 'ldap')  
97 - user = gl_auth.create_from_omniauth(@auth, true)  
98 -  
99 - user.should be_valid  
100 - user.projects_limit.should == Gitlab.config.gitlab.default_projects_limit  
101 - user.can_create_group.should == Gitlab.config.gitlab.default_can_create_group 24 + it "should not find user with invalid login and password" do
  25 + gl_auth.find('jon', 'invalid').should_not == @user
102 end 26 end
103 end 27 end
104 end 28 end
spec/lib/oauth_spec.rb 0 → 100644
@@ -0,0 +1,44 @@ @@ -0,0 +1,44 @@
  1 +require 'spec_helper'
  2 +
  3 +describe Gitlab::OAuth::User do
  4 + let(:gl_auth) { Gitlab::OAuth::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 :create do
  17 + it "should create user from LDAP" do
  18 + @auth = mock(info: @info, provider: 'ldap')
  19 + user = gl_auth.create(@auth)
  20 +
  21 + user.should be_valid
  22 + user.extern_uid.should == @info.uid
  23 + user.provider.should == 'ldap'
  24 + end
  25 +
  26 + it "should create user from Omniauth" do
  27 + @auth = mock(info: @info, provider: 'twitter')
  28 + user = gl_auth.create(@auth)
  29 +
  30 + user.should be_valid
  31 + user.extern_uid.should == @info.uid
  32 + user.provider.should == 'twitter'
  33 + end
  34 +
  35 + it "should apply defaults to user" do
  36 + @auth = mock(info: @info, provider: 'ldap')
  37 + user = gl_auth.create(@auth)
  38 +
  39 + user.should be_valid
  40 + user.projects_limit.should == Gitlab.config.gitlab.default_projects_limit
  41 + user.can_create_group.should == Gitlab.config.gitlab.default_can_create_group
  42 + end
  43 + end
  44 +end