Commit | Line | Data |
b003080b |
1 | use strict; |
2 | use warnings; |
3 | |
1ae2143a |
4 | use Test::More tests => 11; |
5 | use Test::Exception; |
c7b6526a |
6 | use Class::MOP; |
7 | use Class::MOP::Class; |
8 | use Moose::Object; |
b003080b |
9 | |
1ae2143a |
10 | # 1,2 |
5c5af345 |
11 | my $m; BEGIN { use_ok($m = "Catalyst::Authentication::Credential::Password") } |
290e5a7e |
12 | can_ok($m, "authenticate"); |
b003080b |
13 | |
c7b6526a |
14 | my $app_meta = Class::MOP::Class->create_anon_class( superclasses => ['Moose::Object'] ); |
15 | my $realm_meta = Class::MOP::Class->create_anon_class( superclasses => ['Moose::Object'] ); |
16 | my $user_meta = Class::MOP::Class->create_anon_class( superclasses => ['Moose::Object'] ); |
1ae2143a |
17 | our ($user_get_password_field_name, $user_password ); |
c7b6526a |
18 | $user_meta->add_method('get' => sub { $user_get_password_field_name = $_[1]; return $user_password }); |
1ae2143a |
19 | |
20 | # 3-6 # Test clear passwords if you mess up the password_field |
21 | { |
c7b6526a |
22 | local $user_password = undef; # The user returns an undef password, |
1ae2143a |
23 | local $user_get_password_field_name; # as there is no field named 'mistyped' |
24 | my $config = { password_type => 'clear', password_field => 'mistyped' }; |
c7b6526a |
25 | my $i; lives_ok { $i = $m->new($config, $app_meta->name->new, $realm_meta->name->new) } 'Construct instance'; |
1ae2143a |
26 | ok($i, 'Have instance'); |
c7b6526a |
27 | my $r = $i->check_password($user_meta->name->new, { username => 'someuser', password => 'password' }); |
28 | is($user_get_password_field_name, 'mistyped', |
1ae2143a |
29 | '(Incorrect) field name from config correctly passed to user'); |
30 | ok(! $r, 'Authentication unsuccessful' ); |
31 | } |
b003080b |
32 | |
1ae2143a |
33 | # 7-11 # Test clear passwords working, and not working |
34 | { |
c7b6526a |
35 | local $user_password = 'mypassword'; |
1ae2143a |
36 | local $user_get_password_field_name; |
37 | my $config = { password_type => 'clear', password_field => 'the_password_field' }; |
c7b6526a |
38 | my $i; lives_ok { $i = $m->new($config, $app_meta->name->new, $realm_meta->name->new) } 'Construct instance'; |
1ae2143a |
39 | ok($i, 'Have instance'); |
c7b6526a |
40 | my $r = $i->check_password($user_meta->name->new, { username => 'someuser', the_password_field => 'mypassword' }); |
41 | is($user_get_password_field_name, 'the_password_field', |
1ae2143a |
42 | 'Correct field name from config correctly passed to user'); |
43 | ok( $r, 'Authentication successful with correct password' ); |
c7b6526a |
44 | $r = $i->check_password($user_meta->name->new, { username => 'someuser', the_password_field => 'adifferentpassword' }); |
1ae2143a |
45 | ok( ! $r, 'Authentication ussuccessful with incorrect password' ); |
46 | } |