add tests for persist_in_session
[catagits/Catalyst-Authentication-Store-LDAP.git] / t / 20-persist_in_session.t
CommitLineData
a45fc086 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More;
7use Catalyst::Authentication::Store::LDAP::Backend;
8use lib 't/lib';
9use LDAPTest;
10
11my $server = LDAPTest::spawn_server();
12
13my $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
26my $user = $back->find_user( { username => 'somebody' } );
27is($user->for_session, 'somebody', 'persist_in_session unset: for_session ok');
28
29my $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' } );
43is($user->for_session, 'somebody',
44 "persist_in_session 'username': for_session ok");
45
46my $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' } );
60is_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
68done_testing;