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