Use skip_all and done_testing in all tests
[catagits/Catalyst-Authentication-Store-LDAP.git] / t / 05-user_attributes.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use Catalyst::Exception;
6
7 use Test::More;
8 use lib 't/lib';
9 use LDAPTest;
10
11 eval "use Catalyst::Model::LDAP";
12 plan skip_all => "Catalyst::Model::LDAP not installed" if $@;
13
14 my $server = LDAPTest::spawn_server();
15
16 use_ok("Catalyst::Authentication::Store::LDAP::Backend");
17
18 my $back = Catalyst::Authentication::Store::LDAP::Backend->new(
19     {   'ldap_server' => LDAPTest::server_host(),
20         'binddn'      => 'anonymous',
21         'bindpw'      => 'dontcarehow',
22         'start_tls'   => 0,
23         'user_basedn' => 'ou=foobar',
24         'user_filter' => '(&(objectClass=person)(uid=%s))',
25         'user_scope'  => 'one',
26         'user_field'  => 'uid',
27         'use_roles'   => 0,
28         'entry_class' => 'EntryClass',
29     }
30 );
31
32 isa_ok( $back, "Catalyst::Authentication::Store::LDAP::Backend" );
33 my $user = $back->find_user( { username => 'somebody' } );
34 isa_ok( $user, "Catalyst::Authentication::Store::LDAP::User" );
35
36 #Check DN
37 ok $user->dn,"Get DN from AUTOLOAD"; #THIS ONLY WORKS BECAUSE dn is included as a user attribute in the test LDAP server.
38 ok defined $user->has_attribute('dn'),"Get dn from has_attribute";
39
40 #Check Username
41 ok $user->username, "Get username from AUTOLOAD";
42 ok defined $user->has_attribute('username'),"Get username from has_attribute";
43
44 #Make sure both methods match output
45 ok $user->username eq $user->has_attribute('username'),"username from AUTOLOAD and has_attribute should match";
46 ok $user->dn eq $user->has_attribute('dn'),"dn from AUTOLOAD and has_attribute should match";
47
48 done_testing;