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] } );
58 $c->mock( logout => sub { undef $authenticated } );
60 can_ok( $m, "setup" );
64 isa_ok( $config->{typekey_object},
65 "Authen::TypeKey", '$c->config->{authentication}{typekey}{obj}' );
67 $config->{typekey_object} = $tk;
69 can_ok( $m, "authenticate_typekey" );
72 $c->authenticate_typekey;
74 "can try to auth with no args, no params";
76 ok( !$c->called("set_authenticated"), "nothing was authenticated" );
78 $_->clear for $c, $tk;
80 %{ $req->params } = my %vars =
81 ( %user, sig => 'GWwAIXbkb2xNrQO2e/r2LDl14ek=:U5+tDsPM0+EXeKzFWsosizG7+VU=',
85 $c->authenticate_typekey;
87 "can try to auth, no args, all params";
89 $tk->called_ok("verify");
90 $c->called_ok( "set_authenticated", "authenticated" );
92 $_->clear for $c, $tk;
94 %{ $req->params } = ();
95 $config->{auth_store} = $store;
98 $c->authenticate_typekey(%vars);
100 "can try to auth with args";
102 $tk->called_ok("verify");
103 $c->called_ok( "set_authenticated", "authenticated" );
104 $store->called_ok( "get_user", "user retrieved from store" );
106 $_->clear for $c, $tk, $store;
108 $tk->set_false("verify");
111 $c->authenticate_typekey(%vars);
113 "can try to auth with args";
115 $tk->called_ok("verify");
116 ok( !$c->called("set_authenticated"), "authenticated" );
117 ok( !$store->called("get_user"), "no user retrieved from store" );
121 $tk->set_true("verify");
125 $c->authenticate_typekey(
126 my $user = Catalyst::Plugin::Authentication::User::Hash->new(
127 typekey_credentials => { %vars }
130 "can authenticate with user object"
133 $c->called_ok("set_authenticated");