Commit 5d382a50 authored by Yadd's avatar Yadd
Browse files

Remove old tests

parent bb39433a
# 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 => 13;
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} = '';
$ENV{REMOTE_ADDR} = '127.0.0.1';
$ENV{HTTP_ACCEPT} = 'text/html';
ok(
$p = Lemonldap::NG::Portal::Simple->new(
{
globalStorage => 'Apache::Session::File',
domain => 'example.com',
authentication => 'LDAP test=1',
userDB => 'LDAP',
passwordDB => 'LDAP',
registerDB => 'LDAP',
cookieName => 'lemonldap',
whatToTrace => '_user',
multiValuesSeparator => '; ',
securedCookie => 0,
user => '',
password => '',
}
),
'Portal object'
);
# Arg test passed
ok( $p->{test}, 'Authentication arguments' );
# Process test: first access
$ENV{REQUEST_URI} = '/?user=&password=';
$ENV{QUERY_STRING} = 'user=&password=';
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&password=';
$ENV{QUERY_STRING} = 'user=test&password=';
$p = Lemonldap::NG::Portal::Simple->new(
{
globalStorage => 'Apache::Session::File',
domain => 'example.com',
authentication => 'LDAP test=1',
userDB => 'Null',
passwordDB => 'Null',
registerDB => 'Null',
cookieName => 'lemonldap',
whatToTrace => 'dummy',
multiValuesSeparator => '; ',
securedCookie => 0,
}
);
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';
$self->{password} = '';
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 {
my $self = shift;
$self->{id} = 1;
PE_OK;
};
$p->{authenticate} = sub { PE_OK };
$p->{authFinish} = sub { PE_OK };
$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/',
};
ok( $p->process > 0, 'User OK' );
ok(
$p->{sessionInfo}->{macro4} eq "foo",
"Macros computed in alphanumeric order"
);
ok(
$p->{sessionInfo}->{groups} =~ /\bgroup4\b/,
"Groups computed in alphanumeric order"
);
# Cookie test
ok( $p->{cookie}->[0]->value eq '1', 'Cookie value' );
# Time conversion
my ( $d, $h, $m, $s ) = $p->convertSec('123456');
ok( $d == 1 && $h == 10 && $m == 17 && $s == 36, 'Time conversion' );
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl Lemonldap-NG-Portal-SharedConf.t'
#########################
# change 'tests => 1' to 'tests => last_test_to_print';
use Test::More tests => 2;
BEGIN { use_ok('Lemonldap::NG::Portal::SharedConf') }
#########################
# 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.
# Try to load an alternate conffile
use File::Temp;
my $dir = File::Temp::tempdir();
my $ini = File::Temp->new( DIR => $dir );
print $ini "[all]
portal=http://auth.example.com
[configuration]
type=File
dirName=$dir
[portal]
portalSkin = test
authentication = Demo
userDB = Demo
passwordDB = Null
registerDB = Null
";
$ini->flush();
open( CONF, ">$dir/lmConf-1.js" ) or die $@;
print CONF '{"cfgNum":1,"useXForwardedForIP":0,"key":"tmp"}';
CONF->flush();
my $portal = Lemonldap::NG::Portal::SharedConf->new(
{
globalStorage => 'Apache::Session::File',
domain => 'example.com',
configStorage => { confFile => "$ini" },
}
);
my $test = $portal->{portalSkin};
ok( $test eq "test", "Custom INI file" );
# 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 => 10;
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.
# Create portal object with Safe jail (the default)
my $p;
$ENV{REQUEST_METHOD} = "GET";
ok(
$p = Lemonldap::NG::Portal::Simple->new(
{
globalStorage => 'Apache::Session::File',
domain => 'example.com',
authentication => 'Null',
userDB => 'Null',
passwordDB => 'Null',
registerDB => 'Null',
useSafeJail => 1,
}
),
'Portal object with Safe jail'
);
# Fake data
my $sessionData = "coudot";
$p->{sessionInfo}->{uid} = $sessionData;
my $envData = "127.0.0.1";
$ENV{REMOTE_ADDR} = $envData;
# Real Safe jail
ok( $p->{useSafeJail} == 1, 'Safe jail on' );
ok( $p->safe->reval('$uid') eq $sessionData, 'Safe jail on - session data' );
ok( $p->safe->reval('$ENV{REMOTE_ADDR}') eq $envData,
'Safe jail on - env data' );
ok(
defined $p->safe->reval('checkDate(0,1)'),
'Safe jail on - extended function'
);
# Reset safe object
$Lemonldap::NG::Portal::Simple::safe = undef;
$p->{useSafeJail} = 0;
# Fake Safe jail
ok( $p->{useSafeJail} == 0, 'Safe jail off' );
ok( $p->safe->reval('$uid') eq $sessionData, 'Safe jail off - session data' );
ok( $p->safe->reval('$ENV{REMOTE_ADDR}') eq $envData,
'Safe jail off - env data' );
ok(
defined $p->safe->reval('checkDate(0,1)'),
'Safe jail off - extended function'
);
# 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 %tr_err = (
fr => 'French',
# Not yet maintained
ro => 'Romanian',
);
our %tr_msg = ( fr => 'French', );
}
use Test::More tests => 8 + ( keys(%tr_err) * 2 ) + ( keys(%tr_msg) * 2 );
BEGIN { use_ok('Lemonldap::NG::Portal::Simple') }
ok( my @en = @{&Lemonldap::NG::Portal::_i18n::error_en},
'English translation' );
ok( $#en > 21, 'Translation count' );
foreach ( keys %tr_err ) {
my @tmp;
ok( @tmp = @{ &{"Lemonldap::NG::Portal::_i18n::error_$_"} },
"$tr_err{$_} translation" );
ok( $#tmp == $#en, "$tr_err{$_} translation count (" . scalar(@tmp) . ')' );
}
my $p1 = bless {}, 'Lemonldap::NG::Portal::Simple';
$p1->{error} = 10;
$p1->{lang} = [ 'en', 'fr' ];
my $p2 = bless {}, 'Lemonldap::NG::Portal::Simple';
$p2->{error} = 5;
$p2->{lang} = [];
my $p3 = bless {}, 'Lemonldap::NG::Portal::Simple';
$p3->{error} = 10;
$p3->{lang} = [ 'fr', 'es', 'en' ];
ok( $p1->error() eq $p2->error(10), 'HTTP_ACCEPT_LANGUAGE mechanism 1' );
ok( $p1->error() ne $p2->error(), 'HTTP_ACCEPT_LANGUAGE mechanism 2' );
ok( $p1->error() ne $p3->error(), 'HTTP_ACCEPT_LANGUAGE mechanism 3' );
ok( @en = @{&Lemonldap::NG::Portal::_i18n::msg_en},
'English messages translation' );
ok( $#en > 19, 'Messages translation count' );
foreach ( keys %tr_msg ) {
my @tmp;
ok( @tmp = @{ &{"Lemonldap::NG::Portal::_i18n::msg_$_"} },
"$tr_msg{$_} messages translation" );
ok( $#tmp == $#en,
"$tr_msg{$_} messages translation count (" . scalar(@tmp) . ')' );
}
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl Lemonldap-NG-Portal-AuthSsl.t'
#########################
# change 'tests => 1' to 'tests => last_test_to_print';
use Test::More tests => 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.
$ENV{"REQUEST_METHOD"} = 'GET';
my $p;
ok(
$p = Lemonldap::NG::Portal::Simple->new(
{
globalStorage => 'Apache::Session::File',
domain => 'example.com',
authentication => 'Apache',
userDB => 'Null',
passwordDB => 'Null',
registerDB => 'Null',
}
)
);
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl Lemonldap-NG-Portal-AuthSsl.t'
#########################
# change 'tests => 1' to 'tests => last_test_to_print';
use Test::More tests => 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.
$ENV{"REQUEST_METHOD"} = 'GET';
my $p;
ok(
$p = Lemonldap::NG::Portal::Simple->new(
{
globalStorage => 'Apache::Session::File',
domain => 'example.com',
authentication => 'SSL',
userDB => 'Null',
passwordDB => 'Null',
registerDB => 'Null',
}
)
);
use Test::More tests => 1;
use_ok('Lemonldap::NG::Portal::AuthFacebook');
use Test::More tests => 1;
use_ok('Lemonldap::NG::Portal::AuthGoogle');
use Test::More tests => 1;
SKIP: {
eval { require Net::OpenID::Consumer; };
skip "Net::OpenID::Consumer is not installed, so "
. "Lemonldap::NG::Portal::AuthOpenID will not be useable", 1
if ($@);
use_ok('Lemonldap::NG::Portal::AuthOpenID');
}
package My::Portal;
use Test::More tests => 14;
use strict;
our @ISA = qw(Lemonldap::NG::Portal::IssuerDBOpenID
Lemonldap::NG::Portal::OpenID::SREG Lemonldap::NG::Portal::Simple);
sub lmLog {
my ( $self, $msg, $level ) = splice @_;
#print STDERR "[$level] $msg\n";
}
our $param = { confirm => 0 };
sub param {
my ( $self, $key ) = splice @_;
return $param->{$key};
}
sub info { }
sub _sub { }
sub updatePersistentSession { }
$ENV{HTTP_ACCEPT_LANGUAGE} = 'en';
SKIP: {
eval { require Net::OpenID::Server; };
skip(
"Net::OpenID::Consumer is not installed, so "
. "Lemonldap::NG::Portal::AuthOpenID will not be useable",
14
) if ($@);
use_ok('Lemonldap::NG::Portal::OpenID::Server');
use_ok('Lemonldap::NG::Portal::IssuerDBOpenID');
use_ok('Lemonldap::NG::Portal::OpenID::SREG');
my $p = bless {
sessionInfo => {
uid => 'test',
mail => 'x.x.org'
},
whatToTrace => 'uid',
},
__PACKAGE__;
my ( $r, $h );
( $r, $h ) = $p->sregHook( '', '', 0, 0, {} );
ok( $r == 0, 'SREG: Call sregHook with untrusted request' );
$param->{confirm} = -1;
ok(
!$p->sregHook( '', '', 1, 1, {} ),
'SREG: call sregHook with confirm => -1'
);
$param->{confirm} = 1;
ok(
$p->sregHook( '', '', 1, 1, {} ),
'SREG: call sregHook without arguments'
);
( $r, $h ) =
$p->sregHook( '', '', 1, 1,
{ required => 'fullname,email', optional => 'nickname' },
);
ok( $r == 0, 'SREG: 0 returned unless required attributes are configured' );
$p->{openIdSreg_fullname} = '$uid';
$p->{openIdSreg_email} = '$mail';
$p->{openIdSreg_nickname} = '$uid';
( $r, $h ) =
$p->sregHook( '', '', 1, 1,
{ required => 'fullname,email', optional => 'nickname' },
);
ok( $r == 1, 'SREG: 1 returned if required attributes are configured' );
ok( ref($h), 'SREG: Parameters returned as hashref' );
ok( ( $h->{email} eq 'x.x.org' and $h->{fullname} eq 'test' ),
'SREG: required attributes returned' );
ok( !defined( $h->{nickname} ), 'SREG: optional parameter not returned' );
$param->{sreg_nickname} = 0;
( $r, $h ) =
$p->sregHook( '', '', 1, 1,
{ required => 'fullname,email', optional => 'nickname' },
);
ok( !defined( $h->{nickname} ),
'SREG: optional unwanted parameter not returned' );
$param->{sreg_nickname} = 'OK';
( $r, $h ) =
$p->sregHook( '', '', 1, 1,
{ required => 'fullname,email', optional => 'nickname' },
);
ok( defined( $h->{nickname} ), 'SREG: optional wanted parameter returned' );
$param->{confirm} = 0;
( $r, $h ) =
$p->sregHook( '', '', 1, 1,
{ required => 'fullname,email', optional => 'nickname' },
);
ok( ( $r == 0 and ref($h) ),
'SREG: 0 returned for unconfirmed parameters' );
}
use Test::More tests => 1;
use_ok('Lemonldap::NG::Portal::UserDBFacebook');
use Test::More tests => 1;
use_ok('Lemonldap::NG::Portal::UserDBGoogle');
use Test::More tests => 2;
SKIP: {
eval { require Net::OpenID::Consumer; };
skip "Net::OpenID::Consumer is not installed, so "
. "Lemonldap::NG::Portal::AuthOpenID will not be useable", 2
if ($@);
use_ok('Lemonldap::NG::Portal::OpenID::SREG');
use_ok('Lemonldap::NG::Portal::UserDBOpenID');
}
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl Lemonldap-NG-Portal-AuthSsl.t'
#########################
# change 'tests => 1' to 'tests => last_test_to_print';
use Test::More tests => 4;
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.
# Fake ENV
$ENV{"REQUEST_METHOD"} = 'GET';
$ENV{"TEST_STRING"} = 'OK';
$ENV{"REMOTE_ADDR"} = '127.0.0.1';
my $p;
ok(
$p = Lemonldap::NG::Portal::Simple->new(
{
globalStorage => 'Apache::Session::File',
domain => 'example.com',
authentication => 'Null',
userDB => 'Null',
passwordDB => 'Null',
registerDB => 'Null',
exportedVars => { uid => "TEST_STRING", },
}
)
);
ok( $p->setSessionInfo() == PE_OK, 'Run setSessionInfo' );
ok( $p->{sessionInfo}->{"uid"} eq "OK", 'Read info in session' );
use Test::More tests => 1;
SKIP: {
eval "use Lasso;";
skip "Lasso is not installed, can't test SAML features", 1 if ($@);
use_ok('Lemonldap::NG::Portal::IssuerDBSAML');
}
# Unit tests for common SAML functions
use Test::More tests => 4;
# Test Lasso presence and load _SAML module
SKIP: {
eval "use Lasso;";
skip "Lasso is not installed, can't test SAML features", 4 if ($@);