-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #912 from ikedas/issue-893 by ikedas
Data sources: ldap_2level: Returns at most one result not according to select2 parameter
- Loading branch information
Showing
5 changed files
with
181 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,8 +149,6 @@ sub _load_next { | |
|
||
last if $ldap_select eq 'first'; | ||
} | ||
|
||
last if @retrieved; | ||
} | ||
|
||
return [@retrieved]; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# -*- indent-tabs-mode: nil; -*- | ||
# vim:ft=perl:et:sw=4 | ||
|
||
package Sympa::Test::MockLDAP; | ||
|
||
use strict; | ||
use warnings; | ||
use Test::Net::LDAP::Util qw(ldap_mockify); | ||
|
||
use Sympa::DatabaseDriver::LDAP; | ||
|
||
sub build { | ||
my @entries = @_; | ||
|
||
no warnings qw(redefine); | ||
*Sympa::DatabaseDriver::LDAP::_connect = sub { | ||
my $ldap; | ||
ldap_mockify { | ||
$ldap = Net::LDAP->new; | ||
|
||
foreach my $entry (@entries) { | ||
$ldap->add(@$entry); | ||
} | ||
}; | ||
$ldap; | ||
}; | ||
} | ||
|
||
1; | ||
__END__ | ||
=encoding UTF-8 | ||
=head1 NAME | ||
Sympa::Test::MockLDAP - Mocking LDAP directory | ||
=head1 DESCRIPTION | ||
L<Sympa::Test::MockLDAP> mocks LDAP directory on memory so that it will be | ||
used in unit tests. | ||
=head2 Functions | ||
=over | ||
=item build ( entries... ) | ||
Builds mocked directory on memory. | ||
I<entries...> is a list of arrayref to arguments fed to add(). | ||
=back | ||
=head1 SEE ALSO | ||
L<Sympa::DatabaseDriver::LDAP>, | ||
L<Sympa::DataSource::LDAP>, | ||
L<Sympa::DataSource::LDAP2>. | ||
=head1 HISTORY | ||
L<Sympa::Test::MockLDAP> appeared on Sympa 6.2.55b. | ||
=cut | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
# -*- indent-tabs-mode: nil; -*- | ||
# vim:ft=perl:et:sw=4 | ||
|
||
use strict; | ||
use warnings; | ||
use Data::Dumper; | ||
use English qw(-no_match_vars); | ||
use Test::More; | ||
BEGIN { eval 'use Sympa::Test::MockLDAP'; } | ||
|
||
unless (eval 'Test::Net::LDAP::Util->can("ldap_mockify")') { | ||
plan skip_all => 'Test::Net::LDAP required'; | ||
} | ||
|
||
$Data::Dumper::Terse = 1; | ||
$Data::Dumper::Indent = 0; | ||
|
||
use_ok('Sympa::DataSource::LDAP2'); | ||
|
||
my $fake_list = bless { | ||
name => 'list1', | ||
domain => 'mail.example.org', | ||
} => 'Sympa::List'; | ||
|
||
Sympa::Test::MockLDAP::build( | ||
[ 'CN=student1,OU=ELEVES,OU=PERSONNES,DC=info,DC=example,DC=qc,DC=ca', | ||
attrs => [ | ||
cn => 'student1', | ||
businessCategory => '706', | ||
departmentNumber => '023', | ||
], | ||
], | ||
[ '[email protected],OU=PARENTS,OU=PERSONNES,DC=info,DC=example,DC=qc,DC=ca', | ||
attrs => [ | ||
cn => '[email protected]', | ||
mail => '[email protected]', | ||
kids => ['student2', 'student1'], | ||
], | ||
], | ||
[ '[email protected],OU=PARENTS,OU=PERSONNES,DC=info,DC=example,DC=qc,DC=ca', | ||
attrs => [ | ||
cn => '[email protected]', | ||
mail => ['[email protected]', '[email protected]'], | ||
kids => ['student2', 'student1'], | ||
], | ||
], | ||
); | ||
|
||
my $ds; | ||
my @res; | ||
|
||
$ds = Sympa::DataSource->new( | ||
'LDAP2', 'member', | ||
context => $fake_list, | ||
name => 'parent023706', | ||
suffix1 => 'OU=ELEVES,OU=PERSONNES,DC=info,DC=example,DC=qc,DC=ca', | ||
filter1 => '(&(departmentNumber=023)(businessCategory=706))', | ||
scope1 => 'sub', | ||
select1 => 'all', | ||
attrs1 => 'cn', | ||
timeout1 => '60', | ||
suffix2 => 'OU=PARENTS,OU=PERSONNES,dc=info,dc=example,dc=qc,dc=ca', | ||
filter2 => '(kids=[attrs1])', | ||
scope2 => 'sub', | ||
select2 => 'all', | ||
attrs2 => 'mail', | ||
timeout2 => '60', | ||
); | ||
isa_ok $ds, 'Sympa::DataSource::LDAP2'; | ||
ok $ds->open, 'open()'; | ||
|
||
@res = (); | ||
while (my $ent = $ds->next) { | ||
push @res, $ent; | ||
} | ||
is_deeply [sort { $a->[0] cmp $b->[0] } @res], | ||
[ | ||
['[email protected]', undef], | ||
['[email protected]', undef], | ||
['[email protected]', undef] | ||
], | ||
'LDAP 2-level data source with select=all'; | ||
diag Dumper([@res]); | ||
|
||
$ds = Sympa::DataSource->new( | ||
'LDAP2', 'member', | ||
context => $fake_list, | ||
name => 'parent023706', | ||
suffix1 => 'OU=ELEVES,OU=PERSONNES,DC=info,DC=example,DC=qc,DC=ca', | ||
filter1 => '(&(departmentNumber=023)(businessCategory=706))', | ||
scope1 => 'sub', | ||
select1 => 'all', | ||
attrs1 => 'cn', | ||
timeout1 => '60', | ||
suffix2 => 'OU=PARENTS,OU=PERSONNES,dc=info,dc=example,dc=qc,dc=ca', | ||
filter2 => '(kids=[attrs1])', | ||
scope2 => 'sub', | ||
select2 => 'first', | ||
attrs2 => 'mail', | ||
timeout2 => '60', | ||
); | ||
$ds->open or die; | ||
|
||
@res = (); | ||
while (my $ent = $ds->next) { | ||
push @res, $ent; | ||
} | ||
is scalar(@res), 2, 'LDAP 2-level data source with select=first'; | ||
diag Dumper([@res]); | ||
|
||
done_testing(); |