Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Projets publics
Sympa
Commits
ebb3d01b
Commit
ebb3d01b
authored
Mar 15, 2020
by
IKEDA Soji
Browse files
Adding tests
parent
fd89c0d8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Makefile.am
View file @
ebb3d01b
...
...
@@ -36,6 +36,7 @@ check_SCRIPTS = \
t/compile_scenarios.t
\
t/Config_XML.t
\
t/Database_LDAP.t
\
t/DataSource_LDAP2.t
\
t/parse_templates.t
\
t/pod-syntax.t
\
t/tools_data.t
\
...
...
@@ -45,6 +46,7 @@ check_SCRIPTS = \
t/Tools_Text.t
\
t/tools_time.t
check_DATA
=
\
src/lib/Sympa/Test/MockLDAP.pm
\
t/locale/cs/LC_MESSAGES/sympa.mo
\
t/locale/cs/LC_MESSAGES/web_help.mo
\
t/locale/zh_TW/LC_MESSAGES/sympa.mo
\
...
...
cpanfile
View file @
ebb3d01b
...
...
@@ -314,4 +314,5 @@ on 'develop' => sub {
requires 'Test::PerlTidy', '== 20130104';
requires 'Perl::Tidy', '== 20180220';
requires 'Code::TidyAll';
requires 'Test::Net::LDAP', '>= 0.06';
};
src/lib/Sympa/Test/MockLDAP.pm
0 → 100644
View file @
ebb3d01b
# -*- 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
t/DataSource_LDAP2.t
0 → 100644
View file @
ebb3d01b
# -*- 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
;
use
Sympa::Test::
MockLDAP
;
$
Data::Dumper::
Terse
=
1
;
$
Data::Dumper::
Indent
=
0
;
BEGIN
{
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
',
],
],
[
'
CN=random@hotmail.com,OU=PARENTS,OU=PERSONNES,DC=info,DC=example,DC=qc,DC=ca
',
attrs
=>
[
cn
=>
'
random@hotmail.com
',
mail
=>
'
random@hotmail.com
',
kids
=>
['
student2
',
'
student1
'],
],
],
[
'
CN=random2@hotmail.com,OU=PARENTS,OU=PERSONNES,DC=info,DC=example,DC=qc,DC=ca
',
attrs
=>
[
cn
=>
'
random2@hotmail.com
',
mail
=>
['
random1@hotmail.com
',
'
random2@hotmail.com
'],
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
],
[
['
random1@hotmail.com
',
undef
],
['
random2@hotmail.com
',
undef
],
['
random@hotmail.com
',
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
();
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment