ACL + tests
Yuval Kogman [Wed, 9 Nov 2005 00:09:17 +0000 (00:09 +0000)]
misc fixes for the authen, authz::roles
move dummy session store out of t/lib so that it's reusable

lib/Catalyst/Plugin/Authentication/Credential/Password.pm
lib/Catalyst/Plugin/Authentication/Store/Minimal/Backend.pm
lib/Catalyst/Plugin/Authentication/User/Hash.pm
t/live_app_session.t

index 0b05e18..3e3db2d 100644 (file)
@@ -24,7 +24,7 @@ sub login {
           || Catalyst::Exception->throw("Can't determine password for login");
     }
 
-    $user = $c->get_user($user)
+    $user = $c->get_user($user) || return
       unless Scalar::Util::blessed($user)
       and $user->isa("Catalyst:::Plugin::Authentication::User");
 
index 5eecd3d..7bb0a1c 100644 (file)
@@ -17,10 +17,27 @@ sub new {
 sub get_user {
     my ( $self, $id ) = @_;
 
-       my $user = $self->{hash}{$id};
-
-       bless $user, "Catalyst::Plugin::Authentication::User::Hash"
-         unless Scalar::Util::blessed($user);
+    return unless exists $self->{hash}{$id};
+
+    my $user = $self->{hash}{$id};
+
+    if ( ref $user ) {
+        if ( Scalar::Util::blessed($user) ) {
+            return $user;
+        }
+        elsif ( ref $user eq "HASH" ) {
+            return bless $user, "Catalyst::Plugin::Authentication::User::Hash";
+        }
+        else {
+            Catalyst::Exception->throw( "The user '$id' is a reference of type "
+                  . ref($user)
+                  . " but should be a HASH" );
+        }
+    }
+    else {
+        Catalyst::Exception->throw(
+            "The user '$id' is has to be a hash reference or an object");
+    }
 
     return $user;
 }
index 72a57e8..f7cbe5a 100644 (file)
@@ -9,7 +9,7 @@ use warnings;
 sub new {
     my $class = shift;
 
-    bless {@_}, $class;
+    bless { @_ }, $class;
 }
 
 sub AUTOLOAD {
@@ -22,7 +22,9 @@ sub AUTOLOAD {
     }
 
     my $data = $self->{$key};
-    $self->{__hash_obj_key_is_array}{$key} ? @$data : $data;
+    ( $self->{__hash_obj_key_is_array}{$key} || $key =~ /roles/ )
+      ? @$data
+      : $data;
 }
 
 my %features = (
index cb97025..3ebc3d0 100644 (file)
@@ -7,11 +7,8 @@ use Test::More;
 
 BEGIN {
        eval { require Catalyst::Plugin::Session; require Catalyst::Plugin::Session::State::Cookie };
-       if ($@) {
-               plan skip_all => "This test needs Catalyst::Plugin::Session and Catalyst::Plugin::Session::State::Cookie installed";
-       } else {
-               plan tests => 12;
-       }
+       plan skip_all => "This test needs Catalyst::Plugin::Session and Catalyst::Plugin::Session::State::Cookie installed" if $@;
+       plan tests => 12;
 }
 
 {