Merge branch 'persist_in_session'
[catagits/Catalyst-Authentication-Store-LDAP.git] / t / 05-user_attributes.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
10 my $server = LDAPTest::spawn_server();
11
12 use_ok("Catalyst::Authentication::Store::LDAP::Backend");
13
14 my $back = Catalyst::Authentication::Store::LDAP::Backend->new(
15     {   'ldap_server' => LDAPTest::server_host(),
16         'binddn'      => 'anonymous',
17         'bindpw'      => 'dontcarehow',
18         'start_tls'   => 0,
19         'user_basedn' => 'ou=foobar',
20         'user_filter' => '(&(objectClass=person)(uid=%s))',
21         'user_scope'  => 'one',
22         'user_field'  => 'uid',
23         'use_roles'   => 0,
24         'entry_class' => 'EntryClass',
25     }
26 );
27
28 isa_ok( $back, "Catalyst::Authentication::Store::LDAP::Backend" );
29 my $user = $back->find_user( { username => 'somebody' } );
30 isa_ok( $user, "Catalyst::Authentication::Store::LDAP::User" );
31
32 #Check DN
33 ok $user->dn,"Get DN from AUTOLOAD"; #THIS ONLY WORKS BECAUSE dn is included as a user attribute in the test LDAP server.
34 ok defined $user->has_attribute('dn'),"Get dn from has_attribute";
35
36 #Check Username
37 ok $user->username, "Get username from AUTOLOAD";
38 ok defined $user->has_attribute('username'),"Get username from has_attribute";
39
40 #Make sure both methods match output
41 ok $user->username eq $user->has_attribute('username'),"username from AUTOLOAD and has_attribute should match";
42 ok $user->dn eq $user->has_attribute('dn'),"dn from AUTOLOAD and has_attribute should match";
43
44 done_testing;