LEMONLDAP::NG : more tests in Handler and perltidy on test files

This commit is contained in:
Xavier Guimard 2007-04-15 12:44:29 +00:00
parent d5bdcdcd80
commit cf4f11b7a0
25 changed files with 154 additions and 46 deletions

View File

@ -2,7 +2,7 @@ package Lemonldap::NG::Handler;
print STDERR
"See Lemonldap::NG::Handler(3) to know which Lemonldap::NG::Handler::* module to use.";
our $VERSION = "0.8";
our $VERSION = "0.81";
1;

View File

@ -10,13 +10,14 @@ our @ISA = qw(CGI);
use Lemonldap::NG::Handler::SharedConf qw(:all);
our $VERSION = '0.01';
our $VERSION = '0.02';
sub new {
my $class = shift;
my $self = $class->SUPER::new();
$self->{_handler} = bless {}, 'Lemonldap::NG::Handler::_CGI';
$self->_handler->init( @_ );
$self->initLocalStorage();
die "Unable to get configuration" unless $self->_handler->localConfUpdate() == OK;
return $self;
}

View File

@ -7,7 +7,7 @@ use Exporter 'import';
use Safe;
require POSIX;
our $VERSION = '0.8';
our $VERSION = '0.81';
our %EXPORT_TAGS = (
localStorage =>
@ -231,7 +231,7 @@ sub localInit($$) {
$localStorageOptions->{default_expires_in} ||= 600;
eval "use $localStorage;";
die("Unable to load $localStorage") if ($@);
die("Unable to load $localStorage: $@") if ($@);
# At each Apache (re)start, we've to clear the cache to avoid living
# with old datas
@ -269,6 +269,7 @@ sub localInit($$) {
PerlCleanupHandler => sub { return $class->cleanLocalStorage(@_); }
);
}
1;
}
# Global initialization process :
@ -308,6 +309,7 @@ sub locationRulesInit {
# Default police: all authenticated users are accepted
$defaultCondition = $class->conditionSub('accept')
unless ($defaultCondition);
1;
}
# conditionSub returns a pre-compiled subroutine used to grant users (used by
@ -336,6 +338,7 @@ sub defaultValuesInit {
$whatToTrace =~ s/\$//g;
$https = $args->{https} unless defined($https);
$https = 1 unless defined($https);
1;
}
# portalInit : verify that portal variable exists
@ -385,6 +388,7 @@ sub forgeHeadersInit {
$forgeHeaders = $safe->reval("sub {$sub};");
$class->lmLog( "$class: Unable to forge headers: $@: sub {$sub}", 'error' )
if ($@);
1;
}
################

View File

@ -29,6 +29,7 @@ sub locationRulesInit {
$defaultCondition->{$vhost} = $class->conditionSub('accept')
unless ( $defaultCondition->{$vhost} );
}
1;
}
sub forgeHeadersInit {
@ -56,6 +57,7 @@ sub forgeHeadersInit {
'error' )
if ($@);
}
1;
}
sub sendHeaders {

View File

@ -6,7 +6,7 @@
# change 'tests => 1' to 'tests => last_test_to_print';
use Test::More tests => 1;
BEGIN { use_ok('Lemonldap::NG::Handler::CDA') };
BEGIN { use_ok('Lemonldap::NG::Handler::CDA') }
#########################

View File

@ -6,7 +6,7 @@
# change 'tests => 1' to 'tests => last_test_to_print';
use Test::More tests => 1;
BEGIN { use_ok('Lemonldap::NG::Handler::CGI') };
BEGIN { use_ok('Lemonldap::NG::Handler::CGI') }
#########################

View File

@ -6,7 +6,7 @@
# change 'tests => 1' to 'tests => last_test_to_print';
use Test::More tests => 1;
BEGIN { use_ok('Lemonldap::NG::Handler::Proxy') };
BEGIN { use_ok('Lemonldap::NG::Handler::Proxy') }
#########################

View File

@ -6,7 +6,7 @@
# change 'tests => 1' to 'tests => last_test_to_print';
use Test::More tests => 1;
BEGIN { use_ok('Lemonldap::NG::Handler::SharedConf') };
BEGIN { use_ok('Lemonldap::NG::Handler::SharedConf') }
#########################

View File

@ -5,11 +5,49 @@
# change 'tests => 1' to 'tests => last_test_to_print';
use Test::More tests => 1;
BEGIN { use_ok('Lemonldap::NG::Handler::Simple') };
use Test::More tests => 11;
BEGIN { use_ok( 'Lemonldap::NG::Handler::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 $h;
$h = bless {}, 'Lemonldap::NG::Handler::Simple';
ok(
$h->localInit(
{
localStorage => 'Cache::FileCache',
localStorageOptions => { 'namespace' => 'MyNamespace', },
}
)
);
ok(
$h->locationRulesInit(
{
locationRules => {
default => 'accept',
'^/no' => 'deny',
'test' => '$groups =~ /\badmin\b/',
},
}
)
);
ok( $h->defaultValuesInit() );
ok( $h->portalInit( { portal => 'http://auth.example.com' } ) );
ok(
$h->globalStorageInit(
{
globalStorage => 'Apache::Session::File',
globalStorageOptions => {},
}
)
);
ok( $h->forgeHeadersInit );
ok( $h->forgeHeadersInit( { exportedHeaders => { Auth => '$uid', } } ) );
ok( $h->grant('/s') );
ok( !$h->grant('/no') );
ok( $h->cleanLocalStorage == DECLINED );

View File

@ -5,11 +5,41 @@
# change 'tests => 1' to 'tests => last_test_to_print';
use Test::More tests => 1;
BEGIN { use_ok('Lemonldap::NG::Handler::Vhost') };
package My::Package;
use Test::More tests => 4;
BEGIN {
use_ok('Lemonldap::NG::Handler::Vhost');
use_ok('Lemonldap::NG::Handler::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.
our @ISA = qw( Lemonldap::NG::Handler::Vhost Lemonldap::NG::Handler::Simple );
my $h;
$h = bless {}, 'My::Package';
ok(
$h->locationRulesInit(
{
locationRules => {
www1 => {
default => 'accept',
'^/no' => 'deny',
'test' => '$groups =~ /\badmin\b/',
},
},
}
)
);
ok(
$h->forgeHeadersInit(
{ exportedHeaders => { www1 => { Auth => '$uid', } } }
)
);

View File

@ -6,7 +6,7 @@
# change 'tests => 1' to 'tests => last_test_to_print';
use Test::More tests => 1;
BEGIN { use_ok('Lemonldap::NG::Manager::Conf::DBI') };
BEGIN { use_ok('Lemonldap::NG::Manager::Conf::DBI') }
#########################

View File

@ -6,7 +6,7 @@
# change 'tests => 1' to 'tests => last_test_to_print';
use Test::More tests => 1;
BEGIN { use_ok('Lemonldap::NG::Manager::Conf::File') };
BEGIN { use_ok('Lemonldap::NG::Manager::Conf::File') }
#########################

View File

@ -6,11 +6,15 @@
# change 'tests => 1' to 'tests => last_test_to_print';
use Test::More tests => 1;
# SOAP::Lite is not required, so Lemonldap::NG::Manager::Conf::SOAP may
# not run.
SKIP: {
eval { require SOAP::Lite };
skip "SOAP::Lite is not installed, so SOAP configuration access will not work", 1 if($@);
skip
"SOAP::Lite is not installed, so SOAP configuration access will not work",
1
if ($@);
use_ok('Lemonldap::NG::Manager::Conf::SOAP');
}

View File

@ -6,7 +6,7 @@
# change 'tests => 1' to 'tests => last_test_to_print';
use Test::More tests => 1;
BEGIN { use_ok('Lemonldap::NG::Manager::Conf') };
BEGIN { use_ok('Lemonldap::NG::Manager::Conf') }
#########################

View File

@ -16,8 +16,9 @@ BEGIN { use_ok('Lemonldap::NG::Manager') }
$ENV{SCRIPT_NAME} = "__SCRIPTNAME__";
$ENV{SCRIPT_FILENAME} = $0;
my $h;
@ARGV = ( "help=groups" );
ok( $h = new Lemonldap::NG::Manager(
@ARGV = ("help=groups");
ok(
$h = new Lemonldap::NG::Manager(
{
configStorage => {
type => 'File',
@ -26,7 +27,8 @@ ok( $h = new Lemonldap::NG::Manager(
dhtmlXTreeImageLocation => "/imgs/",
jsFile => 'example/lemonldap-ng-manager.js',
}
));
)
);
ok( $h->header_public() );
ok( $h->start_html() );
ok( $h->main() );
@ -36,10 +38,10 @@ ok( $h->print_lmjs() );
ok( $h->print_help() );
ok( $h->buildTree() );
my $tmp = &xml;
ok( ref($h->tree2conf( \$tmp )) );
ok( ref( $h->tree2conf( \$tmp ) ) );
sub xml {
return << 'EOF';
return << 'EOF';
<root><text>Configuration 9</text>
<generalParameters><text>Paramtres gnraux</text>
<authParams><text>Paramtres d'authentification</text>

View File

@ -17,8 +17,9 @@ $ENV{SCRIPT_NAME} = "__SCRIPTNAME__";
$ENV{SCRIPT_FILENAME} = $0;
$ENV{HTTP_ACCEPT_LANGUAGE} = "en";
my $h;
@ARGV = ( "help=groups" );
ok( $h = new Lemonldap::NG::Manager(
@ARGV = ("help=groups");
ok(
$h = new Lemonldap::NG::Manager(
{
configStorage => {
type => 'File',
@ -27,7 +28,8 @@ ok( $h = new Lemonldap::NG::Manager(
dhtmlXTreeImageLocation => "/imgs/",
jsFile => 'example/lemonldap-ng-manager.js',
}
));
)
);
ok( $h->main() );
ok( $h->print_help() );
ok( $h->buildTree() );

View File

@ -17,8 +17,9 @@ $ENV{SCRIPT_NAME} = "__SCRIPTNAME__";
$ENV{SCRIPT_FILENAME} = $0;
$ENV{HTTP_ACCEPT_LANGUAGE} = "fr";
my $h;
@ARGV = ( "help=groups" );
ok( $h = new Lemonldap::NG::Manager(
@ARGV = ("help=groups");
ok(
$h = new Lemonldap::NG::Manager(
{
configStorage => {
type => 'File',
@ -27,7 +28,8 @@ ok( $h = new Lemonldap::NG::Manager(
dhtmlXTreeImageLocation => "/imgs/",
jsFile => 'example/lemonldap-ng-manager.js',
}
));
)
);
ok( $h->main() );
ok( $h->print_help() );
ok( $h->buildTree() );

View File

@ -6,7 +6,7 @@
# change 'tests => 1' to 'tests => last_test_to_print';
use Test::More tests => 2;
BEGIN { use_ok('Lemonldap::NG::Portal::Simple') };
BEGIN { use_ok('Lemonldap::NG::Portal::Simple') }
#########################
@ -14,9 +14,13 @@ BEGIN { use_ok('Lemonldap::NG::Portal::Simple') };
# its man page ( perldoc Test::More ) for help writing this test script.
my $p;
ok( $p = Lemonldap::NG::Portal::Simple->new( {
ok(
$p = Lemonldap::NG::Portal::Simple->new(
{
globalStorage => 'Apache::Session::File',
domain => 'example.com',
authentication => 'Apache',
} ) );
}
)
);

View File

@ -16,13 +16,20 @@ use Test::More tests => 2;
# 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 ($@);
use_ok('Lemonldap::NG::Portal::Simple');
my $p;
ok( $p = Lemonldap::NG::Portal::Simple->new( {
ok(
$p = Lemonldap::NG::Portal::Simple->new(
{
globalStorage => 'Apache::Session::File',
domain => 'example.com',
authentication => 'CAS',
} ) );
}
)
);
}

View File

@ -6,11 +6,15 @@
# change 'tests => 1' to 'tests => last_test_to_print';
use Test::More tests => 1;
# SOAP::Lite is not required, so Lemonldap::NG::Manager::Conf::SOAP may
# not run.
SKIP: {
eval { require lasso };
skip "lasso is not installed, so Lemonldap::NG::Portal::AuthLA will not be useable", 1 if($@);
skip
"lasso is not installed, so Lemonldap::NG::Portal::AuthLA will not be useable",
1
if ($@);
use_ok('Lemonldap::NG::Portal::AuthLA');
}

View File

@ -6,7 +6,7 @@
# change 'tests => 1' to 'tests => last_test_to_print';
use Test::More tests => 2;
BEGIN { use_ok('Lemonldap::NG::Portal::Simple') };
BEGIN { use_ok('Lemonldap::NG::Portal::Simple') }
#########################
@ -14,9 +14,13 @@ BEGIN { use_ok('Lemonldap::NG::Portal::Simple') };
# its man page ( perldoc Test::More ) for help writing this test script.
my $p;
ok( $p = Lemonldap::NG::Portal::Simple->new( {
ok(
$p = Lemonldap::NG::Portal::Simple->new(
{
globalStorage => 'Apache::Session::File',
domain => 'example.com',
authentication => 'SSL',
} ) );
}
)
);

View File

@ -6,7 +6,7 @@
# change 'tests => 1' to 'tests => last_test_to_print';
use Test::More tests => 1;
BEGIN { use_ok('Lemonldap::NG::Portal::CDA') };
BEGIN { use_ok('Lemonldap::NG::Portal::CDA') }
#########################

View File

@ -6,7 +6,7 @@
# change 'tests => 1' to 'tests => last_test_to_print';
use Test::More tests => 3;
BEGIN { use_ok('Lemonldap::NG::Portal::SharedConf') };
BEGIN { use_ok('Lemonldap::NG::Portal::SharedConf') }
#########################
@ -14,6 +14,6 @@ BEGIN { use_ok('Lemonldap::NG::Portal::SharedConf') };
# its man page ( perldoc Test::More ) for help writing this test script.
my $p = bless {}, 'Lemonldap::NG::Portal::SharedConf';
ok( ! $p->scanexpr ( '1 == 0' ) );
ok( $p->scanexpr ( '1 == 1' ) );
ok( !$p->scanexpr('1 == 0') );
ok( $p->scanexpr('1 == 1') );

View File

@ -6,7 +6,7 @@
# change 'tests => 1' to 'tests => last_test_to_print';
use Test::More tests => 5;
BEGIN { use_ok('Lemonldap::NG::Portal::Simple', ':all') };
BEGIN { use_ok( 'Lemonldap::NG::Portal::Simple', ':all' ) }
#########################
@ -14,10 +14,14 @@ BEGIN { use_ok('Lemonldap::NG::Portal::Simple', ':all') };
# its man page ( perldoc Test::More ) for help writing this test script.
my $p;
ok( $p = Lemonldap::NG::Portal::Simple->new( {
ok(
$p = Lemonldap::NG::Portal::Simple->new(
{
globalStorage => 'Apache::Session::File',
domain => 'example.com',
} ) );
}
)
);
ok( $p->process == 0 );
ok( $p->{error} == PE_FIRSTACCESS );

View File

@ -6,7 +6,7 @@
# change 'tests => 1' to 'tests => last_test_to_print';
use Test::More tests => 31;
BEGIN { use_ok('Lemonldap::NG::Portal::Simple', ':all') };
BEGIN { use_ok( 'Lemonldap::NG::Portal::Simple', ':all' ) }
#########################
@ -15,7 +15,7 @@ BEGIN { use_ok('Lemonldap::NG::Portal::Simple', ':all') };
my $p = bless {}, 'Lemonldap::NG::Portal::Simple';
foreach my $i (1..10) {
foreach my $i ( 1 .. 10 ) {
$p->{error} = $i;
ok( $p->error('fr;en') );
ok( $p->error('en') );