Move user password out into a hash, fixing RT#53279
[catagits/Catalyst-Authentication-Store-LDAP.git] / t / 04-user_class.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use Catalyst::Exception;
6
7 use Test::More tests => 8;
8 use lib 't/lib';
9 use LDAPTest;
10 use Storable qw/ freeze /;
11 use Test::Exception;
12
13 SKIP: {
14
15     eval "use Catalyst::Model::LDAP";
16     if ($@) {
17         skip "Catalyst::Model::LDAP not installed", 8;
18     }
19
20     my $server = LDAPTest::spawn_server();
21
22     use_ok("Catalyst::Authentication::Store::LDAP::Backend");
23
24     my $back = Catalyst::Authentication::Store::LDAP::Backend->new(
25         {   'ldap_server' => LDAPTest::server_host(),
26             'binddn'      => 'anonymous',
27             'bindpw'      => 'dontcarehow',
28             'start_tls'   => 0,
29             'user_basedn' => 'ou=foobar',
30             'user_filter' => '(&(objectClass=person)(uid=%s))',
31             'user_scope'  => 'one',
32             'user_field'  => 'uid',
33             'use_roles'   => 0,
34             'user_class' => 'UserClass',
35         }
36     );
37
38     isa_ok( $back, "Catalyst::Authentication::Store::LDAP::Backend" );
39     my $user = $back->find_user( { username => 'somebody' } );
40     isa_ok( $user, "Catalyst::Authentication::Store::LDAP::User" );
41     isa_ok( $user, "UserClass");
42
43     is( $user->my_method, 'frobnitz', "methods on user class work" );
44
45     $server = LDAPTest::spawn_server();
46     ok $user->check_password('foo'), 'Can check password';
47
48     my $frozen_user;
49     lives_ok { $frozen_user = freeze $user } 'Can freeze user with Storable';
50     ok $frozen_user, 'is frozen';
51
52 }
53