6 use Test::More 'no_plan';
7 use Test::MockObject::Extends;
10 use Scalar::Util qw/blessed/;
12 use Catalyst::Plugin::Authentication::User::Hash;
15 BEGIN { use_ok( $m = "Catalyst::Plugin::Authentication::Credential::TypeKey" ) }
17 # from 01-verify.t in Authen-TypeKey-0.04
20 email => 'bentwo@stupidfool.org',
25 my $req = Test::MockObject->new;
26 $req->set_always( params => {} );
27 $req->mock( param => sub { $_[0]->params->{ $_[1] } } );
29 my $tk = Test::MockObject->new;
33 my ( $self, $p ) = @_;
36 return \%user if ( $p->param("sig") );
39 return \%user if ( $p->{sig} );
44 my $store = Test::MockObject->new;
45 $store->mock( get_user =>
46 sub { shift; Catalyst::Plugin::Authentication::User::Hash->new($_[2]) } );
48 my $c = Test::MockObject::Extends->new($m);
49 $c->set_always( config => {} );
50 my $config = $c->config->{authentication}{typekey} ||= {};
52 $c->set_always( req => $req );
53 $c->set_always( request => $req );
54 $c->set_false("debug");
57 $c->mock( set_authenticated => sub { $authenticated = $_[1] } );
59 can_ok( $m, "setup" );
63 isa_ok( $config->{typekey_object},
64 "Authen::TypeKey", '$c->config->{authentication}{typekey}{obj}' );
66 $config->{typekey_object} = $tk;
68 can_ok( $m, "authenticate_typekey" );
71 $c->authenticate_typekey;
73 "can try to auth with no args, no params";
75 ok( !$c->called("set_authenticated"), "nothing was authenticated" );
77 $_->clear for $c, $tk;
79 %{ $req->params } = my %vars =
80 ( %user, sig => 'GWwAIXbkb2xNrQO2e/r2LDl14ek=:U5+tDsPM0+EXeKzFWsosizG7+VU=',
84 $c->authenticate_typekey;
86 "can try to auth, no args, all params";
88 $tk->called_ok("verify");
89 $c->called_ok( "set_authenticated", "authenticated" );
91 $_->clear for $c, $tk;
93 %{ $req->params } = ();
94 $config->{auth_store} = $store;
97 $c->authenticate_typekey(%vars);
99 "can try to auth with args";
101 $tk->called_ok("verify");
102 $c->called_ok( "set_authenticated", "authenticated" );
103 $store->called_ok( "get_user", "user retrieved from store" );
105 $_->clear for $c, $tk, $store;
107 $tk->set_false("verify");
110 $c->authenticate_typekey(%vars);
112 "can try to auth with args";
114 $tk->called_ok("verify");
115 ok( !$c->called("set_authenticated"), "authenticated" );
116 ok( !$store->called("get_user"), "no user retrieved from store" );
120 $tk->set_true("verify");
124 $c->authenticate_typekey(
125 my $user = Catalyst::Plugin::Authentication::User::Hash->new(
126 typekey_credentials => { %vars }
129 "can authenticate with user object"
132 $c->called_ok("set_authenticated");