X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F05_password.t;h=840692b548040cec9e3fbd0c948265317c480119;hb=4e953732d2cad72dd5822fb21034a06da10b2264;hp=13fd88fadfff4cb0c2f5444a3e0168a6748a7dcf;hpb=1ae2143a9c52cfe0eecbe52ef92e9c23d82845cd;p=catagits%2FCatalyst-Plugin-Authentication.git diff --git a/t/05_password.t b/t/05_password.t index 13fd88f..840692b 100644 --- a/t/05_password.t +++ b/t/05_password.t @@ -3,42 +3,44 @@ use warnings; use Test::More tests => 11; use Test::Exception; -use Test::MockObject; +use Class::MOP; +use Class::MOP::Class; +use Moose::Object; # 1,2 my $m; BEGIN { use_ok($m = "Catalyst::Authentication::Credential::Password") } can_ok($m, "authenticate"); -my $app = Test::MockObject->new; -my $realm = Test::MockObject->new; -my $user = Test::MockObject->new; +my $app_meta = Class::MOP::Class->create_anon_class( superclasses => ['Moose::Object'] ); +my $realm_meta = Class::MOP::Class->create_anon_class( superclasses => ['Moose::Object'] ); +my $user_meta = Class::MOP::Class->create_anon_class( superclasses => ['Moose::Object'] ); our ($user_get_password_field_name, $user_password ); -$user->mock('get' => sub { $user_get_password_field_name = $_[1]; return $user_password }); +$user_meta->add_method('get' => sub { $user_get_password_field_name = $_[1]; return $user_password }); # 3-6 # Test clear passwords if you mess up the password_field { - local $user_password = undef; # The user returns an undef password, + local $user_password = undef; # The user returns an undef password, local $user_get_password_field_name; # as there is no field named 'mistyped' my $config = { password_type => 'clear', password_field => 'mistyped' }; - my $i; lives_ok { $i = $m->new($config, $app, $realm) } 'Construct instance'; + my $i; lives_ok { $i = $m->new($config, $app_meta->name->new, $realm_meta->name->new) } 'Construct instance'; ok($i, 'Have instance'); - my $r = $i->check_password($user, { username => 'someuser', password => 'password' }); - is($user_get_password_field_name, 'mistyped', + my $r = $i->check_password($user_meta->name->new, { username => 'someuser', password => 'password' }); + is($user_get_password_field_name, 'mistyped', '(Incorrect) field name from config correctly passed to user'); ok(! $r, 'Authentication unsuccessful' ); } # 7-11 # Test clear passwords working, and not working { - local $user_password = 'mypassword'; + local $user_password = 'mypassword'; local $user_get_password_field_name; my $config = { password_type => 'clear', password_field => 'the_password_field' }; - my $i; lives_ok { $i = $m->new($config, $app, $realm) } 'Construct instance'; + my $i; lives_ok { $i = $m->new($config, $app_meta->name->new, $realm_meta->name->new) } 'Construct instance'; ok($i, 'Have instance'); - my $r = $i->check_password($user, { username => 'someuser', the_password_field => 'mypassword' }); - is($user_get_password_field_name, 'the_password_field', + my $r = $i->check_password($user_meta->name->new, { username => 'someuser', the_password_field => 'mypassword' }); + is($user_get_password_field_name, 'the_password_field', 'Correct field name from config correctly passed to user'); ok( $r, 'Authentication successful with correct password' ); - $r = $i->check_password($user, { username => 'someuser', the_password_field => 'adifferentpassword' }); + $r = $i->check_password($user_meta->name->new, { username => 'someuser', the_password_field => 'adifferentpassword' }); ok( ! $r, 'Authentication ussuccessful with incorrect password' ); }