Commit 85def2d62500afdab39956f0bd987340889894c4
Exists in
master
and in
4 other branches
Merge pull request #1451 from tsigo/omniauth_settings
Be more resilient in the case of missing omniauth settings
Showing
3 changed files
with
10 additions
and
8 deletions
Show diff stats
config/initializers/1_settings.rb
... | ... | @@ -121,19 +121,19 @@ class Settings < Settingslogic |
121 | 121 | end |
122 | 122 | |
123 | 123 | def ldap_enabled? |
124 | - ldap['enabled'] | |
125 | - rescue | |
124 | + ldap && ldap['enabled'] | |
125 | + rescue Settingslogic::MissingSetting | |
126 | 126 | false |
127 | 127 | end |
128 | 128 | |
129 | 129 | def omniauth_enabled? |
130 | 130 | omniauth && omniauth['enabled'] |
131 | - rescue | |
131 | + rescue Settingslogic::MissingSetting | |
132 | 132 | false |
133 | 133 | end |
134 | 134 | |
135 | 135 | def omniauth_providers |
136 | - omniauth['providers'] || [] | |
136 | + (omniauth_enabled? && omniauth['providers']) || [] | |
137 | 137 | end |
138 | 138 | |
139 | 139 | def disable_gravatar? | ... | ... |
lib/gitlab/auth.rb
... | ... | @@ -17,7 +17,7 @@ module Gitlab |
17 | 17 | end |
18 | 18 | end |
19 | 19 | |
20 | - def create_from_omniauth auth, ldap = false | |
20 | + def create_from_omniauth(auth, ldap = false) | |
21 | 21 | provider = auth.provider |
22 | 22 | uid = auth.info.uid || auth.uid |
23 | 23 | name = auth.info.name.force_encoding("utf-8") |
... | ... | @@ -39,7 +39,7 @@ module Gitlab |
39 | 39 | password_confirmation: password, |
40 | 40 | projects_limit: Gitlab.config.default_projects_limit, |
41 | 41 | ) |
42 | - if Gitlab.config.omniauth.block_auto_created_users && !ldap | |
42 | + if Gitlab.config.omniauth['block_auto_created_users'] && !ldap | |
43 | 43 | @user.blocked = true |
44 | 44 | end |
45 | 45 | @user.save! |
... | ... | @@ -52,7 +52,7 @@ module Gitlab |
52 | 52 | if @user = User.find_by_provider_and_extern_uid(provider, uid) |
53 | 53 | @user |
54 | 54 | else |
55 | - if Gitlab.config.omniauth.allow_single_sign_on | |
55 | + if Gitlab.config.omniauth['allow_single_sign_on'] | |
56 | 56 | @user = create_from_omniauth(auth) |
57 | 57 | @user |
58 | 58 | end | ... | ... |
spec/lib/auth_spec.rb
... | ... | @@ -4,6 +4,8 @@ describe Gitlab::Auth do |
4 | 4 | let(:gl_auth) { Gitlab::Auth.new } |
5 | 5 | |
6 | 6 | before do |
7 | + Gitlab.config.stub(omniauth: {}) | |
8 | + | |
7 | 9 | @info = mock( |
8 | 10 | uid: '12djsak321', |
9 | 11 | name: 'John', |
... | ... | @@ -64,7 +66,7 @@ describe Gitlab::Auth do |
64 | 66 | end |
65 | 67 | |
66 | 68 | it "should create user if single_sing_on"do |
67 | - Gitlab.config.omniauth.stub allow_single_sign_on: true | |
69 | + Gitlab.config.omniauth['allow_single_sign_on'] = true | |
68 | 70 | User.stub find_by_provider_and_extern_uid: nil |
69 | 71 | gl_auth.should_receive :create_from_omniauth |
70 | 72 | gl_auth.find_or_new_for_omniauth(@auth) | ... | ... |