LEMONLDAP::NG test for Handler/Status.pm
This commit is contained in:
parent
a4b9df90dd
commit
2b1df6d588
|
@ -5,6 +5,7 @@ use strict;
|
|||
use MIME::Base64;
|
||||
use Exporter 'import';
|
||||
use Safe;
|
||||
require Data::Dumper;
|
||||
require POSIX;
|
||||
|
||||
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 #
|
||||
##############################
|
||||
|
@ -266,33 +297,7 @@ sub localInit($$) {
|
|||
}
|
||||
}
|
||||
if ( $args->{status} ) {
|
||||
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, '>/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
|
||||
. ');';
|
||||
}
|
||||
statusProcess();
|
||||
}
|
||||
|
||||
# We don't initialise local storage in the "init" subroutine because it can
|
||||
|
|
|
@ -20,7 +20,8 @@ ok(
|
|||
localStorage => 'Cache::FileCache',
|
||||
localStorageOptions => { 'namespace' => 'MyNamespace', },
|
||||
}
|
||||
)
|
||||
),
|
||||
'localInit'
|
||||
);
|
||||
|
||||
ok(
|
||||
|
@ -32,22 +33,25 @@ ok(
|
|||
'test' => '$groups =~ /\badmin\b/',
|
||||
},
|
||||
}
|
||||
)
|
||||
),
|
||||
'locationRulesInit'
|
||||
);
|
||||
|
||||
ok( $h->defaultValuesInit() );
|
||||
ok( $h->portalInit( { portal => 'http://auth.example.com' } ) );
|
||||
ok( $h->defaultValuesInit(), 'defaultValuesInit' );
|
||||
ok( $h->portalInit( { portal => 'http://auth.example.com' } ), 'portalInit' );
|
||||
ok(
|
||||
$h->globalStorageInit(
|
||||
{
|
||||
globalStorage => 'Apache::Session::File',
|
||||
globalStorageOptions => {},
|
||||
}
|
||||
)
|
||||
),
|
||||
'globalStorageInit'
|
||||
);
|
||||
ok( $h->forgeHeadersInit );
|
||||
ok( $h->forgeHeadersInit( { exportedHeaders => { Auth => '$uid', } } ) );
|
||||
ok( $h->forgeHeadersInit, 'forgeHeadersInit' );
|
||||
ok( $h->forgeHeadersInit( { exportedHeaders => { Auth => '$uid', } } ),
|
||||
'forgeHeadersInit 2' );
|
||||
|
||||
ok( $h->grant('/s') );
|
||||
ok( !$h->grant('/no') );
|
||||
ok( $h->cleanLocalStorage == DECLINED );
|
||||
ok( $h->grant('/s'), 'grant OK' );
|
||||
ok( !$h->grant('/no'), 'grant NOK' );
|
||||
ok( $h->cleanLocalStorage == DECLINED, 'cleanLocalStorage' );
|
||||
|
|
|
@ -34,12 +34,14 @@ ok(
|
|||
},
|
||||
},
|
||||
}
|
||||
)
|
||||
),
|
||||
'locationRulesInit'
|
||||
);
|
||||
|
||||
ok(
|
||||
$h->forgeHeadersInit(
|
||||
{ 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…
Reference in New Issue
Block a user