[Catalyst-commits] r13395 - in Catalyst-Authentication-Store-LDAP/trunk: . lib/Catalyst/Authentication/Store/LDAP t

t0m at dev.catalyst.perl.org t0m at dev.catalyst.perl.org
Tue Jul 6 20:32:05 GMT 2010


Author: t0m
Date: 2010-07-06 21:32:05 +0100 (Tue, 06 Jul 2010)
New Revision: 13395

Added:
   Catalyst-Authentication-Store-LDAP/trunk/t/05-user_attributes.t
Modified:
   Catalyst-Authentication-Store-LDAP/trunk/Changes
   Catalyst-Authentication-Store-LDAP/trunk/lib/Catalyst/Authentication/Store/LDAP/User.pm
Log:
Fix RT#56710

Modified: Catalyst-Authentication-Store-LDAP/trunk/Changes
===================================================================
--- Catalyst-Authentication-Store-LDAP/trunk/Changes	2010-07-06 09:53:49 UTC (rev 13394)
+++ Catalyst-Authentication-Store-LDAP/trunk/Changes	2010-07-06 20:32:05 UTC (rev 13395)
@@ -1,3 +1,11 @@
+has_attribute has a special case for 'dn' using the underlying ldap_entry
+
+  - Make AUTOLOAD method work for ->dn by generically calling has_attribute
+    which has a special case for it.
+  - Unify the handling of the ->username method between AUTOLOAD and
+    has_attribute by special casing it more generically in has_attribute.
+    Both RT#57610, patch and tests by Jason Fried
+
 1.009  15 May 2010
    - Fix pod for get_user() and from_session() in Backend.pm, adding
      the missing $c param. Pass $c in from_session() through to get_user().

Modified: Catalyst-Authentication-Store-LDAP/trunk/lib/Catalyst/Authentication/Store/LDAP/User.pm
===================================================================
--- Catalyst-Authentication-Store-LDAP/trunk/lib/Catalyst/Authentication/Store/LDAP/User.pm	2010-07-06 09:53:49 UTC (rev 13394)
+++ Catalyst-Authentication-Store-LDAP/trunk/lib/Catalyst/Authentication/Store/LDAP/User.pm	2010-07-06 20:32:05 UTC (rev 13395)
@@ -228,6 +228,9 @@
     if ( $attribute eq "dn" ) {
         return $self->ldap_entry->dn;
     }
+    elsif ( $attribute eq "username" ) {
+       return $self->user->{'attributes'}->{$self->store->user_field};
+    }
     elsif ( exists( $self->user->{'attributes'}->{$attribute} ) ) {
         return $self->user->{'attributes'}->{$attribute};
     }
@@ -302,21 +305,10 @@
     if ( $method eq "DESTROY" ) {
         return;
     }
-    if ( exists( $self->user->{'attributes'}->{$method} ) ) {
-        return $self->user->{'attributes'}->{$method};
+
+    if ( my $attribute = $self->has_attribute($method) ) {
+        return $attribute;
     }
-    elsif ( $method eq "username" ) {
-        my $userfield = $self->store->user_field;
-        my $username  = $self->has_attribute($userfield);
-        if ($username) {
-            return $username;
-        }
-        else {
-            Catalyst::Exception->throw( "User is missing the "
-                    . $userfield
-                    . " attribute, which should not be possible!" );
-        }
-    }
     else {
         Catalyst::Exception->throw(
             "No attribute $method for User " . $self->stringify );

Added: Catalyst-Authentication-Store-LDAP/trunk/t/05-user_attributes.t
===================================================================
--- Catalyst-Authentication-Store-LDAP/trunk/t/05-user_attributes.t	                        (rev 0)
+++ Catalyst-Authentication-Store-LDAP/trunk/t/05-user_attributes.t	2010-07-06 20:32:05 UTC (rev 13395)
@@ -0,0 +1,53 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use Catalyst::Exception;
+
+use Test::More tests => 9;
+use lib 't/lib';
+use LDAPTest;
+
+SKIP: {
+
+    eval "use Catalyst::Model::LDAP";
+    if ($@) {
+        skip "Catalyst::Model::LDAP not installed", 6;
+    }
+
+    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(),
+            'binddn'      => 'anonymous',
+            'bindpw'      => 'dontcarehow',
+            'start_tls'   => 0,
+            'user_basedn' => 'ou=foobar',
+            'user_filter' => '(&(objectClass=person)(uid=%s))',
+            'user_scope'  => 'one',
+            'user_field'  => 'uid',
+            'use_roles'   => 0,
+            'entry_class' => 'EntryClass',
+        }
+    );
+
+    isa_ok( $back, "Catalyst::Authentication::Store::LDAP::Backend" );
+    my $user = $back->find_user( { username => 'somebody' } );
+    isa_ok( $user, "Catalyst::Authentication::Store::LDAP::User" );
+
+    #Check DN
+    ok $user->dn,"Get DN from AUTOLOAD"; #THIS ONLY WORKS BECAUSE dn is included as a user attribute in the test LDAP server.
+    ok defined $user->has_attribute('dn'),"Get dn from has_attribute";
+
+    #Check Username
+    ok $user->username, "Get username from AUTOLOAD";
+    ok defined $user->has_attribute('username'),"Get username from has_attribute";
+
+    #Make sure both methods match output
+    ok $user->username eq $user->has_attribute('username'),"username from AUTOLOAD and has_attribute should match";
+    ok $user->dn eq $user->has_attribute('dn'),"dn from AUTOLOAD and has_attribute should match";
+
+
+}




More information about the Catalyst-commits mailing list