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;
30 $tk->mock("verify", sub {
31 my ( $self, $p ) = @_;
34 return \%user if ( $p->param("sig") );
36 return \%user if ( $p->{sig} );
40 my $store = Test::MockObject->new;
41 $store->mock( get_user => sub { shift; Catalyst::Plugin::Authentication::User::Hash->new( @_ ) } );
43 my $c = Test::MockObject::Extends->new($m);
44 $c->set_always( config => {} );
45 my $config = $c->config->{authentication}{typekey} ||= {};
47 $c->set_always( req => $req );
48 $c->set_always( request => $req );
49 $c->set_false("debug");
52 $c->mock( set_authenticated => sub { $authenticated = $_[1] } );
54 can_ok( $m, "setup" );
58 isa_ok( $config->{typekey_object},
59 "Authen::TypeKey", '$c->config->{authentication}{typekey}{obj}' );
61 $config->{typekey_object} = $tk;
63 can_ok( $m, "authenticate_typekey" );
66 $c->authenticate_typekey;
68 "can try to auth with no args, no params";
70 ok( !$c->called("set_authenticated"), "nothing was authenticated" );
72 $_->clear for $c, $tk;
74 %{ $req->params } = my %vars = (
76 sig => 'GWwAIXbkb2xNrQO2e/r2LDl14ek=:U5+tDsPM0+EXeKzFWsosizG7+VU=',
80 $c->authenticate_typekey;
82 "can try to auth, no args, all params";
84 $tk->called_ok("verify");
85 $c->called_ok( "set_authenticated", "authenticated" );
87 $_->clear for $c, $tk;
89 %{ $req->params } = ();
90 $config->{auth_store} = $store;
93 $c->authenticate_typekey(%vars);
95 "can try to auth with args";
97 $tk->called_ok("verify");
98 $c->called_ok( "set_authenticated", "authenticated" );
99 $store->called_ok( "get_user", "user retrieved from store" );
102 $_->clear for $c, $tk, $store;
104 $tk->set_false("verify");
108 $c->authenticate_typekey(%vars);
110 "can try to auth with args";
112 $tk->called_ok("verify");
113 ok( !$c->called( "set_authenticated" ), "authenticated" );
114 ok( !$store->called( "get_user" ), "no user retrieved from store");