516ee71010250f9a133b5e8c879ec5357875fa71
[catagits/Catalyst-Authentication-Store-LDAP.git] / t / 20-persist_in_session.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7 use Catalyst::Authentication::Store::LDAP::Backend;
8 use lib 't/lib';
9 use LDAPTest;
10
11 my $server = LDAPTest::spawn_server();
12
13 my $back = Catalyst::Authentication::Store::LDAP::Backend->new(
14     {   'ldap_server' => LDAPTest::server_host(),
15         'binddn'      => 'anonymous',
16         'bindpw'      => 'dontcarehow',
17         'start_tls'   => 0,
18         'user_basedn' => 'ou=foobar',
19         'user_filter' => '(&(objectClass=person)(uid=%s))',
20         'user_scope'  => 'one',
21         'user_field'  => 'uid',
22         'use_roles'   => 0,
23     }
24 );
25
26 my $user = $back->find_user( { username => 'somebody' } );
27 is($user->for_session, 'somebody', 'persist_in_session unset: for_session ok');
28
29 my $back_persist_username = Catalyst::Authentication::Store::LDAP::Backend->new(
30     {   ldap_server         => LDAPTest::server_host(),
31         binddn              => 'anonymous',
32         bindpw              => 'dontcarehow',
33         start_tls           => 0,
34         user_basedn         => 'ou=foobar',
35         user_filter         => '(&(objectClass=person)(uid=%s))',
36         user_scope          => 'one',
37         user_field          => 'uid',
38         use_roles           => 0,
39         persist_in_session  => 'username',
40     }
41 );
42 $user = $back_persist_username->find_user( { username => 'somebody' } );
43 is($user->for_session, 'somebody',
44     "persist_in_session 'username': for_session ok");
45
46 my $back_persist_all = Catalyst::Authentication::Store::LDAP::Backend->new(
47     {   ldap_server         => LDAPTest::server_host(),
48         binddn              => 'anonymous',
49         bindpw              => 'dontcarehow',
50         start_tls           => 0,
51         user_basedn         => 'ou=foobar',
52         user_filter         => '(&(objectClass=person)(uid=%s))',
53         user_scope          => 'one',
54         user_field          => 'uid',
55         use_roles           => 0,
56         persist_in_session  => 'all',
57     }
58 );
59 $user = $back_persist_all->find_user( { username => 'somebody' } );
60 is_deeply($user->for_session,
61     {
62         persist_in_session => 'all',
63         user => $user->user,
64         _roles => [],
65     },
66     "persist_in_session 'all': for_session ok");
67
68 done_testing;