devise_ldap_authenticatable 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -2,7 +2,7 @@ source "http://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'devise', '~> 1.5.0'
5
+ gem 'devise', '~> 2.0.0'
6
6
  gem 'net-ldap', '~> 0.2.2'
7
7
 
8
8
  platforms :mri_18 do
data/Gemfile.lock ADDED
@@ -0,0 +1,38 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ devise_ldap_authenticatable (0.5.1)
5
+ devise (~> 1.5.0)
6
+ net-ldap (~> 0.2.2)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ bcrypt-ruby (3.0.1)
12
+ columnize (0.3.6)
13
+ devise (1.5.3)
14
+ bcrypt-ruby (~> 3.0)
15
+ orm_adapter (~> 0.0.3)
16
+ warden (~> 1.1)
17
+ linecache (0.46)
18
+ rbx-require-relative (> 0.0.4)
19
+ net-ldap (0.2.2)
20
+ orm_adapter (0.0.6)
21
+ rack (1.4.0)
22
+ rbx-require-relative (0.0.5)
23
+ ruby-debug (0.10.4)
24
+ columnize (>= 0.1)
25
+ ruby-debug-base (~> 0.10.4.0)
26
+ ruby-debug-base (0.10.4)
27
+ linecache (>= 0.3)
28
+ warden (1.1.0)
29
+ rack (>= 1.0)
30
+
31
+ PLATFORMS
32
+ ruby
33
+
34
+ DEPENDENCIES
35
+ devise (~> 1.5.0)
36
+ devise_ldap_authenticatable!
37
+ net-ldap (~> 0.2.2)
38
+ ruby-debug (>= 0.10.3)
@@ -17,6 +17,6 @@ Gem::Specification.new do |s|
17
17
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
18
  s.require_paths = ["lib"]
19
19
 
20
- s.add_dependency('devise', '~> 1.5.0')
20
+ s.add_dependency('devise', '>= 2.0.0')
21
21
  s.add_dependency('net-ldap', '~> 0.2.2')
22
22
  end
@@ -21,7 +21,7 @@ module Devise
21
21
  @login_with ||= Devise.mappings[self.class.to_s.underscore.to_sym].to.authentication_keys.first
22
22
  self[@login_with]
23
23
  end
24
-
24
+
25
25
  def reset_password!(new_password, new_password_confirmation)
26
26
  if new_password == new_password_confirmation && ::Devise.ldap_update_password
27
27
  Devise::LdapAdapter.update_password(login_with, new_password)
@@ -42,11 +42,11 @@ module Devise
42
42
  return false
43
43
  end
44
44
  end
45
-
45
+
46
46
  def ldap_groups
47
47
  Devise::LdapAdapter.get_groups(login_with)
48
48
  end
49
-
49
+
50
50
  def ldap_dn
51
51
  Devise::LdapAdapter.get_dn(login_with)
52
52
  end
@@ -67,34 +67,36 @@ module Devise
67
67
  module ClassMethods
68
68
  # Authenticate a user based on configured attribute keys. Returns the
69
69
  # authenticated user if it's valid or nil.
70
- def authenticate_with_ldap(attributes={})
70
+ def authenticate_with_ldap(attributes={})
71
71
  auth_key = self.authentication_keys.first
72
- return nil unless attributes[auth_key].present?
72
+ return nil unless attributes[auth_key].present?
73
+
74
+ auth_key_value = (self.case_insensitive_keys || []).include?(auth_key) ? attributes[auth_key].downcase : attributes[auth_key]
73
75
 
74
76
  # resource = find_for_ldap_authentication(conditions)
75
- resource = where(auth_key => attributes[auth_key]).first
76
-
77
+ resource = where(auth_key => auth_key_value).first
78
+
77
79
  if (resource.blank? and ::Devise.ldap_create_user)
78
80
  resource = new
79
- resource[auth_key] = attributes[auth_key]
81
+ resource[auth_key] = auth_key_value
80
82
  resource.password = attributes[:password]
81
83
  end
82
-
84
+
83
85
  if resource.try(:valid_ldap_authentication?, attributes[:password])
84
86
  if resource.new_record?
85
87
  resource.ldap_before_save if resource.respond_to?(:ldap_before_save)
86
- resource.save
88
+ resource.save
87
89
  end
88
90
  return resource
89
91
  else
90
92
  return nil
91
93
  end
92
94
  end
93
-
95
+
94
96
  def update_with_password(resource)
95
97
  puts "UPDATE_WITH_PASSWORD: #{resource.inspect}"
96
98
  end
97
-
99
+
98
100
  end
99
101
  end
100
102
  end
@@ -1,3 +1,3 @@
1
1
  module DeviseLdapAuthenticatable
2
- VERSION = "0.5.1".freeze
2
+ VERSION = "0.6.0".freeze
3
3
  end
@@ -3,7 +3,7 @@ source 'http://rubygems.org'
3
3
  gem 'rails', '3.0.0'
4
4
  gem 'sqlite3-ruby', :require => 'sqlite3'
5
5
 
6
- gem "devise", "~> 1.4.0"
6
+ gem "devise", "~> 1.5.0"
7
7
  gem "devise_ldap_authenticatable", :path => "../../"
8
8
 
9
9
  group :test do
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: ../../
3
3
  specs:
4
- devise_ldap_authenticatable (0.4.9)
5
- devise (~> 1.4.0)
4
+ devise_ldap_authenticatable (0.5.1)
5
+ devise (~> 1.5.0)
6
6
  net-ldap (~> 0.2.2)
7
7
 
8
8
  GEM
@@ -64,10 +64,10 @@ GEM
64
64
  cucumber (>= 0.8.0)
65
65
  culerity (0.2.12)
66
66
  database_cleaner (0.5.2)
67
- devise (1.4.7)
67
+ devise (1.5.3)
68
68
  bcrypt-ruby (~> 3.0)
69
69
  orm_adapter (~> 0.0.3)
70
- warden (~> 1.0.3)
70
+ warden (~> 1.1)
71
71
  diff-lcs (1.1.2)
72
72
  erubis (2.6.6)
73
73
  abstract (>= 1.0.0)
@@ -94,7 +94,7 @@ GEM
94
94
  rake
95
95
  net-ldap (0.2.2)
96
96
  nokogiri (1.4.3.1)
97
- orm_adapter (0.0.5)
97
+ orm_adapter (0.0.6)
98
98
  polyglot (0.3.1)
99
99
  rack (1.2.1)
100
100
  rack-mount (0.6.12)
@@ -134,7 +134,7 @@ GEM
134
134
  polyglot (>= 0.3.1)
135
135
  trollop (1.16.2)
136
136
  tzinfo (0.3.23)
137
- warden (1.0.5)
137
+ warden (1.1.0)
138
138
  rack (>= 1.0)
139
139
 
140
140
  PLATFORMS
@@ -147,7 +147,7 @@ DEPENDENCIES
147
147
  capybara
148
148
  cucumber-rails
149
149
  database_cleaner
150
- devise (~> 1.4.0)
150
+ devise (~> 1.5.0)
151
151
  devise_ldap_authenticatable!
152
152
  factory_girl_rails
153
153
  launchy
@@ -5,7 +5,7 @@ class UserTest < ActiveSupport::TestCase
5
5
  def should_be_validated(user, password, message = "Password is invalid")
6
6
  assert(user.valid_ldap_authentication?(password), message)
7
7
  end
8
-
8
+
9
9
  def should_not_be_validated(user, password, message = "Password is not properly set")
10
10
  assert(!user.valid_ldap_authentication?(password), message)
11
11
  end
@@ -25,12 +25,12 @@ class UserTest < ActiveSupport::TestCase
25
25
  assert_equal false, ::Devise::LdapAdapter.valid_login?('barneystinson')
26
26
  end
27
27
  end
28
-
28
+
29
29
  context "create a basic user" do
30
30
  setup do
31
31
  @user = Factory(:user)
32
32
  end
33
-
33
+
34
34
  should "check for password validation" do
35
35
  assert_equal(@user.email, "example.user@test.com")
36
36
  should_be_validated @user, "secret"
@@ -38,18 +38,18 @@ class UserTest < ActiveSupport::TestCase
38
38
  should_not_be_validated @user, "Secret"
39
39
  end
40
40
  end
41
-
41
+
42
42
  context "change a LDAP password" do
43
43
  setup do
44
44
  @user = Factory(:user)
45
45
  end
46
-
46
+
47
47
  should "change password" do
48
48
  should_be_validated @user, "secret"
49
49
  @user.reset_password!("changed","changed")
50
50
  should_be_validated @user, "changed", "password was not changed properly on the LDAP sevrer"
51
51
  end
52
-
52
+
53
53
  should "not allow to change password if setting is false" do
54
54
  should_be_validated @user, "secret"
55
55
  ::Devise.ldap_update_password = false
@@ -58,42 +58,67 @@ class UserTest < ActiveSupport::TestCase
58
58
  should_be_validated @user, "secret"
59
59
  end
60
60
  end
61
-
61
+
62
62
  context "create new local user if user is in LDAP" do
63
-
63
+
64
64
  setup do
65
65
  assert(User.all.blank?, "There shouldn't be any users in the database")
66
66
  end
67
-
67
+
68
68
  should "don't create user in the database" do
69
69
  @user = User.authenticate_with_ldap(:email => "example.user@test.com", :password => "secret")
70
70
  assert(User.all.blank?)
71
71
  end
72
-
72
+
73
73
  context "creating users is enabled" do
74
74
  setup do
75
75
  ::Devise.ldap_create_user = true
76
76
  end
77
-
77
+
78
78
  should "create a user in the database" do
79
79
  @user = User.authenticate_with_ldap(:email => "example.user@test.com", :password => "secret")
80
80
  assert_equal(User.all.size, 1)
81
81
  assert_contains(User.all.collect(&:email), "example.user@test.com", "user not in database")
82
82
  end
83
-
83
+
84
84
  should "not create a user in the database if the password is wrong_secret" do
85
85
  @user = User.authenticate_with_ldap(:email => "example.user", :password => "wrong_secret")
86
86
  assert(User.all.blank?, "There's users in the database")
87
87
  end
88
-
88
+
89
89
  should "create a user if the user is not in LDAP" do
90
90
  @user = User.authenticate_with_ldap(:email => "wrong_secret.user@test.com", :password => "wrong_secret")
91
91
  assert(User.all.blank?, "There's users in the database")
92
92
  end
93
+
94
+ should "create a user in the database if case insensitivity does not matter" do
95
+ ::Devise.case_insensitive_keys = false
96
+ @user = Factory(:user)
97
+
98
+ assert_difference "User.count", +1 do
99
+ User.authenticate_with_ldap(:email => "EXAMPLE.user@test.com", :password => "secret")
100
+ end
101
+ end
102
+
103
+ should "not create a user in the database if case insensitivity matters" do
104
+ ::Devise.case_insensitive_keys = [:email]
105
+ @user = Factory(:user)
106
+
107
+ assert_no_difference "User.count" do
108
+ User.authenticate_with_ldap(:email => "EXAMPLE.user@test.com", :password => "secret")
109
+ end
110
+ end
111
+
112
+ should "create a user with downcased email in the database if case insensitivity matters" do
113
+ ::Devise.case_insensitive_keys = [:email]
114
+
115
+ @user = User.authenticate_with_ldap(:email => "EXAMPLE.user@test.com", :password => "secret")
116
+ assert_contains(User.all.collect(&:email), "example.user@test.com", "user not in database")
117
+ end
93
118
  end
94
-
119
+
95
120
  end
96
-
121
+
97
122
  context "use groups for authorization" do
98
123
  setup do
99
124
  @admin = Factory(:admin)
@@ -101,55 +126,55 @@ class UserTest < ActiveSupport::TestCase
101
126
  ::Devise.authentication_keys = [:email]
102
127
  ::Devise.ldap_check_group_membership = true
103
128
  end
104
-
129
+
105
130
  should "admin should be allowed in" do
106
131
  should_be_validated @admin, "admin_secret"
107
132
  end
108
-
133
+
109
134
  should "admin should have the proper groups set" do
110
135
  assert_contains(@admin.ldap_groups, /cn=admins/, "groups attribute not being set properly")
111
136
  end
112
-
137
+
113
138
  should "user should not be allowed in" do
114
139
  should_not_be_validated @user, "secret"
115
140
  end
116
-
141
+
117
142
  should "not be validated if group with different attribute is removed" do
118
143
  `ldapmodify #{ldap_connect_string} -f ../ldap/delete_authorization_role.ldif`
119
144
  should_not_be_validated @admin, "admin_secret"
120
145
  end
121
146
  end
122
-
147
+
123
148
  context "use role attribute for authorization" do
124
149
  setup do
125
150
  @admin = Factory(:admin)
126
151
  @user = Factory(:user)
127
152
  ::Devise.ldap_check_attributes = true
128
153
  end
129
-
154
+
130
155
  should "admin should be allowed in" do
131
156
  should_be_validated @admin, "admin_secret"
132
157
  end
133
-
158
+
134
159
  should "user should not be allowed in" do
135
160
  should_not_be_validated @user, "secret"
136
161
  end
137
162
  end
138
-
163
+
139
164
  context "use admin setting to bind" do
140
165
  setup do
141
166
  @admin = Factory(:admin)
142
167
  @user = Factory(:user)
143
168
  ::Devise.ldap_use_admin_to_bind = true
144
169
  end
145
-
170
+
146
171
  should "description" do
147
172
  should_be_validated @admin, "admin_secret"
148
173
  end
149
174
  end
150
-
175
+
151
176
  end
152
-
177
+
153
178
  context "use uid for login" do
154
179
  setup do
155
180
  default_devise_settings!
@@ -157,24 +182,24 @@ class UserTest < ActiveSupport::TestCase
157
182
  ::Devise.ldap_config = "#{Rails.root}/config/#{"ssl_" if ENV["LDAP_SSL"]}ldap_with_uid.yml"
158
183
  ::Devise.authentication_keys = [:uid]
159
184
  end
160
-
185
+
161
186
  context "description" do
162
187
  setup do
163
188
  @admin = Factory(:admin)
164
189
  @user = Factory(:user, :uid => "example_user")
165
190
  end
166
-
191
+
167
192
  should "be able to authenticate using uid" do
168
193
  should_be_validated @user, "secret"
169
194
  should_not_be_validated @admin, "admin_secret"
170
195
  end
171
196
  end
172
-
197
+
173
198
  context "create user" do
174
199
  setup do
175
200
  ::Devise.ldap_create_user = true
176
201
  end
177
-
202
+
178
203
  should "create a user in the database" do
179
204
  @user = User.authenticate_with_ldap(:uid => "example_user", :password => "secret")
180
205
  assert_equal(User.all.size, 1)
@@ -199,22 +224,22 @@ class UserTest < ActiveSupport::TestCase
199
224
  should_be_validated Factory(:user, :uid => "example_user"), "secret"
200
225
  end
201
226
  end
202
- end
227
+ end
203
228
  end
204
-
229
+
205
230
  context "using ERB in the config file" do
206
231
  setup do
207
232
  default_devise_settings!
208
233
  reset_ldap_server!
209
234
  ::Devise.ldap_config = "#{Rails.root}/config/#{"ssl_" if ENV["LDAP_SSL"]}ldap_with_erb.yml"
210
235
  end
211
-
236
+
212
237
  context "authenticate" do
213
238
  setup do
214
239
  @admin = Factory(:admin)
215
240
  @user = Factory(:user)
216
241
  end
217
-
242
+
218
243
  should "be able to authenticate" do
219
244
  should_be_validated @user, "secret"
220
245
  should_be_validated @admin, "admin_secret"
@@ -235,7 +260,7 @@ class UserTest < ActiveSupport::TestCase
235
260
  end
236
261
  end
237
262
  end
238
-
263
+
239
264
  context "use username builder" do
240
265
  setup do
241
266
  default_devise_settings!
@@ -250,5 +275,5 @@ class UserTest < ActiveSupport::TestCase
250
275
  should_be_validated @other, "other_secret"
251
276
  end
252
277
  end
253
-
278
+
254
279
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devise_ldap_authenticatable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,22 +11,22 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2011-12-09 00:00:00.000000000Z
14
+ date: 2012-02-07 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: devise
18
- requirement: &70110522209540 !ruby/object:Gem::Requirement
18
+ requirement: &21244260 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
- - - ~>
21
+ - - ! '>='
22
22
  - !ruby/object:Gem::Version
23
- version: 1.5.0
23
+ version: 2.0.0
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *70110522209540
26
+ version_requirements: *21244260
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: net-ldap
29
- requirement: &70110522208060 !ruby/object:Gem::Requirement
29
+ requirement: &21243760 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ~>
@@ -34,7 +34,7 @@ dependencies:
34
34
  version: 0.2.2
35
35
  type: :runtime
36
36
  prerelease: false
37
- version_requirements: *70110522208060
37
+ version_requirements: *21243760
38
38
  description: Devise extension to allow authentication via LDAP
39
39
  email: curtis.schiewek@gmail.com
40
40
  executables: []
@@ -43,6 +43,7 @@ extra_rdoc_files: []
43
43
  files:
44
44
  - .gitignore
45
45
  - Gemfile
46
+ - Gemfile.lock
46
47
  - MIT-LICENSE
47
48
  - README.md
48
49
  - Rakefile
@@ -156,85 +157,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
157
  version: '0'
157
158
  requirements: []
158
159
  rubyforge_project:
159
- rubygems_version: 1.8.10
160
+ rubygems_version: 1.8.11
160
161
  signing_key:
161
162
  specification_version: 3
162
163
  summary: Devise extension to allow authentication via LDAP
163
- test_files:
164
- - test/devise_ldap_authenticatable_test.rb
165
- - test/ldap/base.ldif
166
- - test/ldap/clear.ldif
167
- - test/ldap/local.schema
168
- - test/ldap/openldap-data/run/.gitkeep
169
- - test/ldap/run-server.sh
170
- - test/ldap/server.pem
171
- - test/ldap/slapd-ssl-test.conf
172
- - test/ldap/slapd-test.conf
173
- - test/rails_app/Gemfile
174
- - test/rails_app/Gemfile.lock
175
- - test/rails_app/Rakefile
176
- - test/rails_app/app/controllers/application_controller.rb
177
- - test/rails_app/app/controllers/posts_controller.rb
178
- - test/rails_app/app/helpers/application_helper.rb
179
- - test/rails_app/app/helpers/posts_helper.rb
180
- - test/rails_app/app/models/post.rb
181
- - test/rails_app/app/models/user.rb
182
- - test/rails_app/app/views/layouts/application.html.erb
183
- - test/rails_app/app/views/posts/index.html.erb
184
- - test/rails_app/config.ru
185
- - test/rails_app/config/application.rb
186
- - test/rails_app/config/boot.rb
187
- - test/rails_app/config/cucumber.yml
188
- - test/rails_app/config/database.yml
189
- - test/rails_app/config/environment.rb
190
- - test/rails_app/config/environments/development.rb
191
- - test/rails_app/config/environments/production.rb
192
- - test/rails_app/config/environments/test.rb
193
- - test/rails_app/config/initializers/backtrace_silencers.rb
194
- - test/rails_app/config/initializers/devise.rb
195
- - test/rails_app/config/initializers/inflections.rb
196
- - test/rails_app/config/initializers/mime_types.rb
197
- - test/rails_app/config/initializers/secret_token.rb
198
- - test/rails_app/config/initializers/session_store.rb
199
- - test/rails_app/config/ldap.yml
200
- - test/rails_app/config/ldap_with_boolean_ssl.yml
201
- - test/rails_app/config/ldap_with_erb.yml
202
- - test/rails_app/config/ldap_with_uid.yml
203
- - test/rails_app/config/locales/devise.en.yml
204
- - test/rails_app/config/locales/en.yml
205
- - test/rails_app/config/routes.rb
206
- - test/rails_app/config/ssl_ldap.yml
207
- - test/rails_app/config/ssl_ldap_with_erb.yml
208
- - test/rails_app/config/ssl_ldap_with_uid.yml
209
- - test/rails_app/db/migrate/20100708120302_create_posts.rb
210
- - test/rails_app/db/migrate/20100708120448_devise_create_users.rb
211
- - test/rails_app/db/schema.rb
212
- - test/rails_app/db/seeds.rb
213
- - test/rails_app/features/manage_logins.feature
214
- - test/rails_app/features/step_definitions/login_steps.rb
215
- - test/rails_app/features/step_definitions/web_steps.rb
216
- - test/rails_app/features/support/env.rb
217
- - test/rails_app/features/support/paths.rb
218
- - test/rails_app/lib/tasks/.gitkeep
219
- - test/rails_app/lib/tasks/cucumber.rake
220
- - test/rails_app/public/404.html
221
- - test/rails_app/public/422.html
222
- - test/rails_app/public/500.html
223
- - test/rails_app/public/images/rails.png
224
- - test/rails_app/public/javascripts/application.js
225
- - test/rails_app/public/javascripts/controls.js
226
- - test/rails_app/public/javascripts/dragdrop.js
227
- - test/rails_app/public/javascripts/effects.js
228
- - test/rails_app/public/javascripts/prototype.js
229
- - test/rails_app/public/javascripts/rails.js
230
- - test/rails_app/public/stylesheets/.gitkeep
231
- - test/rails_app/script/cucumber
232
- - test/rails_app/script/rails
233
- - test/rails_app/test/factories/users.rb
234
- - test/rails_app/test/functional/posts_controller_test.rb
235
- - test/rails_app/test/performance/browsing_test.rb
236
- - test/rails_app/test/test_helper.rb
237
- - test/rails_app/test/unit/helpers/posts_helper_test.rb
238
- - test/rails_app/test/unit/post_test.rb
239
- - test/rails_app/test/unit/user_test.rb
240
- - test/test_helper.rb
164
+ test_files: []