LEMONLDAP::NG test for Handler/Status.pm

environments/ppa-mbqj77/deployments/1
Xavier Guimard 17 years ago
parent a4b9df90dd
commit 2b1df6d588
  1. 59
      modules/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/Simple.pm
  2. 24
      modules/lemonldap-ng-handler/t/01-Lemonldap-NG-Handler-Simple.t
  3. 6
      modules/lemonldap-ng-handler/t/05-Lemonldap-NG-Handler-Vhost.t
  4. 57
      modules/lemonldap-ng-handler/t/11-Lemonldap-NG-Handler-Status.t

@ -5,6 +5,7 @@ use strict;
use MIME::Base64; use MIME::Base64;
use Exporter 'import'; use Exporter 'import';
use Safe; use Safe;
require Data::Dumper;
require POSIX; require POSIX;
our $VERSION = '0.87'; our $VERSION = '0.87';
@ -224,6 +225,36 @@ sub lmHeaderOut {
} }
} }
# Status daemon creation
sub statusProcess {
require IO::Pipe;
$statusPipe = IO::Pipe->new;
$statusOut = IO::Pipe->new;
if ( my $pid = fork() ) {
$statusPipe->writer();
$statusOut->reader();
$statusPipe->autoflush(1);
}
else {
$statusPipe->reader();
$statusOut->writer();
my $fdin = $statusPipe->fileno;
my $fdout = $statusOut->fileno;
open STDIN, "<&$fdin";
open STDOUT, ">&$fdout";
my @tmp = ();
push @tmp, "-I$_" foreach (@INC);
exec 'perl', '-MLemonldap::NG::Handler::Status',
@tmp,
'-e',
'&Lemonldap::NG::Handler::Status::run('
. $localStorage . ','
. Data::Dumper->new( [$localStorageOptions] )->Terse(1)->Dump
. ');';
}
}
############################## ##############################
# Initialization subroutines # # Initialization subroutines #
############################## ##############################
@ -266,33 +297,7 @@ sub localInit($$) {
} }
} }
if ( $args->{status} ) { if ( $args->{status} ) {
require IO::Pipe; statusProcess();
$statusPipe = IO::Pipe->new;
$statusOut = IO::Pipe->new;
if ( my $pid = fork() ) {
$statusPipe->writer();
$statusOut->reader();
$statusPipe->autoflush(1);
}
else {
$statusPipe->reader();
$statusOut->writer();
my $fdin = $statusPipe->fileno;
my $fdout = $statusOut->fileno;
open STDIN, "<&$fdin";
#open STDOUT, '>/tmp/log';
open STDOUT, ">&$fdout";
my @tmp = ();
push @tmp, "-I$_" foreach (@INC);
exec 'perl', '-MLemonldap::NG::Handler::Status',
@tmp,
'-e',
'&Lemonldap::NG::Handler::Status::run('
. $localStorage . ','
. Data::Dumper->new( [$localStorageOptions] )->Terse(1)->Dump
. ');';
}
} }
# We don't initialise local storage in the "init" subroutine because it can # We don't initialise local storage in the "init" subroutine because it can

@ -20,7 +20,8 @@ ok(
localStorage => 'Cache::FileCache', localStorage => 'Cache::FileCache',
localStorageOptions => { 'namespace' => 'MyNamespace', }, localStorageOptions => { 'namespace' => 'MyNamespace', },
} }
) ),
'localInit'
); );
ok( ok(
@ -32,22 +33,25 @@ ok(
'test' => '$groups =~ /\badmin\b/', 'test' => '$groups =~ /\badmin\b/',
}, },
} }
) ),
'locationRulesInit'
); );
ok( $h->defaultValuesInit() ); ok( $h->defaultValuesInit(), 'defaultValuesInit' );
ok( $h->portalInit( { portal => 'http://auth.example.com' } ) ); ok( $h->portalInit( { portal => 'http://auth.example.com' } ), 'portalInit' );
ok( ok(
$h->globalStorageInit( $h->globalStorageInit(
{ {
globalStorage => 'Apache::Session::File', globalStorage => 'Apache::Session::File',
globalStorageOptions => {}, globalStorageOptions => {},
} }
) ),
'globalStorageInit'
); );
ok( $h->forgeHeadersInit ); ok( $h->forgeHeadersInit, 'forgeHeadersInit' );
ok( $h->forgeHeadersInit( { exportedHeaders => { Auth => '$uid', } } ) ); ok( $h->forgeHeadersInit( { exportedHeaders => { Auth => '$uid', } } ),
'forgeHeadersInit 2' );
ok( $h->grant('/s') ); ok( $h->grant('/s'), 'grant OK' );
ok( !$h->grant('/no') ); ok( !$h->grant('/no'), 'grant NOK' );
ok( $h->cleanLocalStorage == DECLINED ); ok( $h->cleanLocalStorage == DECLINED, 'cleanLocalStorage' );

@ -34,12 +34,14 @@ ok(
}, },
}, },
} }
) ),
'locationRulesInit'
); );
ok( ok(
$h->forgeHeadersInit( $h->forgeHeadersInit(
{ exportedHeaders => { www1 => { Auth => '$uid', } } } { exportedHeaders => { www1 => { Auth => '$uid', } } }
) ),
'forgeHeadersInit'
); );

@ -0,0 +1,57 @@
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl Lemonldap-NG-Handler.t'
#########################
# change 'tests => 1' to 'tests => last_test_to_print';
use Test::More tests => 9;
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', },
status => 1
}
),
'New Object'
);
ok( $statusPipe->isa('IO::Pipe::End'), 'In pipe' );
ok( $statusOut->isa('IO::Pipe::End'), 'Out pipe' );
ok( print( $statusPipe "uid => / OK\nuid => / OK\nuid => /no REJECT\n" ),
'New requests' );
ok( print( $statusPipe "STATUS\n" ), 'Status request' );
ok( &read, 'Status result' );
ok( close($statusOut) );
ok( close($statusPipe) );
sub read {
my $ok = 0;
open LOG, '>/tmp/log';
while (<$statusOut>) {
print LOG $_;
$ok++ if (/^OK\s+:\s*2$/);
$ok++ if (/^REJECT\s+:\s*1$/);
if (/^END$/) {
$ok++;
last;
}
}
close LOG;
return ( $ok == 3 );
}
Loading…
Cancel
Save