my $config = $c->config->{authentication}{typekey} ||= {};
$config->{typekey_object} ||= do {
- $config->{user_class} ||=
- "Catalyst::Plugin::Authentication::User::Hash";
+ ( $config->{user_class} ||=
+ "Catalyst::Plugin::Authentication::User::Hash" )->require;
$config->{key_cache} ||=
File::Spec->catfile( Catalyst::Utils::class2tempdir( $c, 1 ),
my $user;
- if ( my $store = $config->{auth_store} || $c->default_auth_store ) {
+ if ( my $store = $config->{auth_store} ) {
$store = $c->get_auth_store($store) unless ref $store;
$user = $store->get_user( $p, $res );
}
- else {
+
+ if ( !$user ) {
my $user_class = $config->{user_class};
- $user_class->require or die $@;
$user = $user_class->new( $res );
}
use Test::MockObject::Extends;
use Test::MockObject;
use Test::Exception;
+use Scalar::Util qw/blessed/;
use Catalyst::Plugin::Authentication::User::Hash;
my $m;
BEGIN { use_ok( $m = "Catalyst::Plugin::Authentication::Credential::TypeKey" ) }
+# from 01-verify.t in Authen-TypeKey-0.04
+my %user = (
+ ts => '1091163746',
+ email => 'bentwo@stupidfool.org',
+ name => 'Melody',
+ nick => 'foobar baz',
+);
+
my $req = Test::MockObject->new;
$req->set_always( params => {} );
$req->mock( param => sub { $_[0]->params->{ $_[1] } } );
my $tk = Test::MockObject->new;
-$tk->set_true("verify");
+$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( @_ ) } );
"can try to auth with no args, no params";
ok( !$c->called("set_authenticated"), "nothing was authenticated" );
-ok( !$tk->called("verify"), "didn't even verify with no params" );
$_->clear for $c, $tk;
-# from 01-verify.t in Authen-TypeKey-0.04
%{ $req->params } = my %vars = (
- ts => '1091163746',
- email => 'bentwo@stupidfool.org',
- name => 'Melody',
- nick => 'foobar baz',
- sig => 'GWwAIXbkb2xNrQO2e/r2LDl14ek=:U5+tDsPM0+EXeKzFWsosizG7+VU=',
+ %user,
+ sig => 'GWwAIXbkb2xNrQO2e/r2LDl14ek=:U5+tDsPM0+EXeKzFWsosizG7+VU=',
);
lives_ok {