spec/omniauth/strategies/ldap_spec.rb in omniauth-ldap-1.0.4 vs spec/omniauth/strategies/ldap_spec.rb in omniauth-ldap-1.0.5

- old
+ new

@@ -48,10 +48,11 @@ end describe 'post /auth/ldap/callback' do before(:each) do @adaptor = double(OmniAuth::LDAP::Adaptor, {:uid => 'ping'}) + @adaptor.stub(:filter) OmniAuth::LDAP::Adaptor.stub(:new).and_return(@adaptor) end context 'failure' do before(:each) do @@ -102,10 +103,21 @@ post('/auth/ldap/callback', {:username => 'ping', :password => 'password'}) last_response.should be_redirect last_response.headers['Location'].should =~ %r{invalid_credentials} end + context 'and filter is set' do + it 'should bind with filter' do + @adaptor.stub(:filter).and_return('uid=%{username}') + Net::LDAP::Filter.should_receive(:construct).with('uid=ping') + post('/auth/ldap/callback', {:username => 'ping', :password => 'password'}) + + last_response.should be_redirect + last_response.headers['Location'].should =~ %r{invalid_credentials} + end + end + end context "and communication with LDAP server caused an exception" do before :each do @adaptor.stub(:bind_as).and_throw(Exception.new('connection_error')) @@ -123,10 +135,11 @@ context 'success' do let(:auth_hash){ last_request.env['omniauth.auth'] } before(:each) do + @adaptor.stub(:filter) @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 @@ -142,17 +155,28 @@ wwwhomepage: www.intridea.com jpegphoto: http://www.intridea.com/ping.jpg description: omniauth-ldap } )) - post('/auth/ldap/callback', {:username => 'ping', :password => 'password'}) end it 'should not redirect to error page' do + post('/auth/ldap/callback', {:username => 'ping', :password => 'password'}) last_response.should_not be_redirect end + context 'and filter is set' do + it 'should bind with filter' do + @adaptor.stub(:filter).and_return('uid=%{username}') + Net::LDAP::Filter.should_receive(:construct).with('uid=ping') + post('/auth/ldap/callback', {:username => 'ping', :password => 'password'}) + + last_response.should_not be_redirect + end + end + it 'should map user info to Auth Hash' do + post('/auth/ldap/callback', {:username => 'ping', :password => 'password'}) auth_hash.uid.should == 'cn=ping, dc=intridea, dc=com' auth_hash.info.email.should == 'ping@intridea.com' auth_hash.info.first_name.should == 'Ping' auth_hash.info.last_name.should == 'Yu' auth_hash.info.phone.should == '555-555-5555'