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.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +1 -4
- data/README.md +45 -92
- data/Rakefile +8 -7
- data/devise_ldap_authenticatable.gemspec +15 -3
- data/lib/devise_ldap_authenticatable/ldap_adapter.rb +51 -27
- data/lib/devise_ldap_authenticatable/model.rb +5 -1
- data/lib/devise_ldap_authenticatable/strategy.rb +3 -1
- data/lib/devise_ldap_authenticatable/version.rb +1 -1
- data/lib/generators/devise_ldap_authenticatable/templates/ldap.yml +3 -3
- data/spec/ldap/.gitignore +2 -0
- data/{test → spec}/ldap/base.ldif +0 -0
- data/{test → spec}/ldap/clear.ldif +0 -0
- data/{test → spec}/ldap/local.schema +0 -0
- data/spec/ldap/openldap-data/.gitignore +2 -0
- data/spec/ldap/openldap-data/run/.gitignore +2 -0
- data/{test → spec}/ldap/openldap-data/run/.gitkeep +0 -0
- data/spec/ldap/run-server +31 -0
- data/{test → spec}/ldap/server.pem +0 -0
- data/{test/ldap/slapd-test.conf → spec/ldap/slapd-test.conf.erb} +16 -16
- data/{test → spec}/rails_app/Rakefile +0 -0
- data/spec/rails_app/app/controllers/application_controller.rb +7 -0
- data/{test → spec}/rails_app/app/controllers/posts_controller.rb +0 -0
- data/{test → spec}/rails_app/app/helpers/application_helper.rb +0 -0
- data/{test → spec}/rails_app/app/helpers/posts_helper.rb +0 -0
- data/{test → spec}/rails_app/app/models/post.rb +0 -0
- data/{test → spec}/rails_app/app/models/user.rb +0 -0
- data/{test → spec}/rails_app/app/views/layouts/application.html.erb +0 -0
- data/{test → spec}/rails_app/app/views/posts/index.html.erb +0 -0
- data/{test → spec}/rails_app/config.ru +0 -0
- data/{test → spec}/rails_app/config/application.rb +0 -0
- data/{test → spec}/rails_app/config/boot.rb +1 -1
- data/{test → spec}/rails_app/config/cucumber.yml +0 -0
- data/{test → spec}/rails_app/config/database.yml +0 -0
- data/{test → spec}/rails_app/config/environment.rb +0 -0
- data/{test → spec}/rails_app/config/environments/development.rb +0 -1
- data/{test → spec}/rails_app/config/environments/production.rb +0 -0
- data/{test → spec}/rails_app/config/environments/test.rb +1 -1
- data/{test → spec}/rails_app/config/initializers/backtrace_silencers.rb +0 -0
- data/spec/rails_app/config/initializers/devise.rb +242 -0
- data/{test → spec}/rails_app/config/initializers/inflections.rb +0 -0
- data/{test → spec}/rails_app/config/initializers/mime_types.rb +0 -0
- data/{test → spec}/rails_app/config/initializers/secret_token.rb +0 -0
- data/{test → spec}/rails_app/config/initializers/session_store.rb +0 -0
- data/{test → spec}/rails_app/config/ldap.yml +0 -0
- data/{test → spec}/rails_app/config/ldap_with_boolean_ssl.yml +0 -0
- data/{test → spec}/rails_app/config/ldap_with_erb.yml +0 -0
- data/{test → spec}/rails_app/config/ldap_with_uid.yml +0 -0
- data/spec/rails_app/config/locales/devise.en.yml +58 -0
- data/{test → spec}/rails_app/config/locales/en.yml +0 -0
- data/{test → spec}/rails_app/config/routes.rb +0 -0
- data/{test → spec}/rails_app/config/ssl_ldap.yml +0 -0
- data/{test → spec}/rails_app/config/ssl_ldap_with_erb.yml +0 -0
- data/{test → spec}/rails_app/config/ssl_ldap_with_uid.yml +0 -0
- data/{test → spec}/rails_app/db/migrate/20100708120448_devise_create_users.rb +18 -4
- data/{test → spec}/rails_app/db/schema.rb +6 -13
- data/{test → spec}/rails_app/features/manage_logins.feature +0 -0
- data/{test → spec}/rails_app/features/step_definitions/login_steps.rb +0 -0
- data/{test → spec}/rails_app/features/step_definitions/web_steps.rb +0 -0
- data/{test → spec}/rails_app/features/support/env.rb +0 -0
- data/{test → spec}/rails_app/features/support/paths.rb +0 -0
- data/{test → spec}/rails_app/lib/tasks/.gitkeep +0 -0
- data/{test → spec}/rails_app/lib/tasks/cucumber.rake +0 -0
- data/{test → spec}/rails_app/public/404.html +0 -0
- data/{test → spec}/rails_app/public/422.html +0 -0
- data/{test → spec}/rails_app/public/500.html +0 -0
- data/{test → spec}/rails_app/public/images/rails.png +0 -0
- data/{test → spec}/rails_app/public/javascripts/application.js +0 -0
- data/{test → spec}/rails_app/public/javascripts/controls.js +0 -0
- data/{test → spec}/rails_app/public/javascripts/dragdrop.js +0 -0
- data/{test → spec}/rails_app/public/javascripts/effects.js +0 -0
- data/{test → spec}/rails_app/public/javascripts/prototype.js +0 -0
- data/{test → spec}/rails_app/public/javascripts/rails.js +0 -0
- data/{test → spec}/rails_app/public/stylesheets/.gitkeep +0 -0
- data/{test → spec}/rails_app/script/cucumber +0 -0
- data/{test → spec}/rails_app/script/rails +0 -0
- data/spec/spec_helper.rb +47 -0
- data/spec/support/factories.rb +16 -0
- data/spec/unit/user_spec.rb +303 -0
- metadata +292 -179
- data/Gemfile.lock +0 -92
- data/rails/init.rb +0 -2
- data/test/devise_ldap_authenticatable_test.rb +0 -8
- data/test/ldap/run-server.sh +0 -10
- data/test/ldap/slapd-ssl-test.conf +0 -107
- data/test/rails_app/Gemfile +0 -22
- data/test/rails_app/Gemfile.lock +0 -159
- data/test/rails_app/app/controllers/application_controller.rb +0 -4
- data/test/rails_app/config/initializers/devise.rb +0 -140
- data/test/rails_app/config/ldap_with_check_membership_off.yml +0 -23
- data/test/rails_app/config/ldap_with_check_membership_on.yml +0 -23
- data/test/rails_app/config/locales/devise.en.yml +0 -39
- data/test/rails_app/db/migrate/20100708120302_create_posts.rb +0 -14
- data/test/rails_app/db/seeds.rb +0 -7
- data/test/rails_app/test/factories/users.rb +0 -14
- data/test/rails_app/test/functional/posts_controller_test.rb +0 -58
- data/test/rails_app/test/performance/browsing_test.rb +0 -9
- data/test/rails_app/test/test_helper.rb +0 -36
- data/test/rails_app/test/unit/helpers/posts_helper_test.rb +0 -4
- data/test/rails_app/test/unit/post_test.rb +0 -4
- data/test/rails_app/test/unit/user_test.rb +0 -314
- data/test/test_helper.rb +0 -3
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# Additional translations at https://github.com/plataformatec/devise/wiki/I18n
|
2
|
+
|
3
|
+
en:
|
4
|
+
errors:
|
5
|
+
messages:
|
6
|
+
expired: "has expired, please request a new one"
|
7
|
+
not_found: "not found"
|
8
|
+
already_confirmed: "was already confirmed, please try signing in"
|
9
|
+
not_locked: "was not locked"
|
10
|
+
not_saved:
|
11
|
+
one: "1 error prohibited this %{resource} from being saved:"
|
12
|
+
other: "%{count} errors prohibited this %{resource} from being saved:"
|
13
|
+
|
14
|
+
devise:
|
15
|
+
failure:
|
16
|
+
already_authenticated: 'You are already signed in.'
|
17
|
+
unauthenticated: 'You need to sign in or sign up before continuing.'
|
18
|
+
unconfirmed: 'You have to confirm your account before continuing.'
|
19
|
+
locked: 'Your account is locked.'
|
20
|
+
invalid: 'Invalid email or password.'
|
21
|
+
invalid_token: 'Invalid authentication token.'
|
22
|
+
timeout: 'Your session expired, please sign in again to continue.'
|
23
|
+
inactive: 'Your account was not activated yet.'
|
24
|
+
sessions:
|
25
|
+
signed_in: 'Signed in successfully.'
|
26
|
+
signed_out: 'Signed out successfully.'
|
27
|
+
passwords:
|
28
|
+
send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.'
|
29
|
+
updated: 'Your password was changed successfully. You are now signed in.'
|
30
|
+
updated_not_active: 'Your password was changed successfully.'
|
31
|
+
send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes."
|
32
|
+
no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided."
|
33
|
+
confirmations:
|
34
|
+
send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.'
|
35
|
+
send_paranoid_instructions: 'If your email address exists in our database, you will receive an email with instructions about how to confirm your account in a few minutes.'
|
36
|
+
confirmed: 'Your account was successfully confirmed. You are now signed in.'
|
37
|
+
registrations:
|
38
|
+
signed_up: 'Welcome! You have signed up successfully.'
|
39
|
+
signed_up_but_unconfirmed: 'A message with a confirmation link has been sent to your email address. Please open the link to activate your account.'
|
40
|
+
signed_up_but_inactive: 'You have signed up successfully. However, we could not sign you in because your account is not yet activated.'
|
41
|
+
signed_up_but_locked: 'You have signed up successfully. However, we could not sign you in because your account is locked.'
|
42
|
+
updated: 'You updated your account successfully.'
|
43
|
+
update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address."
|
44
|
+
destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.'
|
45
|
+
unlocks:
|
46
|
+
send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.'
|
47
|
+
unlocked: 'Your account has been unlocked successfully. Please sign in to continue.'
|
48
|
+
send_paranoid_instructions: 'If your account exists, you will receive an email with instructions about how to unlock it in a few minutes.'
|
49
|
+
omniauth_callbacks:
|
50
|
+
success: 'Successfully authenticated from %{kind} account.'
|
51
|
+
failure: 'Could not authenticate you from %{kind} because "%{reason}".'
|
52
|
+
mailer:
|
53
|
+
confirmation_instructions:
|
54
|
+
subject: 'Confirmation instructions'
|
55
|
+
reset_password_instructions:
|
56
|
+
subject: 'Reset password instructions'
|
57
|
+
unlock_instructions:
|
58
|
+
subject: 'Unlock Instructions'
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,10 +1,24 @@
|
|
1
1
|
class DeviseCreateUsers < ActiveRecord::Migration
|
2
2
|
def self.up
|
3
3
|
create_table(:users) do |t|
|
4
|
-
|
5
|
-
t.
|
6
|
-
t.
|
7
|
-
|
4
|
+
## Database authenticatable
|
5
|
+
t.string :email, :null => false, :default => ""
|
6
|
+
t.string :encrypted_password, :null => false, :default => ""
|
7
|
+
|
8
|
+
## Recoverable
|
9
|
+
t.string :reset_password_token
|
10
|
+
t.datetime :reset_password_sent_at
|
11
|
+
|
12
|
+
## Rememberable
|
13
|
+
t.datetime :remember_created_at
|
14
|
+
|
15
|
+
## Trackable
|
16
|
+
t.integer :sign_in_count, :default => 0
|
17
|
+
t.datetime :current_sign_in_at
|
18
|
+
t.datetime :last_sign_in_at
|
19
|
+
t.string :current_sign_in_ip
|
20
|
+
t.string :last_sign_in_ip
|
21
|
+
|
8
22
|
t.string :uid
|
9
23
|
|
10
24
|
# t.confirmable
|
@@ -12,27 +12,20 @@
|
|
12
12
|
|
13
13
|
ActiveRecord::Schema.define(:version => 20100708120448) do
|
14
14
|
|
15
|
-
create_table "posts", :force => true do |t|
|
16
|
-
t.string "title"
|
17
|
-
t.text "body"
|
18
|
-
t.datetime "created_at"
|
19
|
-
t.datetime "updated_at"
|
20
|
-
end
|
21
|
-
|
22
15
|
create_table "users", :force => true do |t|
|
23
|
-
t.string "email",
|
24
|
-
t.string "encrypted_password",
|
16
|
+
t.string "email", :default => "", :null => false
|
17
|
+
t.string "encrypted_password", :default => "", :null => false
|
25
18
|
t.string "reset_password_token"
|
26
|
-
t.
|
19
|
+
t.datetime "reset_password_sent_at"
|
27
20
|
t.datetime "remember_created_at"
|
28
|
-
t.integer "sign_in_count",
|
21
|
+
t.integer "sign_in_count", :default => 0
|
29
22
|
t.datetime "current_sign_in_at"
|
30
23
|
t.datetime "last_sign_in_at"
|
31
24
|
t.string "current_sign_in_ip"
|
32
25
|
t.string "last_sign_in_ip"
|
33
26
|
t.string "uid"
|
34
|
-
t.datetime "created_at"
|
35
|
-
t.datetime "updated_at"
|
27
|
+
t.datetime "created_at", :null => false
|
28
|
+
t.datetime "updated_at", :null => false
|
36
29
|
end
|
37
30
|
|
38
31
|
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
|
3
|
+
require File.expand_path("rails_app/config/environment.rb", File.dirname(__FILE__))
|
4
|
+
require 'rspec/rails'
|
5
|
+
require 'rspec/autorun'
|
6
|
+
require 'factory_girl' # not sure why this is not already required
|
7
|
+
|
8
|
+
Dir[File.expand_path("support/**/*.rb", File.dirname(__FILE__))].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.mock_with :rspec
|
12
|
+
config.use_transactional_fixtures = true
|
13
|
+
config.infer_base_class_for_anonymous_controllers = false
|
14
|
+
end
|
15
|
+
|
16
|
+
def ldap_root
|
17
|
+
File.expand_path('ldap', File.dirname(__FILE__))
|
18
|
+
end
|
19
|
+
|
20
|
+
def ldap_connect_string
|
21
|
+
if ENV["LDAP_SSL"]
|
22
|
+
"-x -H ldaps://localhost:3389 -D 'cn=admin,dc=test,dc=com' -w secret"
|
23
|
+
else
|
24
|
+
"-x -h localhost -p 3389 -D 'cn=admin,dc=test,dc=com' -w secret"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def reset_ldap_server!
|
29
|
+
if ENV["LDAP_SSL"]
|
30
|
+
`ldapmodify #{ldap_connect_string} -f #{File.join(ldap_root, 'clear.ldif')}`
|
31
|
+
`ldapadd #{ldap_connect_string} -f #{File.join(ldap_root, 'base.ldif')}`
|
32
|
+
else
|
33
|
+
`ldapmodify #{ldap_connect_string} -f #{File.join(ldap_root, 'clear.ldif')}`
|
34
|
+
`ldapadd #{ldap_connect_string} -f #{File.join(ldap_root, 'base.ldif')}`
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def default_devise_settings!
|
39
|
+
::Devise.ldap_logger = true
|
40
|
+
::Devise.ldap_create_user = false
|
41
|
+
::Devise.ldap_update_password = true
|
42
|
+
::Devise.ldap_config = "#{Rails.root}/config/#{"ssl_" if ENV["LDAP_SSL"]}ldap.yml"
|
43
|
+
::Devise.ldap_check_group_membership = false
|
44
|
+
::Devise.ldap_check_attributes = false
|
45
|
+
::Devise.ldap_auth_username_builder = Proc.new() {|attribute, login, ldap| "#{attribute}=#{login},#{ldap.base}" }
|
46
|
+
::Devise.authentication_keys = [:email]
|
47
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
FactoryGirl.define do
|
2
|
+
factory :user do
|
3
|
+
email "example.user@test.com"
|
4
|
+
password "secret"
|
5
|
+
end
|
6
|
+
|
7
|
+
factory :admin, :class => User do
|
8
|
+
email "example.admin@test.com"
|
9
|
+
password "admin_secret"
|
10
|
+
end
|
11
|
+
|
12
|
+
factory :other, :class => User do
|
13
|
+
email "other.user@test.com"
|
14
|
+
password "other_secret"
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,303 @@
|
|
1
|
+
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
describe 'Users' do
|
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
|
+
describe "With default settings" do
|
14
|
+
before do
|
15
|
+
default_devise_settings!
|
16
|
+
reset_ldap_server!
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "look up and ldap user" do
|
20
|
+
it "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
|
+
it "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
|
+
describe "create a basic user" do
|
30
|
+
before do
|
31
|
+
@user = Factory.create(:user)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "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
|
+
describe "change a LDAP password" do
|
43
|
+
before do
|
44
|
+
@user = Factory.create(:user)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should change password" do
|
48
|
+
should_be_validated @user, "secret"
|
49
|
+
@user.password = "changed"
|
50
|
+
@user.change_password!("secret")
|
51
|
+
should_be_validated @user, "changed", "password was not changed properly on the LDAP sevrer"
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should not allow to change password if setting is false" do
|
55
|
+
should_be_validated @user, "secret"
|
56
|
+
::Devise.ldap_update_password = false
|
57
|
+
@user.reset_password!("wrong_secret", "wrong_secret")
|
58
|
+
should_not_be_validated @user, "wrong_secret"
|
59
|
+
should_be_validated @user, "secret"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "create new local user if user is in LDAP" do
|
64
|
+
|
65
|
+
before do
|
66
|
+
assert(User.all.blank?, "There shouldn't be any users in the database")
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should don't create user in the database" do
|
70
|
+
@user = User.authenticate_with_ldap(:email => "example.user@test.com", :password => "secret")
|
71
|
+
assert(User.all.blank?)
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "creating users is enabled" do
|
75
|
+
before do
|
76
|
+
::Devise.ldap_create_user = true
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should create a user in the database" do
|
80
|
+
@user = User.authenticate_with_ldap(:email => "example.user@test.com", :password => "secret")
|
81
|
+
assert_equal(User.all.size, 1)
|
82
|
+
User.all.collect(&:email).should include("example.user@test.com")
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should not create a user in the database if the password is wrong_secret" do
|
86
|
+
@user = User.authenticate_with_ldap(:email => "example.user", :password => "wrong_secret")
|
87
|
+
assert(User.all.blank?, "There's users in the database")
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should create a user if the user is not in LDAP" do
|
91
|
+
@user = User.authenticate_with_ldap(:email => "wrong_secret.user@test.com", :password => "wrong_secret")
|
92
|
+
assert(User.all.blank?, "There's users in the database")
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should create a user in the database if case insensitivity does not matter" do
|
96
|
+
::Devise.case_insensitive_keys = []
|
97
|
+
@user = Factory.create(:user)
|
98
|
+
|
99
|
+
expect do
|
100
|
+
User.authenticate_with_ldap(:email => "EXAMPLE.user@test.com", :password => "secret")
|
101
|
+
end.to change { User.count }.by(1)
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should not create a user in the database if case insensitivity matters" do
|
105
|
+
::Devise.case_insensitive_keys = [:email]
|
106
|
+
@user = Factory.create(:user)
|
107
|
+
|
108
|
+
expect do
|
109
|
+
User.authenticate_with_ldap(:email => "EXAMPLE.user@test.com", :password => "secret")
|
110
|
+
end.to_not change { User.count }
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should create a user with downcased email in the database if case insensitivity matters" do
|
114
|
+
::Devise.case_insensitive_keys = [:email]
|
115
|
+
|
116
|
+
@user = User.authenticate_with_ldap(:email => "EXAMPLE.user@test.com", :password => "secret")
|
117
|
+
User.all.collect(&:email).should include("example.user@test.com")
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
describe "use groups for authorization" do
|
124
|
+
before do
|
125
|
+
@admin = Factory.create(:admin)
|
126
|
+
@user = Factory.create(:user)
|
127
|
+
::Devise.authentication_keys = [:email]
|
128
|
+
::Devise.ldap_check_group_membership = true
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should admin should be allowed in" do
|
132
|
+
should_be_validated @admin, "admin_secret"
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should admin should have the proper groups set" do
|
136
|
+
@admin.ldap_groups.should include('cn=admins,ou=groups,dc=test,dc=com')
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should user should not be allowed in" do
|
140
|
+
should_not_be_validated @user, "secret"
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
describe "check group membership" do
|
145
|
+
before do
|
146
|
+
@admin = Factory.create(:admin)
|
147
|
+
@user = Factory.create(:user)
|
148
|
+
end
|
149
|
+
|
150
|
+
it "should return true for admin being in the admins group" do
|
151
|
+
assert_equal true, @admin.in_ldap_group?('cn=admins,ou=groups,dc=test,dc=com')
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should return false for admin being in the admins group using the 'foobar' group attribute" do
|
155
|
+
assert_equal false, @admin.in_ldap_group?('cn=admins,ou=groups,dc=test,dc=com', 'foobar')
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should return true for user being in the users group" do
|
159
|
+
assert_equal true, @user.in_ldap_group?('cn=users,ou=groups,dc=test,dc=com')
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should return false for user being in the admins group" do
|
163
|
+
assert_equal false, @user.in_ldap_group?('cn=admins,ou=groups,dc=test,dc=com')
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should return false for a user being in a nonexistent group" do
|
167
|
+
assert_equal false, @user.in_ldap_group?('cn=thisgroupdoesnotexist,ou=groups,dc=test,dc=com')
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
|
172
|
+
describe "use role attribute for authorization" do
|
173
|
+
before do
|
174
|
+
@admin = Factory.create(:admin)
|
175
|
+
@user = Factory.create(:user)
|
176
|
+
::Devise.ldap_check_attributes = true
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should admin should be allowed in" do
|
180
|
+
should_be_validated @admin, "admin_secret"
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should user should not be allowed in" do
|
184
|
+
should_not_be_validated @user, "secret"
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
describe "use admin setting to bind" do
|
189
|
+
before do
|
190
|
+
@admin = Factory.create(:admin)
|
191
|
+
@user = Factory.create(:user)
|
192
|
+
::Devise.ldap_use_admin_to_bind = true
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should description" do
|
196
|
+
should_be_validated @admin, "admin_secret"
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
end
|
201
|
+
|
202
|
+
describe "use uid for login" do
|
203
|
+
before do
|
204
|
+
default_devise_settings!
|
205
|
+
reset_ldap_server!
|
206
|
+
::Devise.ldap_config = "#{Rails.root}/config/#{"ssl_" if ENV["LDAP_SSL"]}ldap_with_uid.yml"
|
207
|
+
::Devise.authentication_keys = [:uid]
|
208
|
+
end
|
209
|
+
|
210
|
+
describe "description" do
|
211
|
+
before do
|
212
|
+
@admin = Factory.create(:admin)
|
213
|
+
@user = Factory.create(:user, :uid => "example_user")
|
214
|
+
end
|
215
|
+
|
216
|
+
it "should be able to authenticate using uid" do
|
217
|
+
should_be_validated @user, "secret"
|
218
|
+
should_not_be_validated @admin, "admin_secret"
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
describe "create user" do
|
223
|
+
before do
|
224
|
+
::Devise.ldap_create_user = true
|
225
|
+
end
|
226
|
+
|
227
|
+
it "should create a user in the database" do
|
228
|
+
@user = User.authenticate_with_ldap(:uid => "example_user", :password => "secret")
|
229
|
+
assert_equal(User.all.size, 1)
|
230
|
+
User.all.collect(&:uid).should include("example_user")
|
231
|
+
end
|
232
|
+
|
233
|
+
it "should call ldap_before_save hooks" do
|
234
|
+
User.class_eval do
|
235
|
+
def ldap_before_save
|
236
|
+
@foobar = 'foobar'
|
237
|
+
end
|
238
|
+
end
|
239
|
+
user = User.authenticate_with_ldap(:uid => "example_user", :password => "secret")
|
240
|
+
assert_equal 'foobar', user.instance_variable_get(:"@foobar")
|
241
|
+
User.class_eval do
|
242
|
+
undef ldap_before_save
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
it "should not call ldap_before_save hook if not defined" do
|
247
|
+
assert_nothing_raised do
|
248
|
+
should_be_validated Factory.create(:user, :uid => "example_user"), "secret"
|
249
|
+
end
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
describe "using ERB in the config file" do
|
255
|
+
before do
|
256
|
+
default_devise_settings!
|
257
|
+
reset_ldap_server!
|
258
|
+
::Devise.ldap_config = "#{Rails.root}/config/#{"ssl_" if ENV["LDAP_SSL"]}ldap_with_erb.yml"
|
259
|
+
end
|
260
|
+
|
261
|
+
describe "authenticate" do
|
262
|
+
before do
|
263
|
+
@admin = Factory.create(:admin)
|
264
|
+
@user = Factory.create(:user)
|
265
|
+
end
|
266
|
+
|
267
|
+
it "should be able to authenticate" do
|
268
|
+
should_be_validated @user, "secret"
|
269
|
+
should_be_validated @admin, "admin_secret"
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
describe "using variants in the config file" do
|
275
|
+
before do
|
276
|
+
default_devise_settings!
|
277
|
+
reset_ldap_server!
|
278
|
+
::Devise.ldap_config = Rails.root.join 'config', 'ldap_with_boolean_ssl.yml'
|
279
|
+
end
|
280
|
+
|
281
|
+
it "should not fail if config file has ssl: true" do
|
282
|
+
assert_nothing_raised do
|
283
|
+
Devise::LdapAdapter::LdapConnect.new
|
284
|
+
end
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
describe "use username builder" do
|
289
|
+
before do
|
290
|
+
default_devise_settings!
|
291
|
+
reset_ldap_server!
|
292
|
+
::Devise.ldap_auth_username_builder = Proc.new() do |attribute, login, ldap|
|
293
|
+
"#{attribute}=#{login},ou=others,dc=test,dc=com"
|
294
|
+
end
|
295
|
+
@other = Factory.create(:other)
|
296
|
+
end
|
297
|
+
|
298
|
+
it "should be able to authenticate" do
|
299
|
+
should_be_validated @other, "other_secret"
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
end
|