Revision b7f90cc0
Added by Stephen Benjamin about 10 years ago
app/models/auth_sources/auth_source_ldap.rb | ||
---|---|---|
|
||
def attributes_values entry
|
||
Hash[required_ldap_attributes.merge(optional_ldap_attributes).map do |name, value|
|
||
next if entry[value].empty? and optional_ldap_attributes.keys.include? name
|
||
next if value.blank? || (entry[value].blank? && optional_ldap_attributes.keys.include?(name))
|
||
if name.eql? :avatar
|
||
[:avatar_hash, store_avatar(entry[value].first)]
|
||
else
|
test/unit/auth_source_ldap_test.rb | ||
---|---|---|
assert_equal 'LDAP', @auth_source_ldap.auth_method_name
|
||
end
|
||
|
||
test "ldap user should be able to login" do
|
||
# stubs out all the actual ldap connectivity, but tests the authenticate
|
||
# method of auth_source_ldap
|
||
setup_ldap_stubs
|
||
assert_not_nil AuthSourceLdap.authenticate("test123", "changeme")
|
||
end
|
||
|
||
def setup_ldap_stubs
|
||
# stub out all the LDAP connectivity
|
||
entry = Net::LDAP::Entry.new
|
||
{:givenname=>["test"], :dn=>["uid=test123,cn=users,cn=accounts,dc=example,dc=com"], :mail=>["test123@example.com"], :sn=>["test"]}.each do |k, v|
|
||
entry[k] = v
|
||
end
|
||
AuthSourceLdap.any_instance.stubs(:initialize_ldap_con).returns(stub(:bind => true))
|
||
AuthSourceLdap.any_instance.stubs(:search_for_user_entries).returns(entry)
|
||
end
|
||
|
||
def missing(attr)
|
||
@attributes.each { |k, v| @auth_source_ldap.send k, v unless k == attr }
|
||
end
|
Also available in: Unified diff
fixes #4643 - Retrieving Optional LDAP attributes fails on 1.8.7