6 use Test::More 'no_plan';
7 use Test::MockObject::Extends;
11 use Catalyst::Plugin::Authentication::User::Hash;
14 BEGIN { use_ok( $m = "Catalyst::Plugin::Authentication::Credential::TypeKey" ) }
16 my $req = Test::MockObject->new;
17 $req->set_always( params => {} );
18 $req->mock( param => sub { $_[0]->params->{ $_[1] } } );
20 my $tk = Test::MockObject->new;
21 $tk->set_true("verify");
23 my $store = Test::MockObject->new;
24 $store->mock( get_user => sub { shift; Catalyst::Plugin::Authentication::User::Hash->new( @_ ) } );
26 my $c = Test::MockObject::Extends->new($m);
27 $c->set_always( config => {} );
28 my $config = $c->config->{authentication}{typekey} ||= {};
30 $c->set_always( req => $req );
31 $c->set_always( request => $req );
32 $c->set_false("debug");
35 $c->mock( set_authenticated => sub { $authenticated = $_[1] } );
37 can_ok( $m, "setup" );
41 isa_ok( $config->{typekey_object},
42 "Authen::TypeKey", '$c->config->{authentication}{typekey}{obj}' );
44 $config->{typekey_object} = $tk;
46 can_ok( $m, "authenticate_typekey" );
49 $c->authenticate_typekey;
51 "can try to auth with no args, no params";
53 ok( !$c->called("set_authenticated"), "nothing was authenticated" );
54 ok( !$tk->called("verify"), "didn't even verify with no params" );
56 $_->clear for $c, $tk;
58 # from 01-verify.t in Authen-TypeKey-0.04
59 %{ $req->params } = my %vars = (
61 email => 'bentwo@stupidfool.org',
64 sig => 'GWwAIXbkb2xNrQO2e/r2LDl14ek=:U5+tDsPM0+EXeKzFWsosizG7+VU=',
68 $c->authenticate_typekey;
70 "can try to auth, no args, all params";
72 $tk->called_ok("verify");
73 $c->called_ok( "set_authenticated", "authenticated" );
75 $_->clear for $c, $tk;
77 %{ $req->params } = ();
78 $config->{auth_store} = $store;
81 $c->authenticate_typekey(%vars);
83 "can try to auth with args";
85 $tk->called_ok("verify");
86 $c->called_ok( "set_authenticated", "authenticated" );
87 $store->called_ok( "get_user", "user retrieved from store" );
90 $_->clear for $c, $tk, $store;
92 $tk->set_false("verify");
96 $c->authenticate_typekey(%vars);
98 "can try to auth with args";
100 $tk->called_ok("verify");
101 ok( !$c->called( "set_authenticated" ), "authenticated" );
102 ok( !$store->called( "get_user" ), "no user retrieved from store");