2008-06-06 05:53:14 +02:00
|
|
|
# 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';
|
|
|
|
|
2013-05-23 21:07:48 +02:00
|
|
|
use Test::More tests => 13;
|
2008-06-06 05:53:14 +02:00
|
|
|
|
|
|
|
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} = '';
|
2010-08-23 15:27:16 +02:00
|
|
|
$ENV{REMOTE_ADDR} = '127.0.0.1';
|
2008-06-06 05:53:14 +02:00
|
|
|
|
|
|
|
ok(
|
|
|
|
$p = Lemonldap::NG::Portal::Simple->new(
|
|
|
|
{
|
2014-02-14 09:26:25 +01:00
|
|
|
globalStorage => 'Apache::Session::File',
|
|
|
|
domain => 'example.com',
|
|
|
|
authentication => 'LDAP test=1',
|
|
|
|
userDB => 'LDAP',
|
|
|
|
passwordDB => 'LDAP',
|
2014-05-29 09:38:50 +02:00
|
|
|
registerDB => 'LDAP',
|
2014-02-14 09:26:25 +01:00
|
|
|
cookieName => 'lemonldap',
|
|
|
|
whatToTrace => '_user',
|
|
|
|
multiValuesSeparator => '; ',
|
|
|
|
securedCookie => 0,
|
|
|
|
user => '',
|
|
|
|
password => '',
|
2008-06-06 05:53:14 +02:00
|
|
|
}
|
|
|
|
),
|
|
|
|
'Portal object'
|
|
|
|
);
|
|
|
|
|
|
|
|
# Arg test passed
|
|
|
|
ok( $p->{test}, 'Authentication arguments' );
|
|
|
|
|
|
|
|
# Process test: first access
|
2009-12-03 11:08:33 +01:00
|
|
|
$ENV{REQUEST_URI} = '/?user=&password=';
|
|
|
|
$ENV{QUERY_STRING} = 'user=&password=';
|
2008-06-06 05:53:14 +02:00
|
|
|
ok( $p->process == 0, 'No user' );
|
|
|
|
ok( $p->{error} == PE_FIRSTACCESS, 'Error code: first access' );
|
|
|
|
|
|
|
|
# Process test: user without password
|
2008-06-13 16:53:43 +02:00
|
|
|
$ENV{REQUEST_URI} = '/?user=test&password=';
|
|
|
|
$ENV{QUERY_STRING} = 'user=test&password=';
|
2008-06-06 05:53:14 +02:00
|
|
|
$p = Lemonldap::NG::Portal::Simple->new(
|
|
|
|
{
|
2014-02-14 09:26:25 +01:00
|
|
|
globalStorage => 'Apache::Session::File',
|
|
|
|
domain => 'example.com',
|
|
|
|
authentication => 'LDAP test=1',
|
|
|
|
userDB => 'Null',
|
|
|
|
passwordDB => 'Null',
|
2014-05-29 09:38:50 +02:00
|
|
|
registerDB => 'Null',
|
2014-02-14 09:26:25 +01:00
|
|
|
cookieName => 'lemonldap',
|
|
|
|
whatToTrace => 'dummy',
|
|
|
|
multiValuesSeparator => '; ',
|
|
|
|
securedCookie => 0,
|
2008-06-06 05:53:14 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
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;
|
2010-04-30 07:27:06 +02:00
|
|
|
$self->{user} = 'user';
|
|
|
|
$self->{password} = '';
|
2008-06-06 05:53:14 +02:00
|
|
|
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 };
|
2010-04-30 07:27:06 +02:00
|
|
|
$p->{store} = sub {
|
|
|
|
my $self = shift;
|
|
|
|
$self->{id} = 1;
|
|
|
|
PE_OK;
|
|
|
|
};
|
2010-09-01 14:56:15 +02:00
|
|
|
$p->{authenticate} = sub { PE_OK };
|
|
|
|
$p->{authFinish} = sub { PE_OK };
|
2013-05-23 21:07:48 +02:00
|
|
|
|
|
|
|
$p->{macros} = {
|
|
|
|
macro1 => '"foo"',
|
|
|
|
macro2 => '$macro1',
|
|
|
|
macro3 => '$macro2',
|
|
|
|
macro4 => '$macro3',
|
|
|
|
};
|
|
|
|
$p->{groups} = {
|
|
|
|
group1 => '1',
|
|
|
|
group2 => '$groups =~ /\bgroup1\b/',
|
|
|
|
group3 => '$groups =~ /\bgroup2\b/',
|
|
|
|
group4 => '$groups =~ /\bgroup3\b/',
|
|
|
|
};
|
|
|
|
|
2008-12-25 15:14:15 +01:00
|
|
|
ok( $p->process > 0, 'User OK' );
|
2013-05-30 16:41:02 +02:00
|
|
|
ok(
|
|
|
|
$p->{sessionInfo}->{macro4} eq "foo",
|
|
|
|
"Macros computed in alphanumeric order"
|
|
|
|
);
|
|
|
|
ok(
|
|
|
|
$p->{sessionInfo}->{groups} =~ /\bgroup4\b/,
|
|
|
|
"Groups computed in alphanumeric order"
|
|
|
|
);
|
2008-06-06 05:53:14 +02:00
|
|
|
|
|
|
|
# Cookie test
|
|
|
|
ok( $p->{cookie}->[0]->value eq '1', 'Cookie value' );
|
|
|
|
|
2012-12-18 10:52:54 +01:00
|
|
|
# Time conversion
|
2013-02-17 23:25:26 +01:00
|
|
|
my ( $d, $h, $m, $s ) = $p->convertSec('123456');
|
|
|
|
ok( $d == 1 && $h == 10 && $m == 17 && $s == 36, 'Time conversion' );
|
2012-12-18 10:52:54 +01:00
|
|
|
|