devise_ldap_authenticatable 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.md +7 -0
  4. data/Gemfile +1 -4
  5. data/README.md +45 -92
  6. data/Rakefile +8 -7
  7. data/devise_ldap_authenticatable.gemspec +15 -3
  8. data/lib/devise_ldap_authenticatable/ldap_adapter.rb +51 -27
  9. data/lib/devise_ldap_authenticatable/model.rb +5 -1
  10. data/lib/devise_ldap_authenticatable/strategy.rb +3 -1
  11. data/lib/devise_ldap_authenticatable/version.rb +1 -1
  12. data/lib/generators/devise_ldap_authenticatable/templates/ldap.yml +3 -3
  13. data/spec/ldap/.gitignore +2 -0
  14. data/{test → spec}/ldap/base.ldif +0 -0
  15. data/{test → spec}/ldap/clear.ldif +0 -0
  16. data/{test → spec}/ldap/local.schema +0 -0
  17. data/spec/ldap/openldap-data/.gitignore +2 -0
  18. data/spec/ldap/openldap-data/run/.gitignore +2 -0
  19. data/{test → spec}/ldap/openldap-data/run/.gitkeep +0 -0
  20. data/spec/ldap/run-server +31 -0
  21. data/{test → spec}/ldap/server.pem +0 -0
  22. data/{test/ldap/slapd-test.conf → spec/ldap/slapd-test.conf.erb} +16 -16
  23. data/{test → spec}/rails_app/Rakefile +0 -0
  24. data/spec/rails_app/app/controllers/application_controller.rb +7 -0
  25. data/{test → spec}/rails_app/app/controllers/posts_controller.rb +0 -0
  26. data/{test → spec}/rails_app/app/helpers/application_helper.rb +0 -0
  27. data/{test → spec}/rails_app/app/helpers/posts_helper.rb +0 -0
  28. data/{test → spec}/rails_app/app/models/post.rb +0 -0
  29. data/{test → spec}/rails_app/app/models/user.rb +0 -0
  30. data/{test → spec}/rails_app/app/views/layouts/application.html.erb +0 -0
  31. data/{test → spec}/rails_app/app/views/posts/index.html.erb +0 -0
  32. data/{test → spec}/rails_app/config.ru +0 -0
  33. data/{test → spec}/rails_app/config/application.rb +0 -0
  34. data/{test → spec}/rails_app/config/boot.rb +1 -1
  35. data/{test → spec}/rails_app/config/cucumber.yml +0 -0
  36. data/{test → spec}/rails_app/config/database.yml +0 -0
  37. data/{test → spec}/rails_app/config/environment.rb +0 -0
  38. data/{test → spec}/rails_app/config/environments/development.rb +0 -1
  39. data/{test → spec}/rails_app/config/environments/production.rb +0 -0
  40. data/{test → spec}/rails_app/config/environments/test.rb +1 -1
  41. data/{test → spec}/rails_app/config/initializers/backtrace_silencers.rb +0 -0
  42. data/spec/rails_app/config/initializers/devise.rb +242 -0
  43. data/{test → spec}/rails_app/config/initializers/inflections.rb +0 -0
  44. data/{test → spec}/rails_app/config/initializers/mime_types.rb +0 -0
  45. data/{test → spec}/rails_app/config/initializers/secret_token.rb +0 -0
  46. data/{test → spec}/rails_app/config/initializers/session_store.rb +0 -0
  47. data/{test → spec}/rails_app/config/ldap.yml +0 -0
  48. data/{test → spec}/rails_app/config/ldap_with_boolean_ssl.yml +0 -0
  49. data/{test → spec}/rails_app/config/ldap_with_erb.yml +0 -0
  50. data/{test → spec}/rails_app/config/ldap_with_uid.yml +0 -0
  51. data/spec/rails_app/config/locales/devise.en.yml +58 -0
  52. data/{test → spec}/rails_app/config/locales/en.yml +0 -0
  53. data/{test → spec}/rails_app/config/routes.rb +0 -0
  54. data/{test → spec}/rails_app/config/ssl_ldap.yml +0 -0
  55. data/{test → spec}/rails_app/config/ssl_ldap_with_erb.yml +0 -0
  56. data/{test → spec}/rails_app/config/ssl_ldap_with_uid.yml +0 -0
  57. data/{test → spec}/rails_app/db/migrate/20100708120448_devise_create_users.rb +18 -4
  58. data/{test → spec}/rails_app/db/schema.rb +6 -13
  59. data/{test → spec}/rails_app/features/manage_logins.feature +0 -0
  60. data/{test → spec}/rails_app/features/step_definitions/login_steps.rb +0 -0
  61. data/{test → spec}/rails_app/features/step_definitions/web_steps.rb +0 -0
  62. data/{test → spec}/rails_app/features/support/env.rb +0 -0
  63. data/{test → spec}/rails_app/features/support/paths.rb +0 -0
  64. data/{test → spec}/rails_app/lib/tasks/.gitkeep +0 -0
  65. data/{test → spec}/rails_app/lib/tasks/cucumber.rake +0 -0
  66. data/{test → spec}/rails_app/public/404.html +0 -0
  67. data/{test → spec}/rails_app/public/422.html +0 -0
  68. data/{test → spec}/rails_app/public/500.html +0 -0
  69. data/{test → spec}/rails_app/public/images/rails.png +0 -0
  70. data/{test → spec}/rails_app/public/javascripts/application.js +0 -0
  71. data/{test → spec}/rails_app/public/javascripts/controls.js +0 -0
  72. data/{test → spec}/rails_app/public/javascripts/dragdrop.js +0 -0
  73. data/{test → spec}/rails_app/public/javascripts/effects.js +0 -0
  74. data/{test → spec}/rails_app/public/javascripts/prototype.js +0 -0
  75. data/{test → spec}/rails_app/public/javascripts/rails.js +0 -0
  76. data/{test → spec}/rails_app/public/stylesheets/.gitkeep +0 -0
  77. data/{test → spec}/rails_app/script/cucumber +0 -0
  78. data/{test → spec}/rails_app/script/rails +0 -0
  79. data/spec/spec_helper.rb +47 -0
  80. data/spec/support/factories.rb +16 -0
  81. data/spec/unit/user_spec.rb +303 -0
  82. metadata +292 -179
  83. data/Gemfile.lock +0 -92
  84. data/rails/init.rb +0 -2
  85. data/test/devise_ldap_authenticatable_test.rb +0 -8
  86. data/test/ldap/run-server.sh +0 -10
  87. data/test/ldap/slapd-ssl-test.conf +0 -107
  88. data/test/rails_app/Gemfile +0 -22
  89. data/test/rails_app/Gemfile.lock +0 -159
  90. data/test/rails_app/app/controllers/application_controller.rb +0 -4
  91. data/test/rails_app/config/initializers/devise.rb +0 -140
  92. data/test/rails_app/config/ldap_with_check_membership_off.yml +0 -23
  93. data/test/rails_app/config/ldap_with_check_membership_on.yml +0 -23
  94. data/test/rails_app/config/locales/devise.en.yml +0 -39
  95. data/test/rails_app/db/migrate/20100708120302_create_posts.rb +0 -14
  96. data/test/rails_app/db/seeds.rb +0 -7
  97. data/test/rails_app/test/factories/users.rb +0 -14
  98. data/test/rails_app/test/functional/posts_controller_test.rb +0 -58
  99. data/test/rails_app/test/performance/browsing_test.rb +0 -9
  100. data/test/rails_app/test/test_helper.rb +0 -36
  101. data/test/rails_app/test/unit/helpers/posts_helper_test.rb +0 -4
  102. data/test/rails_app/test/unit/post_test.rb +0 -4
  103. data/test/rails_app/test/unit/user_test.rb +0 -314
  104. data/test/test_helper.rb +0 -3
@@ -1,23 +0,0 @@
1
- authorizations: &AUTHORIZATIONS
2
- ## Authorization
3
- group_base: ou=groups,dc=test,dc=com
4
- check_group_membership: false
5
- required_groups:
6
- - cn=admins,ou=groups,dc=test,dc=com
7
- - ["authorizationRole", "cn=users,ou=groups,dc=test,dc=com"]
8
- require_attribute:
9
- objectClass: inetOrgPerson
10
- authorizationRole: blogAdmin
11
-
12
- test: &TEST
13
- host: localhost
14
- port: 3389
15
- attribute: cn
16
- base: ou=people,dc=test,dc=com
17
- admin_user: cn=admin,dc=test,dc=com
18
- admin_password: secret
19
- ssl: false
20
- <<: *AUTHORIZATIONS
21
-
22
- development:
23
- <<: *TEST
@@ -1,23 +0,0 @@
1
- authorizations: &AUTHORIZATIONS
2
- ## Authorization
3
- group_base: ou=groups,dc=test,dc=com
4
- check_group_membership: true
5
- required_groups:
6
- - cn=admins,ou=groups,dc=test,dc=com
7
- - ["authorizationRole", "cn=users,ou=groups,dc=test,dc=com"]
8
- require_attribute:
9
- objectClass: inetOrgPerson
10
- authorizationRole: blogAdmin
11
-
12
- test: &TEST
13
- host: localhost
14
- port: 3389
15
- attribute: cn
16
- base: ou=people,dc=test,dc=com
17
- admin_user: cn=admin,dc=test,dc=com
18
- admin_password: secret
19
- ssl: false
20
- <<: *AUTHORIZATIONS
21
-
22
- development:
23
- <<: *TEST
@@ -1,39 +0,0 @@
1
- en:
2
- errors:
3
- messages:
4
- not_found: "not found"
5
- already_confirmed: "was already confirmed"
6
- not_locked: "was not locked"
7
-
8
- devise:
9
- failure:
10
- unauthenticated: 'You need to sign in or sign up before continuing.'
11
- unconfirmed: 'You have to confirm your account before continuing.'
12
- locked: 'Your account is locked.'
13
- invalid: 'Invalid email or password.'
14
- invalid_token: 'Invalid authentication token.'
15
- timeout: 'Your session expired, please sign in again to continue.'
16
- inactive: 'Your account was not activated yet.'
17
- sessions:
18
- signed_in: 'Signed in successfully.'
19
- signed_out: 'Signed out successfully.'
20
- passwords:
21
- send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.'
22
- updated: 'Your password was changed successfully. You are now signed in.'
23
- confirmations:
24
- send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.'
25
- confirmed: 'Your account was successfully confirmed. You are now signed in.'
26
- registrations:
27
- signed_up: 'You have signed up successfully. If enabled, a confirmation was sent to your e-mail.'
28
- updated: 'You updated your account successfully.'
29
- destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.'
30
- unlocks:
31
- send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.'
32
- unlocked: 'Your account was successfully unlocked. You are now signed in.'
33
- mailer:
34
- confirmation_instructions:
35
- subject: 'Confirmation instructions'
36
- reset_password_instructions:
37
- subject: 'Reset password instructions'
38
- unlock_instructions:
39
- subject: 'Unlock Instructions'
@@ -1,14 +0,0 @@
1
- class CreatePosts < ActiveRecord::Migration
2
- def self.up
3
- create_table :posts do |t|
4
- t.string :title
5
- t.text :body
6
-
7
- t.timestamps
8
- end
9
- end
10
-
11
- def self.down
12
- drop_table :posts
13
- end
14
- end
@@ -1,7 +0,0 @@
1
- # This file should contain all the record creation needed to seed the database with its default values.
2
- # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
3
- #
4
- # Examples:
5
- #
6
- # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
7
- # Mayor.create(:name => 'Daley', :city => cities.first)
@@ -1,14 +0,0 @@
1
- Factory.define :user do |f|
2
- f.email "example.user@test.com"
3
- f.password "secret"
4
- end
5
-
6
- Factory.define :admin, :class => "user" do |f|
7
- f.email "example.admin@test.com"
8
- f.password "admin_secret"
9
- end
10
-
11
- Factory.define :other, :class => "user" do |f|
12
- f.email "other.user@test.com"
13
- f.password "other_secret"
14
- end
@@ -1,58 +0,0 @@
1
- require 'test_helper'
2
-
3
- class PostsControllerTest < ActionController::TestCase
4
-
5
- include Devise::TestHelpers
6
-
7
- context "not logged in" do
8
- should "should get INDEX" do
9
- get :index
10
- assert_response :success
11
- assert_equal(response.body, "posts#index")
12
- end
13
-
14
- context "go to NEW page" do
15
- setup do
16
- get :new
17
- end
18
-
19
- should "not get NEW" do
20
- assert_response :redirect
21
- end
22
- end
23
- end
24
-
25
- context "logged in" do
26
- setup do
27
- @user = Factory(:user)
28
- sign_in(@user)
29
- end
30
-
31
- context "get NEW action" do
32
- setup do
33
- get :new
34
- end
35
-
36
- should "get the NEW action" do
37
- assert_response :success
38
- assert_equal(response.body, "posts#new")
39
- end
40
- end
41
-
42
- context "log out user" do
43
- setup do
44
- sign_out(@user)
45
- get :new
46
- end
47
-
48
- should "get redirected to the login page" do
49
- assert_response :redirect
50
- end
51
- end
52
-
53
-
54
- end
55
-
56
-
57
-
58
- end
@@ -1,9 +0,0 @@
1
- require 'test_helper'
2
- require 'rails/performance_test_help'
3
-
4
- # Profiling results for each test method are written to tmp/performance.
5
- class BrowsingTest < ActionDispatch::PerformanceTest
6
- def test_homepage
7
- get '/'
8
- end
9
- end
@@ -1,36 +0,0 @@
1
- ENV["RAILS_ENV"] = "test"
2
- require File.expand_path('../../config/environment', __FILE__)
3
- require 'rails/test_help'
4
-
5
- class ActiveSupport::TestCase
6
-
7
- def ldap_connect_string
8
- if ENV["LDAP_SSL"]
9
- "-x -H ldaps://localhost:3389 -D 'cn=admin,dc=test,dc=com' -w secret"
10
- else
11
- "-x -h localhost -p 3389 -D 'cn=admin,dc=test,dc=com' -w secret"
12
- end
13
- end
14
-
15
- def reset_ldap_server!
16
- if ENV["LDAP_SSL"]
17
- `ldapmodify #{ldap_connect_string} -f ../ldap/clear.ldif`
18
- `ldapadd #{ldap_connect_string} -f ../ldap/base.ldif`
19
- else
20
- `ldapmodify #{ldap_connect_string} -f ../ldap/clear.ldif`
21
- `ldapadd #{ldap_connect_string} -f ../ldap/base.ldif`
22
- end
23
- end
24
-
25
- def default_devise_settings!
26
- ::Devise.ldap_logger = true
27
- ::Devise.ldap_create_user = false
28
- ::Devise.ldap_update_password = true
29
- ::Devise.ldap_config = "#{Rails.root}/config/#{"ssl_" if ENV["LDAP_SSL"]}ldap.yml"
30
- ::Devise.ldap_check_group_membership = false
31
- ::Devise.ldap_check_attributes = false
32
- ::Devise.ldap_auth_username_builder = Proc.new() {|attribute, login, ldap| "#{attribute}=#{login},#{ldap.base}" }
33
- ::Devise.authentication_keys = [:email]
34
- end
35
-
36
- end
@@ -1,4 +0,0 @@
1
- require 'test_helper'
2
-
3
- class PostsHelperTest < ActionView::TestCase
4
- end
@@ -1,4 +0,0 @@
1
- require 'test_helper'
2
-
3
- class PostTest < ActiveSupport::TestCase
4
- end
@@ -1,314 +0,0 @@
1
- require 'test_helper'
2
-
3
- class UserTest < ActiveSupport::TestCase
4
-
5
- def should_be_validated(user, password, message = "Password is invalid")
6
- assert(user.valid_ldap_authentication?(password), message)
7
- end
8
-
9
- def should_not_be_validated(user, password, message = "Password is not properly set")
10
- assert(!user.valid_ldap_authentication?(password), message)
11
- end
12
-
13
- context "With default settings" do
14
- setup do
15
- default_devise_settings!
16
- reset_ldap_server!
17
- end
18
-
19
- context "look up and ldap user" do
20
- should "return true for a user that does exist in LDAP" do
21
- assert_equal true, ::Devise::LdapAdapter.valid_login?('example.user@test.com')
22
- end
23
-
24
- should "return false for a user that doesn't exist in LDAP" do
25
- assert_equal false, ::Devise::LdapAdapter.valid_login?('barneystinson')
26
- end
27
- end
28
-
29
- context "create a basic user" do
30
- setup do
31
- @user = Factory(:user)
32
- end
33
-
34
- should "check for password validation" do
35
- assert_equal(@user.email, "example.user@test.com")
36
- should_be_validated @user, "secret"
37
- should_not_be_validated @user, "wrong_secret"
38
- should_not_be_validated @user, "Secret"
39
- end
40
- end
41
-
42
- context "change a LDAP password" do
43
- setup do
44
- @user = Factory(:user)
45
- end
46
-
47
- should "change password" do
48
- should_be_validated @user, "secret"
49
- @user.reset_password!("changed","changed")
50
- should_be_validated @user, "changed", "password was not changed properly on the LDAP sevrer"
51
- end
52
-
53
- should "not allow to change password if setting is false" do
54
- should_be_validated @user, "secret"
55
- ::Devise.ldap_update_password = false
56
- @user.reset_password!("wrong_secret", "wrong_secret")
57
- should_not_be_validated @user, "wrong_secret"
58
- should_be_validated @user, "secret"
59
- end
60
- end
61
-
62
- context "create new local user if user is in LDAP" do
63
-
64
- setup do
65
- assert(User.all.blank?, "There shouldn't be any users in the database")
66
- end
67
-
68
- should "don't create user in the database" do
69
- @user = User.authenticate_with_ldap(:email => "example.user@test.com", :password => "secret")
70
- assert(User.all.blank?)
71
- end
72
-
73
- context "creating users is enabled" do
74
- setup do
75
- ::Devise.ldap_create_user = true
76
- end
77
-
78
- should "create a user in the database" do
79
- @user = User.authenticate_with_ldap(:email => "example.user@test.com", :password => "secret")
80
- assert_equal(User.all.size, 1)
81
- assert_contains(User.all.collect(&:email), "example.user@test.com", "user not in database")
82
- end
83
-
84
- should "not create a user in the database if the password is wrong_secret" do
85
- @user = User.authenticate_with_ldap(:email => "example.user", :password => "wrong_secret")
86
- assert(User.all.blank?, "There's users in the database")
87
- end
88
-
89
- should "create a user if the user is not in LDAP" do
90
- @user = User.authenticate_with_ldap(:email => "wrong_secret.user@test.com", :password => "wrong_secret")
91
- assert(User.all.blank?, "There's users in the database")
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
118
- end
119
-
120
- end
121
-
122
- context "use groups for authorization" do
123
- setup do
124
- @admin = Factory(:admin)
125
- @user = Factory(:user)
126
- ::Devise.authentication_keys = [:email]
127
- ::Devise.ldap_check_group_membership = true
128
- end
129
-
130
- context "config check_group_membership is not defined" do
131
- should "admin should be allowed in" do
132
- should_be_validated @admin, "admin_secret"
133
- end
134
-
135
- should "admin should have the proper groups set" do
136
- assert_contains(@admin.ldap_groups, /cn=admins/, "groups attribute not being set properly")
137
- end
138
-
139
- should "user should not be allowed in" do
140
- should_not_be_validated @user, "secret"
141
- end
142
-
143
- should "not be validated if group with different attribute is removed" do
144
- `ldapmodify #{ldap_connect_string} -f ../ldap/delete_authorization_role.ldif`
145
- should_not_be_validated @admin, "admin_secret"
146
- end
147
- end
148
-
149
- context "config file check_group_membership is defined" do
150
- setup do
151
- default_devise_settings!
152
- reset_ldap_server!
153
- end
154
-
155
- context "check_group_membership is turned on" do
156
- setup do
157
- ::Devise.ldap_config = "#{Rails.root}/config/ldap_with_check_membership_on.yml"
158
-
159
- ::Devise.ldap_check_group_membership = false
160
- end
161
-
162
- # Config file value has precedence over ldap_check_group_membership
163
- should "user should not be allowed in" do
164
- should_not_be_validated @user, "secret"
165
- end
166
- end
167
-
168
- context "check_group_membership is turned off" do
169
- setup do
170
- ::Devise.ldap_config = "#{Rails.root}/config/ldap_with_check_membership_off.yml"
171
-
172
- ::Devise.ldap_check_group_membership = true
173
- end
174
-
175
- # Config file value has precedence over ldap_check_group_membership
176
- should "user should be allowed in" do
177
- should_be_validated @user, "secret"
178
- end
179
- end
180
- end
181
- end
182
-
183
- context "use role attribute for authorization" do
184
- setup do
185
- @admin = Factory(:admin)
186
- @user = Factory(:user)
187
- ::Devise.ldap_check_attributes = true
188
- end
189
-
190
- should "admin should be allowed in" do
191
- should_be_validated @admin, "admin_secret"
192
- end
193
-
194
- should "user should not be allowed in" do
195
- should_not_be_validated @user, "secret"
196
- end
197
- end
198
-
199
- context "use admin setting to bind" do
200
- setup do
201
- @admin = Factory(:admin)
202
- @user = Factory(:user)
203
- ::Devise.ldap_use_admin_to_bind = true
204
- end
205
-
206
- should "description" do
207
- should_be_validated @admin, "admin_secret"
208
- end
209
- end
210
-
211
- end
212
-
213
- context "use uid for login" do
214
- setup do
215
- default_devise_settings!
216
- reset_ldap_server!
217
- ::Devise.ldap_config = "#{Rails.root}/config/#{"ssl_" if ENV["LDAP_SSL"]}ldap_with_uid.yml"
218
- ::Devise.authentication_keys = [:uid]
219
- end
220
-
221
- context "description" do
222
- setup do
223
- @admin = Factory(:admin)
224
- @user = Factory(:user, :uid => "example_user")
225
- end
226
-
227
- should "be able to authenticate using uid" do
228
- should_be_validated @user, "secret"
229
- should_not_be_validated @admin, "admin_secret"
230
- end
231
- end
232
-
233
- context "create user" do
234
- setup do
235
- ::Devise.ldap_create_user = true
236
- end
237
-
238
- should "create a user in the database" do
239
- @user = User.authenticate_with_ldap(:uid => "example_user", :password => "secret")
240
- assert_equal(User.all.size, 1)
241
- assert_contains(User.all.collect(&:uid), "example_user", "user not in database")
242
- end
243
-
244
- should "call ldap_before_save hooks" do
245
- User.class_eval do
246
- def ldap_before_save
247
- @foobar = 'foobar'
248
- end
249
- end
250
- user = User.authenticate_with_ldap(:uid => "example_user", :password => "secret")
251
- assert_equal 'foobar', user.instance_variable_get(:"@foobar")
252
- User.class_eval do
253
- undef ldap_before_save
254
- end
255
- end
256
-
257
- should "not call ldap_before_save hook if not defined" do
258
- assert_nothing_raised do
259
- should_be_validated Factory(:user, :uid => "example_user"), "secret"
260
- end
261
- end
262
- end
263
- end
264
-
265
- context "using ERB in the config file" do
266
- setup do
267
- default_devise_settings!
268
- reset_ldap_server!
269
- ::Devise.ldap_config = "#{Rails.root}/config/#{"ssl_" if ENV["LDAP_SSL"]}ldap_with_erb.yml"
270
- end
271
-
272
- context "authenticate" do
273
- setup do
274
- @admin = Factory(:admin)
275
- @user = Factory(:user)
276
- end
277
-
278
- should "be able to authenticate" do
279
- should_be_validated @user, "secret"
280
- should_be_validated @admin, "admin_secret"
281
- end
282
- end
283
- end
284
-
285
- context "using variants in the config file" do
286
- setup do
287
- default_devise_settings!
288
- reset_ldap_server!
289
- ::Devise.ldap_config = Rails.root.join 'config', 'ldap_with_boolean_ssl.yml'
290
- end
291
-
292
- should "not fail if config file has ssl: true" do
293
- assert_nothing_raised do
294
- Devise::LdapAdapter::LdapConnect.new
295
- end
296
- end
297
- end
298
-
299
- context "use username builder" do
300
- setup do
301
- default_devise_settings!
302
- reset_ldap_server!
303
- ::Devise.ldap_auth_username_builder = Proc.new() do |attribute, login, ldap|
304
- "#{attribute}=#{login},ou=others,dc=test,dc=com"
305
- end
306
- @other = Factory(:other)
307
- end
308
-
309
- should "be able to authenticate" do
310
- should_be_validated @other, "other_secret"
311
- end
312
- end
313
-
314
- end