mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-04 15:01:48 +01:00
Improved reliability of ldap test (somewhat... it's still very environment specific).
Fixed validations in User model. Updated environment.rb.tmpl to be a little easier to follow. A note for upgraders. Be sure to include the following line in your environment.rb: AUTHENTICATION_SCHEMES = ['database'] See environment.rb.tmpl for details git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@337 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
parent
b57765486d
commit
4caca8db70
3 changed files with 32 additions and 4 deletions
|
|
@ -56,10 +56,14 @@ protected
|
|||
def crypt_password
|
||||
write_attribute("password", self.class.sha1(password)) if password == @password_confirmation
|
||||
end
|
||||
|
||||
def password_required?
|
||||
auth_type == 'database'
|
||||
end
|
||||
|
||||
validates_presence_of :login
|
||||
validates_presence_of :password, :if => Proc.new{|user| user.auth_type == 'database'}
|
||||
validates_length_of :password, :within => 5..40
|
||||
validates_presence_of :password, :if => :password_required?
|
||||
validates_length_of :password, :within => 5..40, :if => :password_required?
|
||||
validates_confirmation_of :password
|
||||
validates_length_of :login, :within => 3..80
|
||||
validates_uniqueness_of :login, :on => :create
|
||||
|
|
|
|||
|
|
@ -58,6 +58,10 @@ SALT = "change-me"
|
|||
# e.g. if you are in the Eastern time zone of the US, set the value below.
|
||||
# ENV['TZ'] = 'US/Eastern'
|
||||
|
||||
# Leave this alone or set it to one or more of ['database', 'ldap', 'open_id'].
|
||||
# If you choose ldap, see the additional configuration options further down.
|
||||
AUTHENTICATION_SCHEMES = ['database']
|
||||
|
||||
require 'acts_as_namepart_finder'
|
||||
require 'acts_as_todo_container'
|
||||
require 'config'
|
||||
|
|
@ -67,7 +71,6 @@ ActiveRecord::Base.class_eval do
|
|||
include Tracks::Acts::TodoContainer
|
||||
end
|
||||
|
||||
AUTHENTICATION_SCHEMES = ['database'] #one or more of ['database', 'ldap', 'open_id']
|
||||
if (AUTHENTICATION_SCHEMES.include? 'ldap')
|
||||
require 'net/ldap' #requires ruby-net-ldap gem be installed
|
||||
require 'simple_ldap_authenticator'
|
||||
|
|
|
|||
|
|
@ -2,6 +2,17 @@ require "#{File.dirname(__FILE__)}/../test_helper"
|
|||
require 'tempfile'
|
||||
require 'user'
|
||||
|
||||
module Tracks
|
||||
class Config
|
||||
def self.salt
|
||||
"change-me"
|
||||
end
|
||||
def self.auth_schemes
|
||||
['database','ldap']
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class LdapAuthTest < Test::Unit::TestCase
|
||||
|
||||
fixtures :users
|
||||
|
|
@ -10,6 +21,15 @@ class LdapAuthTest < Test::Unit::TestCase
|
|||
SLAPD_SCHEMA_DIR = "/etc/openldap/schema/" #You may need to adjust this
|
||||
SLAPD_TEST_PORT = 10389
|
||||
OUTPUT_DEBUG_INFO = false
|
||||
|
||||
require 'net/ldap' #requires ruby-net-ldap gem be installed
|
||||
require 'simple_ldap_authenticator'
|
||||
SimpleLdapAuthenticator.ldap_library = 'net/ldap'
|
||||
SimpleLdapAuthenticator.servers = %w'localhost'
|
||||
SimpleLdapAuthenticator.use_ssl = false
|
||||
SimpleLdapAuthenticator.login_format = 'cn=%s,dc=lukemelia,dc=com'
|
||||
SimpleLdapAuthenticator.port = 10389
|
||||
SimpleLdapAuthenticator.logger = RAILS_DEFAULT_LOGGER
|
||||
|
||||
def setup
|
||||
assert_equal "test", ENV['RAILS_ENV']
|
||||
|
|
@ -25,6 +45,7 @@ class LdapAuthTest < Test::Unit::TestCase
|
|||
|
||||
def test_authenticate_against_ldap
|
||||
add_ldap_user_to_ldap_repository
|
||||
assert SimpleLdapAuthenticator.valid?('john', 'deere')
|
||||
user = User.authenticate('john', 'deere')
|
||||
assert_not_nil(user)
|
||||
assert_equal user.login, 'john'
|
||||
|
|
@ -41,7 +62,7 @@ class LdapAuthTest < Test::Unit::TestCase
|
|||
def start_ldap_server
|
||||
t = Thread.new(@slapd_conf.path) { |slapd_conf_path|
|
||||
puts "starting slapd..." if OUTPUT_DEBUG_INFO
|
||||
run_cmd %Q{/usr/libexec/slapd -f #{slapd_conf_path} -h "ldap://127.0.0.1:10389/"}
|
||||
run_cmd %Q{/usr/libexec/slapd -f #{slapd_conf_path} -h "ldap://127.0.0.1:10389/" -d0}
|
||||
}
|
||||
sleep(2)
|
||||
run_cmd %Q{ldapsearch -H "ldap://127.0.0.1:10389/" -x -b '' -s base '(objectclass=*)' namingContexts}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue