Changelog, bump version
[catagits/Catalyst-Plugin-Authentication.git] / t / 05_password.t
CommitLineData
dde93f12 1use strict;
2use warnings;
3
007228c1 4use Test::More tests => 11;
5use Test::Exception;
6use Test::MockObject;
dde93f12 7
007228c1 8# 1,2
e0499ed6 9my $m; BEGIN { use_ok($m = "Catalyst::Authentication::Credential::Password") }
db42e696 10can_ok($m, "authenticate");
dde93f12 11
007228c1 12my $app = Test::MockObject->new;
13my $realm = Test::MockObject->new;
14my $user = Test::MockObject->new;
15our ($user_get_password_field_name, $user_password );
16$user->mock('get' => sub { $user_get_password_field_name = $_[1]; return $user_password });
17
18# 3-6 # Test clear passwords if you mess up the password_field
19{
20 local $user_password = undef; # The user returns an undef password,
21 local $user_get_password_field_name; # as there is no field named 'mistyped'
22 my $config = { password_type => 'clear', password_field => 'mistyped' };
23 my $i; lives_ok { $i = $m->new($config, $app, $realm) } 'Construct instance';
24 ok($i, 'Have instance');
25 my $r = $i->check_password($user, { username => 'someuser', password => 'password' });
26 is($user_get_password_field_name, 'mistyped',
27 '(Incorrect) field name from config correctly passed to user');
28 ok(! $r, 'Authentication unsuccessful' );
29}
dde93f12 30
007228c1 31# 7-11 # Test clear passwords working, and not working
32{
33 local $user_password = 'mypassword';
34 local $user_get_password_field_name;
35 my $config = { password_type => 'clear', password_field => 'the_password_field' };
36 my $i; lives_ok { $i = $m->new($config, $app, $realm) } 'Construct instance';
37 ok($i, 'Have instance');
38 my $r = $i->check_password($user, { username => 'someuser', the_password_field => 'mypassword' });
39 is($user_get_password_field_name, 'the_password_field',
40 'Correct field name from config correctly passed to user');
41 ok( $r, 'Authentication successful with correct password' );
42 $r = $i->check_password($user, { username => 'someuser', the_password_field => 'adifferentpassword' });
43 ok( ! $r, 'Authentication ussuccessful with incorrect password' );
44}