From 09043dd74d17a4652305cfafb305fdd90c451742 Mon Sep 17 00:00:00 2001 From: Rashit Azizbaev Date: Wed, 4 Jul 2012 02:07:15 +0400 Subject: [PATCH 1/3] Added Net::LDAP::Entry object to strategies test Conflicts: spec/omniauth/strategies/ldap_spec.rb --- spec/omniauth/strategies/ldap_spec.rb | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/spec/omniauth/strategies/ldap_spec.rb b/spec/omniauth/strategies/ldap_spec.rb index 01a48bb..96a9182 100644 --- a/spec/omniauth/strategies/ldap_spec.rb +++ b/spec/omniauth/strategies/ldap_spec.rb @@ -83,10 +83,25 @@ def session context 'success' do let(:auth_hash){ last_request.env['omniauth.auth'] } before(:each) do - @adaptor.stub(:bind_as).and_return({:dn => ['cn=ping, dc=intridea, dc=com'], :mail => ['ping@intridea.com'], :givenname => ['Ping'], :sn => ['Yu'], - :telephonenumber => ['555-555-5555'], :mobile => ['444-444-4444'], :uid => ['ping'], :title => ['dev'], :address =>[ 'k street'], - :l => ['Washington'], :st => ['DC'], :co => ["U.S.A"], :postofficebox => ['20001'], :wwwhomepage => ['www.intridea.com'], - :jpegphoto => ['http://www.intridea.com/ping.jpg'], :description => ['omniauth-ldap']}) + @adaptor.stub(:bind_as).and_return(Net::LDAP::Entry.from_single_ldif_string( + %Q{dn: cn=ping, dc=intridea, dc=com +mail: ping@intridea.com +givenname: Ping +sn: Yu +telephonenumber: 555-555-5555 +mobile: 444-444-4444 +uid: ping +title: dev +address: k street +l: Washington +st: DC +co: U.S.A +postofficebox: 20001 +wwwhomepage: www.intridea.com +jpegphoto: http://www.intridea.com/ping.jpg +description: omniauth-ldap +} + )) post('/auth/ldap/callback', {:username => 'ping', :password => 'password'}) end From abffe08d457d1b4479639ac0ebf0f3e7f51a735a Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Fri, 31 Jan 2014 09:30:40 +0100 Subject: [PATCH 2/3] Change LDAP test data to trigger a lookup error The first email attribute we check for is 'mail', then 'email'. By returning an 'email' attribute in the test response we trigger the fallback to the second attribute. This makes a test fail. --- spec/omniauth/strategies/ldap_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/omniauth/strategies/ldap_spec.rb b/spec/omniauth/strategies/ldap_spec.rb index 96a9182..28347fe 100644 --- a/spec/omniauth/strategies/ldap_spec.rb +++ b/spec/omniauth/strategies/ldap_spec.rb @@ -85,7 +85,7 @@ def session before(:each) do @adaptor.stub(:bind_as).and_return(Net::LDAP::Entry.from_single_ldif_string( %Q{dn: cn=ping, dc=intridea, dc=com -mail: ping@intridea.com +email: ping@intridea.com givenname: Ping sn: Yu telephonenumber: 555-555-5555 From e8a50e5f76e2a70d71fc42c89cf7be70553655a7 Mon Sep 17 00:00:00 2001 From: Rashit Azizbaev Date: Wed, 4 Jul 2012 02:11:21 +0400 Subject: [PATCH 3/3] Added respond_to? check to user mapping function Net::LDAP::Entry returns empty array if key not exists, so we should check for key with respond_to? --- lib/omniauth/strategies/ldap.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/omniauth/strategies/ldap.rb b/lib/omniauth/strategies/ldap.rb index c28628d..479340b 100644 --- a/lib/omniauth/strategies/ldap.rb +++ b/lib/omniauth/strategies/ldap.rb @@ -70,14 +70,14 @@ def self.map_user(mapper, object) mapper.each do |key, value| case value when String - user[key] = object[value.downcase.to_sym].first if object[value.downcase.to_sym] + user[key] = object[value.downcase.to_sym].first if object.respond_to? value.downcase.to_sym when Array - value.each {|v| (user[key] = object[v.downcase.to_sym].first; break;) if object[v.downcase.to_sym]} + value.each {|v| (user[key] = object[v.downcase.to_sym].first; break;) if object.respond_to? v.downcase.to_sym} when Hash value.map do |key1, value1| pattern = key1.dup value1.each_with_index do |v,i| - part = ''; v.collect(&:downcase).collect(&:to_sym).each {|v1| (part = object[v1].first; break;) if object[v1]} + part = ''; v.collect(&:downcase).collect(&:to_sym).each {|v1| (part = object[v1].first; break;) if object.respond_to? v1} pattern.gsub!("%#{i}",part||'') end user[key] = pattern