LDAP 身份验证是在 Rails 中使用https://github.com/plataformatec/devise/wiki/How-To:-Authenticate-via-LDAP实现的,并且工作正常。
在系统测试期间尝试使用 LDAP http://guides.rubyonrails.org/testing.html#system-testing失败:
Rack app error handling request { POST /login }
#<NoMethodError: undefined method `[]' for nil:NilClass>
.../config/initializers/ldap_authenticatable.rb:92:in `ldap'
.../config/initializers/ldap_authenticatable.rb:60:in `bind_to_ldap'
.../config/initializers/ldap_authenticatable.rb:44:in `authenticate!'
由于ldap.yml文件而发生错误,似乎测试无法从 extern 文件中读取配置。替换 LDAP 参数的解决方法
LDAP_CONFIG = YAML.load_file("#{Rails.root}/config/ldap.yml")[Rails.env]
def ldap
ldap = Net::LDAP.new({
:host => LDAP_CONFIG['host'],
:port => LDAP_CONFIG['port'],
...
和
def ldap
ldap = Net::LDAP.new({
:host => 'ldap.domainname.com',
:port => 636,
...
将避免错误。
请告知这是否是一个错误。