add README
[catagits/Catalyst-Authentication-Credential-HTTP-Proxy.git] / t / basic.t
index 3ec92c0..dd1b277 100644 (file)
--- a/t/basic.t
+++ b/t/basic.t
@@ -16,7 +16,7 @@ BEGIN { use_ok( $m = "Catalyst::Plugin::Authentication::Credential::TypeKey" ) }
 
 # from 01-verify.t in Authen-TypeKey-0.04
 my %user = (
-       ts    => '1091163746',
+    ts    => '1091163746',
     email => 'bentwo@stupidfool.org',
     name  => 'Melody',
     nick  => 'foobar baz',
@@ -27,18 +27,23 @@ $req->set_always( params => {} );
 $req->mock( param => sub { $_[0]->params->{ $_[1] } } );
 
 my $tk = Test::MockObject->new;
-$tk->mock("verify", sub {
-       my ( $self, $p ) = @_;
-
-       if ( blessed($p) ) {
-               return \%user if ( $p->param("sig") );
-       } else {
-               return \%user if ( $p->{sig} );
-       }
-});
+$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( @_ ) } );
+$store->mock( get_user =>
+      sub { shift; Catalyst::Plugin::Authentication::User::Hash->new($_[2]) } );
 
 my $c = Test::MockObject::Extends->new($m);
 $c->set_always( config => {} );
@@ -71,10 +76,9 @@ ok( !$c->called("set_authenticated"), "nothing was authenticated" );
 
 $_->clear for $c, $tk;
 
-%{ $req->params } = my %vars = (
-    %user,
-       sig   => 'GWwAIXbkb2xNrQO2e/r2LDl14ek=:U5+tDsPM0+EXeKzFWsosizG7+VU=',
-);
+%{ $req->params } = my %vars =
+  ( %user, sig => 'GWwAIXbkb2xNrQO2e/r2LDl14ek=:U5+tDsPM0+EXeKzFWsosizG7+VU=',
+  );
 
 lives_ok {
     $c->authenticate_typekey;
@@ -96,21 +100,33 @@ lives_ok {
 
 $tk->called_ok("verify");
 $c->called_ok( "set_authenticated", "authenticated" );
-$store->called_ok( "get_user", "user retrieved from store" );
-
+$store->called_ok( "get_user",      "user retrieved from store" );
 
 $_->clear for $c, $tk, $store;
 
 $tk->set_false("verify");
 
-
 lives_ok {
     $c->authenticate_typekey(%vars);
   }
   "can try to auth with args";
 
 $tk->called_ok("verify");
-ok( !$c->called( "set_authenticated" ), "authenticated" );
-ok( !$store->called( "get_user" ), "no user retrieved from store");
+ok( !$c->called("set_authenticated"), "authenticated" );
+ok( !$store->called("get_user"),      "no user retrieved from store" );
+
+$c->logout;
 
+$tk->set_true("verify");
+$c->clear;
+
+ok(
+    $c->authenticate_typekey(
+        my $user = Catalyst::Plugin::Authentication::User::Hash->new(
+            typekey_credentials => { %vars }
+        )
+    ),
+    "can authenticate with user object"
+);
 
+$c->called_ok("set_authenticated");