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