forked from sympa-community/sympa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataSource_LDAP2.t
113 lines (100 loc) · 2.92 KB
/
DataSource_LDAP2.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# -*- 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';
}
use Sympa::List;
$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();