committing fixes helps sometimes... also more DWIM for typekey
Yuval Kogman [Sat, 26 Nov 2005 03:28:40 +0000 (03:28 +0000)]
lib/Catalyst/Plugin/Authentication/Credential/TypeKey.pm
t/basic.t

index cbdfb5f..cec5b63 100644 (file)
@@ -18,8 +18,8 @@ sub setup {
     my $config = $c->config->{authentication}{typekey} ||= {};
 
     $config->{typekey_object} ||= do {
-        $config->{user_class} ||=
-          "Catalyst::Plugin::Authentication::User::Hash";
+        ( $config->{user_class} ||=
+          "Catalyst::Plugin::Authentication::User::Hash" )->require;
 
         $config->{key_cache} ||=
           File::Spec->catfile( Catalyst::Utils::class2tempdir( $c, 1 ),
@@ -54,13 +54,13 @@ sub authenticate_typekey {
 
         my $user;
 
-        if ( my $store = $config->{auth_store} || $c->default_auth_store ) {
+        if ( my $store = $config->{auth_store} ) {
             $store = $c->get_auth_store($store) unless ref $store;
             $user = $store->get_user( $p, $res );
         }
-        else {
+
+               if ( !$user ) {
             my $user_class = $config->{user_class};
-            $user_class->require or die $@;
             $user = $user_class->new( $res );
         }
 
index 12dd00a..3ec92c0 100644 (file)
--- a/t/basic.t
+++ b/t/basic.t
@@ -7,18 +7,35 @@ use Test::More 'no_plan';
 use Test::MockObject::Extends;
 use Test::MockObject;
 use Test::Exception;
+use Scalar::Util qw/blessed/;
 
 use Catalyst::Plugin::Authentication::User::Hash;
 
 my $m;
 BEGIN { use_ok( $m = "Catalyst::Plugin::Authentication::Credential::TypeKey" ) }
 
+# from 01-verify.t in Authen-TypeKey-0.04
+my %user = (
+       ts    => '1091163746',
+    email => 'bentwo@stupidfool.org',
+    name  => 'Melody',
+    nick  => 'foobar baz',
+);
+
 my $req = Test::MockObject->new;
 $req->set_always( params => {} );
 $req->mock( param => sub { $_[0]->params->{ $_[1] } } );
 
 my $tk = Test::MockObject->new;
-$tk->set_true("verify");
+$tk->mock("verify", sub {
+       my ( $self, $p ) = @_;
+
+       if ( blessed($p) ) {
+               return \%user if ( $p->param("sig") );
+       } else {
+               return \%user if ( $p->{sig} );
+       }
+});
 
 my $store = Test::MockObject->new;
 $store->mock( get_user => sub { shift; Catalyst::Plugin::Authentication::User::Hash->new( @_ ) } );
@@ -51,17 +68,12 @@ lives_ok {
   "can try to auth with no args, no params";
 
 ok( !$c->called("set_authenticated"), "nothing was authenticated" );
-ok( !$tk->called("verify"),           "didn't even verify with no params" );
 
 $_->clear for $c, $tk;
 
-# from 01-verify.t in Authen-TypeKey-0.04
 %{ $req->params } = my %vars = (
-    ts    => '1091163746',
-    email => 'bentwo@stupidfool.org',
-    name  => 'Melody',
-    nick  => 'foobar baz',
-    sig   => 'GWwAIXbkb2xNrQO2e/r2LDl14ek=:U5+tDsPM0+EXeKzFWsosizG7+VU=',
+    %user,
+       sig   => 'GWwAIXbkb2xNrQO2e/r2LDl14ek=:U5+tDsPM0+EXeKzFWsosizG7+VU=',
 );
 
 lives_ok {