Subject: | lookup_user chokes on array in user_field |
user_field can, according to the documentation, be an array of fields
that can be the userid. This chokes in lookup_user with:
"LDAP claims 'ARRAY0xBEEFCAKE' equals 'some_user_id' but results entry
does not match."
the attached patch includes a test-case for this, and a patch to
lookup_user to check each of the userfields if user_fields is an array.
If you need it some other way, or better tests or whatever, let me know.
Subject: | catalyst-authentication-store-ldap-array-user-field.01.diff |
diff -urN Catalyst-Authentication-Store-LDAP-0.1000.orig/lib/Catalyst/Authentication/Store/LDAP/Backend.pm Catalyst-Authentication-Store-LDAP-0.1000/lib/Catalyst/Authentication/Store/LDAP/Backend.pm
--- Catalyst-Authentication-Store-LDAP-0.1000.orig/lib/Catalyst/Authentication/Store/LDAP/Backend.pm 2008-02-13 07:52:05.000000000 +0100
+++ Catalyst-Authentication-Store-LDAP-0.1000/lib/Catalyst/Authentication/Store/LDAP/Backend.pm 2008-02-13 07:55:42.000000000 +0100
@@ -315,10 +315,25 @@
# a little extra sanity check with the 'eq' since LDAP already
# says it matches.
if ( defined($entry) ) {
- unless ( $entry->get_value($user_field) eq $id ) {
- Catalyst::Exception->throw(
- "LDAP claims '$user_field' equals '$id' but results entry does not match."
- );
+ if (ref($user_field) eq 'ARRAY') {
+ # userfield can be an array, lets check each one
+ my $match = 0;
+ foreach my $f (@$user_field) {
+ if ($entry->get_value($f) eq $id) {
+ $match = 1;
+ }
+ }
+ unless ($match) {
+ Catalyst::Exception->throw(
+ "LDAP claims '$user_field' equals '$id' but results entry does not match."
+ );
+ }
+ } else {
+ unless ( $entry->get_value($user_field) eq $id ) {
+ Catalyst::Exception->throw(
+ "LDAP claims '$user_field' equals '$id' but results entry does not match."
+ );
+ }
}
$userentry = $entry;
}
diff -urN Catalyst-Authentication-Store-LDAP-0.1000.orig/t/04-array_user_field.t Catalyst-Authentication-Store-LDAP-0.1000/t/04-array_user_field.t
--- Catalyst-Authentication-Store-LDAP-0.1000.orig/t/04-array_user_field.t 1970-01-01 01:00:00.000000000 +0100
+++ Catalyst-Authentication-Store-LDAP-0.1000/t/04-array_user_field.t 2008-02-13 07:54:19.000000000 +0100
@@ -0,0 +1,37 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use Catalyst::Exception;
+
+use Test::More tests => 5;
+use lib 't/lib';
+use LDAPTest;
+my $server = LDAPTest::spawn_server();
+
+use_ok("Catalyst::Authentication::Store::LDAP::Backend");
+
+my $back = Catalyst::Authentication::Store::LDAP::Backend->new(
+ { 'ldap_server' => LDAPTest::server_host(),
+
+ # can test the timeout SKIP with this
+ 'ldap_server_options' =>
+ { timeout => -1, debug => $ENV{PERL_DEBUG} || 0 },
+
+ 'binddn' => 'anonymous',
+ 'bindpw' => 'dontcarehow',
+ 'start_tls' => 0,
+ 'user_basedn' => 'ou=foobar',
+ 'user_filter' => '(&(objectClass=person)(uid=%s))',
+ 'user_scope' => 'one',
+ 'user_field' => [qw(uid displayName)],
+ 'use_roles' => 0,
+ }
+);
+
+isa_ok( $back, "Catalyst::Authentication::Store::LDAP::Backend" );
+ok( my $user = $back->find_user( { username => 'somebody' } ), "find_user" );
+isa_ok( $user, "Catalyst::Authentication::Store::LDAP::User" );
+my $displayname = $user->displayname;
+cmp_ok( $displayname, 'eq', 'Some Body', 'Should be Some Body' );
+