From: Peter Karman Date: Fri, 1 May 2009 02:33:43 +0000 (+0000) Subject: release 0.1005 X-Git-Tag: v0.1005^0 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d94851da6ba1c489ebd20d159c0df06c332b3687;p=catagits%2FCatalyst-Authentication-Store-LDAP.git release 0.1005 --- diff --git a/Changes b/Changes index f31808c..d7402ea 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,7 @@ +0.1005 30 April 2009 + - Stop throwing an exception when the lookup_user method fails + to find a user and instead return undef. (t0m) + - Add tests for above (t0m) - Change documentation which still refers to the old ::Plugin:: style auth system to use ->authenticate instead of ->login, and not say that you need to do things manually to have multiple stores. (t0m) diff --git a/Makefile.PL b/Makefile.PL index 9b041d9..8fa0f37 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -13,6 +13,7 @@ requires( 'Catalyst::Plugin::Authentication' => '0.10003' ); build_requires('Net::LDAP::Server::Test' => '0.07'); build_requires('Test::More'); build_requires('Test::MockObject'); +build_required('Test::Exception'); auto_install(); diff --git a/lib/Catalyst/Authentication/Store/LDAP.pm b/lib/Catalyst/Authentication/Store/LDAP.pm index bc558e2..7070f8c 100644 --- a/lib/Catalyst/Authentication/Store/LDAP.pm +++ b/lib/Catalyst/Authentication/Store/LDAP.pm @@ -3,7 +3,7 @@ package Catalyst::Authentication::Store::LDAP; use strict; use warnings; -our $VERSION = '0.1004'; +our $VERSION = '0.1005'; use Catalyst::Authentication::Store::LDAP::Backend; diff --git a/lib/Catalyst/Authentication/Store/LDAP/Backend.pm b/lib/Catalyst/Authentication/Store/LDAP/Backend.pm index 5ae20ce..80aad95 100644 --- a/lib/Catalyst/Authentication/Store/LDAP/Backend.pm +++ b/lib/Catalyst/Authentication/Store/LDAP/Backend.pm @@ -72,7 +72,7 @@ use base qw( Class::Accessor::Fast ); use strict; use warnings; -our $VERSION = '0.1004'; +our $VERSION = '0.1005'; use Catalyst::Authentication::Store::LDAP::User; use Net::LDAP; @@ -255,11 +255,12 @@ Given a User ID, this method will: A) Bind to the directory using the configured binddn and bindpw B) Perform a search for the User Object in the directory, using user_basedn, user_filter, and user_scope. - C) Assuming we found the object, we will walk it's attributes + C) Assuming we found the object, we will walk it's attributes using L's get_value method. We store the - results in a hashref. - D) Return a hashref that looks like: - + results in a hashref. If we do not find the object, then + undef is returned. + D) Return a hashref that looks like: + $results = { 'ldap_entry' => $entry, # The Net::LDAP::Entry object 'attributes' => $attributes, @@ -292,10 +293,9 @@ sub lookup_user { push( @searchopts, %{ $self->user_search_options } ); } my $usersearch = $ldap->search(@searchopts); - if ( $usersearch->is_error ) { - Catalyst::Exception->throw( - "LDAP Error while searching for user: " . $usersearch->error ); - } + + return if ( $usersearch->is_error ); + my $userentry; my $user_field = $self->user_field; my $results_filter = $self->user_results_filter; diff --git a/lib/Catalyst/Authentication/Store/LDAP/User.pm b/lib/Catalyst/Authentication/Store/LDAP/User.pm index aa40d03..219576e 100644 --- a/lib/Catalyst/Authentication/Store/LDAP/User.pm +++ b/lib/Catalyst/Authentication/Store/LDAP/User.pm @@ -49,7 +49,7 @@ use base qw( Catalyst::Authentication::User Class::Accessor::Fast ); use strict; use warnings; -our $VERSION = '0.1004'; +our $VERSION = '0.1005'; BEGIN { __PACKAGE__->mk_accessors(qw/user store/) } diff --git a/t/10-roles-mock.t b/t/10-roles-mock.t index d79a533..359e76e 100644 --- a/t/10-roles-mock.t +++ b/t/10-roles-mock.t @@ -4,8 +4,9 @@ use strict; use warnings; use Catalyst::Exception; -use Test::More tests => 7; +use Test::More tests => 11; use Test::MockObject::Extends; +use Test::Exception; use Net::LDAP::Entry; use lib 't/lib'; @@ -13,7 +14,7 @@ SKIP: { eval "use Catalyst::Model::LDAP"; if ($@) { - skip "Catalyst::Model::LDAP not installed", 7; + skip "Catalyst::Model::LDAP not installed", 11; } use_ok("Catalyst::Authentication::Store::LDAP::Backend"); @@ -46,7 +47,8 @@ SKIP: { $ldap->mock('unbind' => sub {}); $ldap->mock('disconnect' => sub {}); my $search_res = Test::MockObject->new(); - $search_res->mock(is_error => sub {}); # Never an error + my $search_is_error = 0; + $search_res->mock(is_error => sub { $search_is_error }); $search_res->mock(entries => sub { return map { my $id = $_; @@ -73,12 +75,21 @@ SKIP: { is_deeply( [sort $user->roles], [sort qw/quuxone quuxtwo/], "User has the expected set of roles" ); + + $search_is_error = 1; + lives_ok { + ok !$back->find_user( { username => 'doesnotexist' } ), + 'Nonexistent user returns undef'; + } 'No exception thrown for nonexistent user'; + } is_deeply(\@searches, [ ['base', 'ou=foobar', 'filter', '(&(objectClass=inetOrgPerson)(uid=somebody))', 'scope', 'one'], ['base', 'ou=roles', 'filter', '(&(objectClass=posixGroup)(memberUid=test))', 'scope', 'one', 'attrs', [ 'userinrole' ]], + ['base', 'ou=foobar', 'filter', '(&(objectClass=inetOrgPerson)(uid=doesnotexist))', 'scope', 'one'], ['base', 'ou=foobar', 'filter', '(&(objectClass=inetOrgPerson)(uid=somebody))', 'scope', 'one'], ['base', 'ou=roles', 'filter', '(&(objectClass=posixGroup)(memberUid=test))', 'scope', 'one', 'attrs', [ 'userinrole' ]], + ['base', 'ou=foobar', 'filter', '(&(objectClass=inetOrgPerson)(uid=doesnotexist))', 'scope', 'one'], ], 'User searches as expected'); is_deeply(\@binds, [ [ undef ], # First user search @@ -90,12 +101,14 @@ SKIP: { [ undef ], # Rebind with initial credentials to find roles + [ undef ], # Second user search # 2nd pass round main loop [ undef ], # First user search [ 'ou=foobar', 'password', 'password' - ] # Rebind to confirm user _and_ lookup roles; + ], # Rebind to confirm user _and_ lookup roles; + [ undef ], # Second user search ], 'Binds as expected'); }