use warnings;
use Catalyst::Exception;
-use Test::More tests => 6;
+use Test::More;
use lib 't/lib';
use LDAPTest;
-SKIP: {
+eval "use Catalyst::Model::LDAP";
+plan skip_all => "Catalyst::Model::LDAP not installed" if $@;
- eval "use Catalyst::Model::LDAP";
- if ($@) {
- skip "Catalyst::Model::LDAP not installed", 6;
+my $server = LDAPTest::spawn_server();
+
+use_ok("Catalyst::Authentication::Store::LDAP::Backend");
+
+my $back = Catalyst::Authentication::Store::LDAP::Backend->new(
+ { 'ldap_server' => LDAPTest::server_host(),
+ 'binddn' => 'anonymous',
+ 'bindpw' => 'dontcarehow',
+ 'start_tls' => 0,
+ 'user_basedn' => 'ou=foobar',
+ 'user_filter' => '(&(objectClass=person)(uid=%s))',
+ 'user_scope' => 'one',
+ 'user_field' => 'uid',
+ 'use_roles' => 0,
+ 'entry_class' => 'EntryClass',
}
+);
+
+isa_ok( $back, "Catalyst::Authentication::Store::LDAP::Backend" );
+my $user = $back->find_user( { username => 'somebody' } );
+isa_ok( $user, "Catalyst::Authentication::Store::LDAP::User" );
+my $displayname = $user->displayname;
+cmp_ok( $displayname, 'eq', 'Some Body', 'Should be Some Body' );
+
+isa_ok( $user->ldap_entry, "EntryClass", "entry_class works" );
+is( $user->ldap_entry->my_method, 1001, "methods on entry_class works" );
- my $server = LDAPTest::spawn_server();
-
- use_ok("Catalyst::Authentication::Store::LDAP::Backend");
-
- my $back = Catalyst::Authentication::Store::LDAP::Backend->new(
- { 'ldap_server' => LDAPTest::server_host(),
- 'binddn' => 'anonymous',
- 'bindpw' => 'dontcarehow',
- 'start_tls' => 0,
- 'user_basedn' => 'ou=foobar',
- 'user_filter' => '(&(objectClass=person)(uid=%s))',
- 'user_scope' => 'one',
- 'user_field' => 'uid',
- 'use_roles' => 0,
- 'entry_class' => 'EntryClass',
- }
- );
-
- isa_ok( $back, "Catalyst::Authentication::Store::LDAP::Backend" );
- my $user = $back->find_user( { username => 'somebody' } );
- isa_ok( $user, "Catalyst::Authentication::Store::LDAP::User" );
- my $displayname = $user->displayname;
- cmp_ok( $displayname, 'eq', 'Some Body', 'Should be Some Body' );
-
- isa_ok( $user->ldap_entry, "EntryClass", "entry_class works" );
- is( $user->ldap_entry->my_method, 1001, "methods on entry_class works" );
-
-}
+done_testing;
use warnings;
use Catalyst::Exception;
-use Test::More tests => 8;
+use Test::More;
use lib 't/lib';
use LDAPTest;
use Storable qw/ freeze /;
use Test::Exception;
-SKIP: {
+eval "use Catalyst::Model::LDAP";
+plan skip_all => "Catalyst::Model::LDAP not installed" if $@;
- eval "use Catalyst::Model::LDAP";
- if ($@) {
- skip "Catalyst::Model::LDAP not installed", 8;
- }
-
- my $server = LDAPTest::spawn_server();
+my $server = LDAPTest::spawn_server();
- use_ok("Catalyst::Authentication::Store::LDAP::Backend");
+use_ok("Catalyst::Authentication::Store::LDAP::Backend");
- my $back = Catalyst::Authentication::Store::LDAP::Backend->new(
- { 'ldap_server' => LDAPTest::server_host(),
- 'binddn' => 'anonymous',
- 'bindpw' => 'dontcarehow',
- 'start_tls' => 0,
- 'user_basedn' => 'ou=foobar',
- 'user_filter' => '(&(objectClass=person)(uid=%s))',
- 'user_scope' => 'one',
- 'user_field' => 'uid',
- 'use_roles' => 0,
- 'user_class' => 'UserClass',
- }
- );
+my $back = Catalyst::Authentication::Store::LDAP::Backend->new(
+ { 'ldap_server' => LDAPTest::server_host(),
+ 'binddn' => 'anonymous',
+ 'bindpw' => 'dontcarehow',
+ 'start_tls' => 0,
+ 'user_basedn' => 'ou=foobar',
+ 'user_filter' => '(&(objectClass=person)(uid=%s))',
+ 'user_scope' => 'one',
+ 'user_field' => 'uid',
+ 'use_roles' => 0,
+ 'user_class' => 'UserClass',
+ }
+);
- isa_ok( $back, "Catalyst::Authentication::Store::LDAP::Backend" );
- my $user = $back->find_user( { username => 'somebody' } );
- isa_ok( $user, "Catalyst::Authentication::Store::LDAP::User" );
- isa_ok( $user, "UserClass");
+isa_ok( $back, "Catalyst::Authentication::Store::LDAP::Backend" );
+my $user = $back->find_user( { username => 'somebody' } );
+isa_ok( $user, "Catalyst::Authentication::Store::LDAP::User" );
+isa_ok( $user, "UserClass");
- is( $user->my_method, 'frobnitz', "methods on user class work" );
+is( $user->my_method, 'frobnitz', "methods on user class work" );
- # RT 69615
- diag("stop() server");
- $server->stop();
+# RT 69615
+diag("stop() server");
+$server->stop();
- $server = LDAPTest::spawn_server();
- ok $user->check_password('foo'), 'Can check password';
+$server = LDAPTest::spawn_server();
+ok $user->check_password('foo'), 'Can check password';
- my $frozen_user;
- lives_ok { $frozen_user = freeze $user } 'Can freeze user with Storable';
- ok $frozen_user, 'is frozen';
+my $frozen_user;
+lives_ok { $frozen_user = freeze $user } 'Can freeze user with Storable';
+ok $frozen_user, 'is frozen';
- # RT 69615
- diag("stop() server");
- $server->stop();
+# RT 69615
+diag("stop() server");
+$server->stop();
-}
+done_testing;
use warnings;
use Catalyst::Exception;
-use Test::More tests => 9;
+use Test::More;
use lib 't/lib';
use LDAPTest;
-SKIP: {
+eval "use Catalyst::Model::LDAP";
+plan skip_all => "Catalyst::Model::LDAP not installed" if $@;
- eval "use Catalyst::Model::LDAP";
- if ($@) {
- skip "Catalyst::Model::LDAP not installed", 9;
- }
-
- my $server = LDAPTest::spawn_server();
+my $server = LDAPTest::spawn_server();
- use_ok("Catalyst::Authentication::Store::LDAP::Backend");
+use_ok("Catalyst::Authentication::Store::LDAP::Backend");
- my $back = Catalyst::Authentication::Store::LDAP::Backend->new(
- { 'ldap_server' => LDAPTest::server_host(),
- 'binddn' => 'anonymous',
- 'bindpw' => 'dontcarehow',
- 'start_tls' => 0,
- 'user_basedn' => 'ou=foobar',
- 'user_filter' => '(&(objectClass=person)(uid=%s))',
- 'user_scope' => 'one',
- 'user_field' => 'uid',
- 'use_roles' => 0,
- 'entry_class' => 'EntryClass',
- }
- );
-
- isa_ok( $back, "Catalyst::Authentication::Store::LDAP::Backend" );
- my $user = $back->find_user( { username => 'somebody' } );
- isa_ok( $user, "Catalyst::Authentication::Store::LDAP::User" );
+my $back = Catalyst::Authentication::Store::LDAP::Backend->new(
+ { 'ldap_server' => LDAPTest::server_host(),
+ 'binddn' => 'anonymous',
+ 'bindpw' => 'dontcarehow',
+ 'start_tls' => 0,
+ 'user_basedn' => 'ou=foobar',
+ 'user_filter' => '(&(objectClass=person)(uid=%s))',
+ 'user_scope' => 'one',
+ 'user_field' => 'uid',
+ 'use_roles' => 0,
+ 'entry_class' => 'EntryClass',
+ }
+);
- #Check DN
- ok $user->dn,"Get DN from AUTOLOAD"; #THIS ONLY WORKS BECAUSE dn is included as a user attribute in the test LDAP server.
- ok defined $user->has_attribute('dn'),"Get dn from has_attribute";
+isa_ok( $back, "Catalyst::Authentication::Store::LDAP::Backend" );
+my $user = $back->find_user( { username => 'somebody' } );
+isa_ok( $user, "Catalyst::Authentication::Store::LDAP::User" );
- #Check Username
- ok $user->username, "Get username from AUTOLOAD";
- ok defined $user->has_attribute('username'),"Get username from has_attribute";
+#Check DN
+ok $user->dn,"Get DN from AUTOLOAD"; #THIS ONLY WORKS BECAUSE dn is included as a user attribute in the test LDAP server.
+ok defined $user->has_attribute('dn'),"Get dn from has_attribute";
- #Make sure both methods match output
- ok $user->username eq $user->has_attribute('username'),"username from AUTOLOAD and has_attribute should match";
- ok $user->dn eq $user->has_attribute('dn'),"dn from AUTOLOAD and has_attribute should match";
+#Check Username
+ok $user->username, "Get username from AUTOLOAD";
+ok defined $user->has_attribute('username'),"Get username from has_attribute";
+#Make sure both methods match output
+ok $user->username eq $user->has_attribute('username'),"username from AUTOLOAD and has_attribute should match";
+ok $user->dn eq $user->has_attribute('dn'),"dn from AUTOLOAD and has_attribute should match";
-}
+done_testing;
use warnings;
use Catalyst::Exception;
-use Test::More tests => 11;
+use Test::More;
use Test::MockObject::Extends;
use Test::Exception;
use Net::LDAP::Entry;
use lib 't/lib';
-SKIP: {
+eval "use Catalyst::Model::LDAP";
+plan skip_all => "Catalyst::Model::LDAP not installed" if $@;
- eval "use Catalyst::Model::LDAP";
- if ($@) {
- skip "Catalyst::Model::LDAP not installed", 11;
- }
+use_ok("Catalyst::Authentication::Store::LDAP::Backend");
- use_ok("Catalyst::Authentication::Store::LDAP::Backend");
+my (@searches, @binds);
+for my $i (0..1) {
- my (@searches, @binds);
- for my $i (0..1) {
+ my $back = Catalyst::Authentication::Store::LDAP::Backend->new({
+ 'ldap_server' => 'ldap://127.0.0.1:555',
+ 'binddn' => 'anonymous',
+ 'bindpw' => 'dontcarehow',
+ 'start_tls' => 0,
+ 'user_basedn' => 'ou=foobar',
+ 'user_filter' => '(&(objectClass=inetOrgPerson)(uid=%s))',
+ 'user_scope' => 'one',
+ 'user_field' => 'uid',
+ 'use_roles' => 1,
+ 'role_basedn' => 'ou=roles',
+ 'role_filter' => '(&(objectClass=posixGroup)(memberUid=%s))',
+ 'role_scope' => 'one',
+ 'role_field' => 'userinrole',
+ 'role_value' => 'cn',
+ 'role_search_as_user' => $i,
+ });
+ $back = Test::MockObject::Extends->new($back);
+ my $bind_msg = Test::MockObject->new;
+ $bind_msg->mock(is_error => sub {}); # Cause bind call to always succeed
+ my $ldap = Test::MockObject->new;
+ $ldap->mock('bind', sub { shift; push (@binds, [@_]); return $bind_msg});
+ $ldap->mock('unbind' => sub {});
+ $ldap->mock('disconnect' => sub {});
+ my $search_res = Test::MockObject->new();
+ my $search_is_error = 0;
+ $search_res->mock(is_error => sub { $search_is_error });
+ $search_res->mock(entries => sub {
+ return map
+ { my $id = $_;
+ Test::MockObject->new->mock(
+ get_value => sub { "quux$id" }
+ )
+ }
+ qw/one two/
+ });
+ my @user_entries;
+ $search_res->mock(pop_entry => sub { return pop @user_entries });
+ $ldap->mock('search', sub { shift; push(@searches, [@_]); return $search_res; });
+ $back->mock('ldap_connect' => sub { $ldap });
+ my $user_entry = Net::LDAP::Entry->new;
+ push(@user_entries, $user_entry);
+ $user_entry->dn('ou=foobar');
+ $user_entry->add(
+ uid => 'somebody',
+ cn => 'test',
+ );
+ my $user = $back->find_user( { username => 'somebody' } );
+ isa_ok( $user, "Catalyst::Authentication::Store::LDAP::User" );
+ $user->check_password('password');
+ is_deeply( [sort $user->roles],
+ [sort qw/quuxone quuxtwo/],
+ "User has the expected set of roles" );
- my $back = Catalyst::Authentication::Store::LDAP::Backend->new({
- 'ldap_server' => 'ldap://127.0.0.1:555',
- 'binddn' => 'anonymous',
- 'bindpw' => 'dontcarehow',
- 'start_tls' => 0,
- 'user_basedn' => 'ou=foobar',
- 'user_filter' => '(&(objectClass=inetOrgPerson)(uid=%s))',
- 'user_scope' => 'one',
- 'user_field' => 'uid',
- 'use_roles' => 1,
- 'role_basedn' => 'ou=roles',
- 'role_filter' => '(&(objectClass=posixGroup)(memberUid=%s))',
- 'role_scope' => 'one',
- 'role_field' => 'userinrole',
- 'role_value' => 'cn',
- 'role_search_as_user' => $i,
- });
- $back = Test::MockObject::Extends->new($back);
- my $bind_msg = Test::MockObject->new;
- $bind_msg->mock(is_error => sub {}); # Cause bind call to always succeed
- my $ldap = Test::MockObject->new;
- $ldap->mock('bind', sub { shift; push (@binds, [@_]); return $bind_msg});
- $ldap->mock('unbind' => sub {});
- $ldap->mock('disconnect' => sub {});
- my $search_res = Test::MockObject->new();
- my $search_is_error = 0;
- $search_res->mock(is_error => sub { $search_is_error });
- $search_res->mock(entries => sub {
- return map
- { my $id = $_;
- Test::MockObject->new->mock(
- get_value => sub { "quux$id" }
- )
- }
- qw/one two/
- });
- my @user_entries;
- $search_res->mock(pop_entry => sub { return pop @user_entries });
- $ldap->mock('search', sub { shift; push(@searches, [@_]); return $search_res; });
- $back->mock('ldap_connect' => sub { $ldap });
- my $user_entry = Net::LDAP::Entry->new;
- push(@user_entries, $user_entry);
- $user_entry->dn('ou=foobar');
- $user_entry->add(
- uid => 'somebody',
- cn => 'test',
- );
- my $user = $back->find_user( { username => 'somebody' } );
- isa_ok( $user, "Catalyst::Authentication::Store::LDAP::User" );
- $user->check_password('password');
- is_deeply( [sort $user->roles],
- [sort qw/quuxone quuxtwo/],
- "User has the expected set of roles" );
+ $search_is_error = 1;
+ lives_ok {
+ ok !$back->find_user( { username => 'doesnotexist' } ),
+ 'Nonexistent user returns undef';
+ } 'No exception thrown for nonexistent user';
- $search_is_error = 1;
- lives_ok {
- ok !$back->find_user( { username => 'doesnotexist' } ),
- 'Nonexistent user returns undef';
- } 'No exception thrown for nonexistent user';
-
- }
- is_deeply(\@searches, [
- ['base', 'ou=foobar', 'filter', '(&(objectClass=inetOrgPerson)(uid=somebody))', 'scope', 'one'],
- ['base', 'ou=roles', 'filter', '(&(objectClass=posixGroup)(memberUid=test))', 'scope', 'one', 'attrs', [ 'userinrole' ]],
- ['base', 'ou=foobar', 'filter', '(&(objectClass=inetOrgPerson)(uid=doesnotexist))', 'scope', 'one'],
- ['base', 'ou=foobar', 'filter', '(&(objectClass=inetOrgPerson)(uid=somebody))', 'scope', 'one'],
- ['base', 'ou=roles', 'filter', '(&(objectClass=posixGroup)(memberUid=test))', 'scope', 'one', 'attrs', [ 'userinrole' ]],
- ['base', 'ou=foobar', 'filter', '(&(objectClass=inetOrgPerson)(uid=doesnotexist))', 'scope', 'one'],
- ], 'User searches as expected');
- is_deeply(\@binds, [
- [ undef ], # First user search
- [
- 'ou=foobar',
- 'password',
- 'password'
- ], # Rebind to confirm user
- [
- undef
- ], # Rebind with initial credentials to find roles
- [ undef ], # Second user search
- # 2nd pass round main loop
- [ undef ], # First user search
- [
- 'ou=foobar',
- 'password',
- 'password'
- ], # Rebind to confirm user _and_ lookup roles;
- [ undef ], # Second user search
- ], 'Binds as expected');
}
+is_deeply(\@searches, [
+ ['base', 'ou=foobar', 'filter', '(&(objectClass=inetOrgPerson)(uid=somebody))', 'scope', 'one'],
+ ['base', 'ou=roles', 'filter', '(&(objectClass=posixGroup)(memberUid=test))', 'scope', 'one', 'attrs', [ 'userinrole' ]],
+ ['base', 'ou=foobar', 'filter', '(&(objectClass=inetOrgPerson)(uid=doesnotexist))', 'scope', 'one'],
+ ['base', 'ou=foobar', 'filter', '(&(objectClass=inetOrgPerson)(uid=somebody))', 'scope', 'one'],
+ ['base', 'ou=roles', 'filter', '(&(objectClass=posixGroup)(memberUid=test))', 'scope', 'one', 'attrs', [ 'userinrole' ]],
+ ['base', 'ou=foobar', 'filter', '(&(objectClass=inetOrgPerson)(uid=doesnotexist))', 'scope', 'one'],
+], 'User searches as expected');
+is_deeply(\@binds, [
+ [ undef ], # First user search
+ [
+ 'ou=foobar',
+ 'password',
+ 'password'
+ ], # Rebind to confirm user
+ [
+ undef
+ ], # Rebind with initial credentials to find roles
+ [ undef ], # Second user search
+ # 2nd pass round main loop
+ [ undef ], # First user search
+ [
+ 'ou=foobar',
+ 'password',
+ 'password'
+ ], # Rebind to confirm user _and_ lookup roles;
+ [ undef ], # Second user search
+], 'Binds as expected');
+
+done_testing;