From 6679fe6f2bd3c9100015ad33565ddd4ce6ea5512 Mon Sep 17 00:00:00 2001 From: Xavier Guimard Date: Fri, 6 Jun 2008 03:53:14 +0000 Subject: [PATCH] LEMONLDAP::NG : tests update --- build/lemonldap-ng/Makefile | 4 +- modules/lemonldap-ng-manager/MANIFEST | 2 - .../lib/Lemonldap/NG/Manager/_i18n.pm | 2 +- .../lemonldap-ng-manager/t/20-Manager-i18n.t | 70 +++++++++++++-- .../t/21-Manager-i18n-en.t | 35 -------- .../t/22-Manager-i18n-fr.t | 35 -------- .../t/01-Lemonldap-NG-Portal-Simple.t | 87 +++++++++++++++++++ ....t => 02-Lemonldap-NG-Portal-SharedConf.t} | 0 .../t/10-Lemonldap-NG-Portal-i18n.t | 39 +++++++++ ....t => 20-Lemonldap-NG-Portal-AuthApache.t} | 6 +- ...SSL.t => 21-Lemonldap-NG-Portal-AuthSSL.t} | 7 +- ...CAS.t => 22-Lemonldap-NG-Portal-AuthCAS.t} | 16 ++-- ...thLA.t => 23-Lemonldap-NG-Portal-AuthLA.t} | 0 ...tal-CDA.t => 40-Lemonldap-NG-Portal-CDA.t} | 0 .../t/Lemonldap-NG-Portal-Simple.t | 39 --------- .../t/Lemonldap-NG-Portal-i18n.t | 24 ----- 16 files changed, 208 insertions(+), 158 deletions(-) delete mode 100644 modules/lemonldap-ng-manager/t/21-Manager-i18n-en.t delete mode 100644 modules/lemonldap-ng-manager/t/22-Manager-i18n-fr.t create mode 100644 modules/lemonldap-ng-portal/t/01-Lemonldap-NG-Portal-Simple.t rename modules/lemonldap-ng-portal/t/{Lemonldap-NG-Portal-SharedConf.t => 02-Lemonldap-NG-Portal-SharedConf.t} (100%) create mode 100644 modules/lemonldap-ng-portal/t/10-Lemonldap-NG-Portal-i18n.t rename modules/lemonldap-ng-portal/t/{Lemonldap-NG-Portal-AuthApache.t => 20-Lemonldap-NG-Portal-AuthApache.t} (80%) rename modules/lemonldap-ng-portal/t/{Lemonldap-NG-Portal-AuthSSL.t => 21-Lemonldap-NG-Portal-AuthSSL.t} (77%) rename modules/lemonldap-ng-portal/t/{Lemonldap-NG-Portal-AuthCAS.t => 22-Lemonldap-NG-Portal-AuthCAS.t} (65%) rename modules/lemonldap-ng-portal/t/{Lemonldap-NG-Portal-AuthLA.t => 23-Lemonldap-NG-Portal-AuthLA.t} (100%) rename modules/lemonldap-ng-portal/t/{Lemonldap-NG-Portal-CDA.t => 40-Lemonldap-NG-Portal-CDA.t} (100%) delete mode 100644 modules/lemonldap-ng-portal/t/Lemonldap-NG-Portal-Simple.t delete mode 100644 modules/lemonldap-ng-portal/t/Lemonldap-NG-Portal-i18n.t diff --git a/build/lemonldap-ng/Makefile b/build/lemonldap-ng/Makefile index b311a51cb..b9abcea9b 100644 --- a/build/lemonldap-ng/Makefile +++ b/build/lemonldap-ng/Makefile @@ -45,7 +45,7 @@ manager_conf: cd ${MANAGERDIR}; perl Makefile.PL INSTALLDIRS=$(INSTALLDIRS) touch manager_conf -test: manager_test handler_test portal_test +test: manager handler portal manager_test handler_test portal_test manager_test: manager $(MAKE) -C ${MANAGERDIR} test @@ -74,7 +74,7 @@ distclean: clean clean: handler_clean portal_clean manager_clean rm -rf example - find . -name '*.gz' -exec rm -vf {} \; + rm -vf *gz handler_clean: - $(MAKE) -C ${HANDLERDIR} distclean diff --git a/modules/lemonldap-ng-manager/MANIFEST b/modules/lemonldap-ng-manager/MANIFEST index cfd8baca9..3b9ccf935 100644 --- a/modules/lemonldap-ng-manager/MANIFEST +++ b/modules/lemonldap-ng-manager/MANIFEST @@ -78,8 +78,6 @@ t/03-Manager-Conf-DBI.t t/04-Manager-Conf-SOAP.t t/10-Manager.t t/20-Manager-i18n.t -t/21-Manager-i18n-en.t -t/22-Manager-i18n-fr.t t/50-Manager-SOAPServer.t t/99-pod.t TODO diff --git a/modules/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/_i18n.pm b/modules/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/_i18n.pm index eec976c47..df842b54a 100644 --- a/modules/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/_i18n.pm +++ b/modules/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/_i18n.pm @@ -155,7 +155,7 @@ sub fr { isNotAValidDomainName => "n'est pas un nom de domaine valide", isNotAValidGroupName => "n'est pas un nom de groupe valide", isNotAValidHTTPHeaderName => "n'est pas un nom d'en-tête HTTP valide", - isNotAValidLDAPAttributeName => "is not a valid LDAP attribute name", + isNotAValidLDAPAttributeName => "n'est pas un nom d'attribut LDAP valide", isNotAValidMacroName => "n'est pas un nom de macro valide", isNotAValidVirtualHostName => "n'est pas un nom d'hôte virtuel valide", lastConf => "Dernière", diff --git a/modules/lemonldap-ng-manager/t/20-Manager-i18n.t b/modules/lemonldap-ng-manager/t/20-Manager-i18n.t index 224bf05ae..4ce663e13 100644 --- a/modules/lemonldap-ng-manager/t/20-Manager-i18n.t +++ b/modules/lemonldap-ng-manager/t/20-Manager-i18n.t @@ -1,23 +1,75 @@ -use Test::More tests => 2; -BEGIN { use_ok('Lemonldap::NG::Manager::_i18n') } +# Lemonldap::NG::Manager translation test +# +# Here, we test : +# 1) each keyword is translated in each language +# 2) display functions in english language -ok ( &compare ( "en", "fr" ) ); +BEGIN { + our %lang = ( + en => 'English', + fr => 'French', + ); +} + +use Test::More tests => ( keys(%lang) + 4 ); + +use_ok('Lemonldap::NG::Manager'); + +my $win = 0; +$win ++ unless( -e '/dev/null' ); + +if($win) { + open STDOUT, '>test_stdout.txt'; +} +else { + open STDOUT, '>/dev/null'; +} + +foreach ( keys %lang ) { + ok( &compare( "en", $_ ), + "Compare English and $lang{$_} translation coverage" ) + unless ( $_ eq 'en' ); +} + +$ENV{SCRIPT_NAME} = "__SCRIPTNAME__"; +$ENV{SCRIPT_FILENAME} = $0; +$ENV{HTTP_ACCEPT_LANGUAGE} = 'en'; +my $h; +@ARGV = ("help=groups"); +ok( + $h = new Lemonldap::NG::Manager( + { + configStorage => { + type => 'File', + dirName => ".", + }, + dhtmlXTreeImageLocation => "/imgs/", + jsFile => 'example/lemonldap-ng-manager.js', + } + ), + 'New manager object' +); +ok( $h->main(), "HTML code" ); +ok( $h->print_help(), "Help page" ); +ok( $h->buildTree(), "XML tree" ); + +unlink('test_stdout.txt') if($win); sub compare { my ( $l1, $l2 ) = @_; - $r1 = &{"Lemonldap::NG::Manager::_i18n::" . $l1}; - $r2 = &{"Lemonldap::NG::Manager::_i18n::" . $l2}; + $r1 = &{ "Lemonldap::NG::Manager::_i18n::" . $l1 }; + $r2 = &{ "Lemonldap::NG::Manager::_i18n::" . $l2 }; my $r = 1; foreach ( keys %$r1 ) { - unless( $r2->{$_} ) { + unless ( $r2->{$_} ) { print STDERR "$_ is present in $l1 but miss in $l2"; - $r=0; + $r = 0; } } foreach ( keys %$r2 ) { - unless( $r1->{$_} ) { + unless ( $r1->{$_} ) { print STDERR "$_ is present in $l2 but miss in $l1"; - $r=0; + $r = 0; } } return $r; diff --git a/modules/lemonldap-ng-manager/t/21-Manager-i18n-en.t b/modules/lemonldap-ng-manager/t/21-Manager-i18n-en.t deleted file mode 100644 index 5e65e38da..000000000 --- a/modules/lemonldap-ng-manager/t/21-Manager-i18n-en.t +++ /dev/null @@ -1,35 +0,0 @@ -# Before `make install' is performed this script should be runnable with -# `make test'. After `make install' it should work as `perl Lemonldap-NG-Manager.t' - -######################### - -# change 'tests => 1' to 'tests => last_test_to_print'; - -use Test::More tests => 5; -BEGIN { use_ok('Lemonldap::NG::Manager') } - -######################### - -# Insert your test code below, the Test::More module is use()ed here so read -# its man page ( perldoc Test::More ) for help writing this test script. - -$ENV{SCRIPT_NAME} = "__SCRIPTNAME__"; -$ENV{SCRIPT_FILENAME} = $0; -$ENV{HTTP_ACCEPT_LANGUAGE} = "en"; -my $h; -@ARGV = ("help=groups"); -ok( - $h = new Lemonldap::NG::Manager( - { - configStorage => { - type => 'File', - dirName => ".", - }, - dhtmlXTreeImageLocation => "/imgs/", - jsFile => 'example/lemonldap-ng-manager.js', - } - ) -); -ok( $h->main() ); -ok( $h->print_help() ); -ok( $h->buildTree() ); diff --git a/modules/lemonldap-ng-manager/t/22-Manager-i18n-fr.t b/modules/lemonldap-ng-manager/t/22-Manager-i18n-fr.t deleted file mode 100644 index 8310045f4..000000000 --- a/modules/lemonldap-ng-manager/t/22-Manager-i18n-fr.t +++ /dev/null @@ -1,35 +0,0 @@ -# Before `make install' is performed this script should be runnable with -# `make test'. After `make install' it should work as `perl Lemonldap-NG-Manager.t' - -######################### - -# change 'tests => 1' to 'tests => last_test_to_print'; - -use Test::More tests => 5; -BEGIN { use_ok('Lemonldap::NG::Manager') } - -######################### - -# Insert your test code below, the Test::More module is use()ed here so read -# its man page ( perldoc Test::More ) for help writing this test script. - -$ENV{SCRIPT_NAME} = "__SCRIPTNAME__"; -$ENV{SCRIPT_FILENAME} = $0; -$ENV{HTTP_ACCEPT_LANGUAGE} = "fr"; -my $h; -@ARGV = ("help=groups"); -ok( - $h = new Lemonldap::NG::Manager( - { - configStorage => { - type => 'File', - dirName => ".", - }, - dhtmlXTreeImageLocation => "/imgs/", - jsFile => 'example/lemonldap-ng-manager.js', - } - ) -); -ok( $h->main() ); -ok( $h->print_help() ); -ok( $h->buildTree() ); diff --git a/modules/lemonldap-ng-portal/t/01-Lemonldap-NG-Portal-Simple.t b/modules/lemonldap-ng-portal/t/01-Lemonldap-NG-Portal-Simple.t new file mode 100644 index 000000000..1ceafb6fd --- /dev/null +++ b/modules/lemonldap-ng-portal/t/01-Lemonldap-NG-Portal-Simple.t @@ -0,0 +1,87 @@ +# Before `make install' is performed this script should be runnable with +# `make test'. After `make install' it should work as `perl Lemonldap-NG-Portal.t' + +######################### + +# change 'tests => 1' to 'tests => last_test_to_print'; + +use Test::More tests => 12; + +BEGIN { use_ok( 'Lemonldap::NG::Portal::Simple', ':all' ) } + +SKIP: { + eval { require Net::LDAP::Control::PasswordPolicy }; + skip +"Net::LDAP Password Policy Control is not installed (perl-ldap >= 0.35), so Password Policy will not be usable", + 1 + if ($@); + use_ok('Net::LDAP::Control::PasswordPolicy'); +} + +######################### + +# Insert your test code below, the Test::More module is use()ed here so read +# its man page ( perldoc Test::More ) for help writing this test script. + +my $p; + +# CGI Environment +$ENV{SCRIPT_NAME} = '/test.pl'; +$ENV{SCRIPT_FILENAME} = '/tmp/test.pl'; +$ENV{REQUEST_METHOD} = 'GET'; +$ENV{REQUEST_URI} = '/'; +$ENV{QUERY_STRING} = ''; + +ok( + $p = Lemonldap::NG::Portal::Simple->new( + { + globalStorage => 'Apache::Session::File', + domain => 'example.com', + authentication => 'LDAP test=1', + } + ), + 'Portal object' +); + +# Arg test passed +ok( $p->{test}, 'Authentication arguments' ); + +# Process test: first access +ok( $p->process == 0, 'No user' ); +ok( $p->{error} == PE_FIRSTACCESS, 'Error code: first access' ); + +# Process test: user without password +$ENV{REQUEST_URI} = '/?user=test'; +$ENV{QUERY_STRING} = 'user=test'; +$p = Lemonldap::NG::Portal::Simple->new( + { + globalStorage => 'Apache::Session::File', + domain => 'example.com', + } +); + +ok( $p->process == 0, 'User without password' ); +ok( $p->{error} == PE_FORMEMPTY, 'Error code: missing password' ); + +# Process test without LDAP +# No ldap +$p->{extractFormInfo} = sub { + my $self = shift; + $self->{user} = 'user'; + PE_OK; +}; + +$p->{connectLDAP} = sub { PE_OK }; +$p->{bind} = sub { PE_OK }; +$p->{search} = sub { PE_OK }; +$p->{setSessionInfo} = sub { PE_OK }; +$p->{unbind} = sub { PE_OK }; +$p->{store} = sub { PE_OK }; +ok( $p->process, 'User OK' ); + +# Cookie test +$p->{id} = 1; +ok( $p->buildCookie == PE_OK, 'Cookie build' ); +ok( ( ref( $p->{cookie} ) eq 'ARRAY' and $p->{cookie}->[0]->isa('CGI::Cookie') ), 'Valid cookie' ); +ok( $p->{cookie}->[0]->value eq '1', 'Cookie value' ); + diff --git a/modules/lemonldap-ng-portal/t/Lemonldap-NG-Portal-SharedConf.t b/modules/lemonldap-ng-portal/t/02-Lemonldap-NG-Portal-SharedConf.t similarity index 100% rename from modules/lemonldap-ng-portal/t/Lemonldap-NG-Portal-SharedConf.t rename to modules/lemonldap-ng-portal/t/02-Lemonldap-NG-Portal-SharedConf.t diff --git a/modules/lemonldap-ng-portal/t/10-Lemonldap-NG-Portal-i18n.t b/modules/lemonldap-ng-portal/t/10-Lemonldap-NG-Portal-i18n.t new file mode 100644 index 000000000..d1c3083ba --- /dev/null +++ b/modules/lemonldap-ng-portal/t/10-Lemonldap-NG-Portal-i18n.t @@ -0,0 +1,39 @@ +# Before `make install' is performed this script should be runnable with +# `make test'. After `make install' it should work as `perl Lemonldap-NG-Portal.t' + +######################### + +# change 'tests => 1' to 'tests => last_test_to_print'; + +BEGIN { + our %translations = ( + fr => 'French', + ro => 'Romanian' + ); +} + +use Test::More tests => 5 + ( keys(%translations) * 2 ); +BEGIN { use_ok('Lemonldap::NG::Portal::Simple') } + +######################### + +# Insert your test code below, the Test::More module is use()ed here so read +# its man page ( perldoc Test::More ) for help writing this test script. + +ok( my @en = @{&Lemonldap::NG::Portal::_i18n::error_en}, + 'English translation' ); +ok( $#en > 21, 'Translation count' ); + +foreach ( keys %translations ) { + ok( my @tmp = @{ &{"Lemonldap::NG::Portal::_i18n::error_$_"} }, + "$translations{$_} translation" ); + ok( $#tmp == $#en, "$translations{$_} translation count" ); +} + +my $p = bless {}, 'Lemonldap::NG::Portal::Simple'; +$p->{error} = 10; +$ENV{HTTP_ACCEPT_LANGUAGE} = 'fr'; + +ok( $p->error() eq $p->error('fr'), 'HTTP_ACCEPT_LANGUAGE mechanism 1' ); +ok( $p->error() ne $p->error('ro'), 'HTTP_ACCEPT_LANGUAGE mechanism 2' ); + diff --git a/modules/lemonldap-ng-portal/t/Lemonldap-NG-Portal-AuthApache.t b/modules/lemonldap-ng-portal/t/20-Lemonldap-NG-Portal-AuthApache.t similarity index 80% rename from modules/lemonldap-ng-portal/t/Lemonldap-NG-Portal-AuthApache.t rename to modules/lemonldap-ng-portal/t/20-Lemonldap-NG-Portal-AuthApache.t index 9805ba7c6..424871f84 100644 --- a/modules/lemonldap-ng-portal/t/Lemonldap-NG-Portal-AuthApache.t +++ b/modules/lemonldap-ng-portal/t/20-Lemonldap-NG-Portal-AuthApache.t @@ -17,9 +17,9 @@ my $p; ok( $p = Lemonldap::NG::Portal::Simple->new( { - globalStorage => 'Apache::Session::File', - domain => 'example.com', - authentication => 'Apache', + globalStorage => 'Apache::Session::File', + domain => 'example.com', + authentication => 'Apache', } ) ); diff --git a/modules/lemonldap-ng-portal/t/Lemonldap-NG-Portal-AuthSSL.t b/modules/lemonldap-ng-portal/t/21-Lemonldap-NG-Portal-AuthSSL.t similarity index 77% rename from modules/lemonldap-ng-portal/t/Lemonldap-NG-Portal-AuthSSL.t rename to modules/lemonldap-ng-portal/t/21-Lemonldap-NG-Portal-AuthSSL.t index 6cd350246..028b6f29d 100644 --- a/modules/lemonldap-ng-portal/t/Lemonldap-NG-Portal-AuthSSL.t +++ b/modules/lemonldap-ng-portal/t/21-Lemonldap-NG-Portal-AuthSSL.t @@ -17,9 +17,10 @@ my $p; ok( $p = Lemonldap::NG::Portal::Simple->new( { - globalStorage => 'Apache::Session::File', - domain => 'example.com', - authentication => 'SSL', + globalStorage => 'Apache::Session::File', + domain => 'example.com', + authentication => 'SSL', + SSLRequired => 0, } ) ); diff --git a/modules/lemonldap-ng-portal/t/Lemonldap-NG-Portal-AuthCAS.t b/modules/lemonldap-ng-portal/t/22-Lemonldap-NG-Portal-AuthCAS.t similarity index 65% rename from modules/lemonldap-ng-portal/t/Lemonldap-NG-Portal-AuthCAS.t rename to modules/lemonldap-ng-portal/t/22-Lemonldap-NG-Portal-AuthCAS.t index c1a89d96e..708863eca 100644 --- a/modules/lemonldap-ng-portal/t/Lemonldap-NG-Portal-AuthCAS.t +++ b/modules/lemonldap-ng-portal/t/22-Lemonldap-NG-Portal-AuthCAS.t @@ -16,16 +16,22 @@ use Test::More tests => 1; # not run. SKIP: { eval { require AuthCAS }; - skip "AuthCAS is not installed, so Lemonldap::NG::Portal::AuthCAS will not be useable", 1 if ($@); + skip +"AuthCAS is not installed, so Lemonldap::NG::Portal::AuthCAS will not be useable", + 1 + if ($@); my $p; eval { require Lemonldap::NG::Portal::Simple }; - skip "Problem with Lemonldap::NG::Portal::Simple, Lemonldap::NG::Portal::AuthCAS will not be tested", 1 if ($@); + skip +"Problem with Lemonldap::NG::Portal::Simple, Lemonldap::NG::Portal::AuthCAS will not be tested", + 1 + if ($@); ok( $p = Lemonldap::NG::Portal::Simple->new( { - globalStorage => 'Apache::Session::File', - domain => 'example.com', - authentication => 'CAS', + globalStorage => 'Apache::Session::File', + domain => 'example.com', + authentication => 'CAS', } ) ); diff --git a/modules/lemonldap-ng-portal/t/Lemonldap-NG-Portal-AuthLA.t b/modules/lemonldap-ng-portal/t/23-Lemonldap-NG-Portal-AuthLA.t similarity index 100% rename from modules/lemonldap-ng-portal/t/Lemonldap-NG-Portal-AuthLA.t rename to modules/lemonldap-ng-portal/t/23-Lemonldap-NG-Portal-AuthLA.t diff --git a/modules/lemonldap-ng-portal/t/Lemonldap-NG-Portal-CDA.t b/modules/lemonldap-ng-portal/t/40-Lemonldap-NG-Portal-CDA.t similarity index 100% rename from modules/lemonldap-ng-portal/t/Lemonldap-NG-Portal-CDA.t rename to modules/lemonldap-ng-portal/t/40-Lemonldap-NG-Portal-CDA.t diff --git a/modules/lemonldap-ng-portal/t/Lemonldap-NG-Portal-Simple.t b/modules/lemonldap-ng-portal/t/Lemonldap-NG-Portal-Simple.t deleted file mode 100644 index e280e3b31..000000000 --- a/modules/lemonldap-ng-portal/t/Lemonldap-NG-Portal-Simple.t +++ /dev/null @@ -1,39 +0,0 @@ -# Before `make install' is performed this script should be runnable with -# `make test'. After `make install' it should work as `perl Lemonldap-NG-Portal.t' - -######################### - -# change 'tests => 1' to 'tests => last_test_to_print'; - -use Test::More tests => 6; - -BEGIN { use_ok( 'Lemonldap::NG::Portal::Simple', ':all' ) } - -SKIP: { - eval { require Net::LDAP::Control::PasswordPolicy }; - skip "Net::LDAP Password Policy Control is not installed (perl-ldap >= 0.35), so Password Policy will not be usable", - 1 - if ($@); - use_ok('Net::LDAP::Control::PasswordPolicy') -} - -######################### - -# Insert your test code below, the Test::More module is use()ed here so read -# its man page ( perldoc Test::More ) for help writing this test script. - -my $p; -ok( - $p = Lemonldap::NG::Portal::Simple->new( - { - globalStorage => 'Apache::Session::File', - domain => 'example.com', - } - ) -); - -ok( $p->process == 0 ); -ok( $p->{error} == PE_FIRSTACCESS ); -$p->{id} = 1; -ok( $p->buildCookie == PE_OK ); - diff --git a/modules/lemonldap-ng-portal/t/Lemonldap-NG-Portal-i18n.t b/modules/lemonldap-ng-portal/t/Lemonldap-NG-Portal-i18n.t deleted file mode 100644 index de6ce0cab..000000000 --- a/modules/lemonldap-ng-portal/t/Lemonldap-NG-Portal-i18n.t +++ /dev/null @@ -1,24 +0,0 @@ -# Before `make install' is performed this script should be runnable with -# `make test'. After `make install' it should work as `perl Lemonldap-NG-Portal.t' - -######################### - -# change 'tests => 1' to 'tests => last_test_to_print'; - -use Test::More tests => 34; -BEGIN { use_ok( 'Lemonldap::NG::Portal::Simple', ':all' ) } - -######################### - -# Insert your test code below, the Test::More module is use()ed here so read -# its man page ( perldoc Test::More ) for help writing this test script. - -my $p = bless {}, 'Lemonldap::NG::Portal::Simple'; - -foreach my $i ( 0 .. 10 ) { - $p->{error} = $i; - ok( $p->error('fr') ); - ok( $p->error('en') ); - ok( $p->error('') ); -} -