Prepare tests for SAML (#595)

environments/ppa-mbqj77/deployments/1
Xavier Guimard 9 years ago
parent eb127484d8
commit ea1b78b1e7
  1. 17
      lemonldap-ng-portal/t/01-AuthDemo.t
  2. 24
      lemonldap-ng-portal/t/02-Password-Demo.t
  3. 22
      lemonldap-ng-portal/t/03-XSS-protection.t
  4. 35
      lemonldap-ng-portal/t/04-Notification-File.t
  5. 44
      lemonldap-ng-portal/t/20-Auth-and-password-DBI.t
  6. 31
      lemonldap-ng-portal/t/21-Auth-and-password-LDAP.t
  7. 31
      lemonldap-ng-portal/t/22-Auth-and-password-AD.t
  8. 16
      lemonldap-ng-portal/t/23-AuthNull.t
  9. 16
      lemonldap-ng-portal/t/24-AuthApache.t
  10. 22
      lemonldap-ng-portal/t/25-AuthSlave.t
  11. 39
      lemonldap-ng-portal/t/26-AuthRemote.t
  12. 20
      lemonldap-ng-portal/t/27-AuthProxy.t
  13. 52
      lemonldap-ng-portal/t/28-AuthChoice.t
  14. 18
      lemonldap-ng-portal/t/29-AuthSSL.t
  15. 30
      lemonldap-ng-portal/t/40-Notifications-DBI.t
  16. 27
      lemonldap-ng-portal/t/50-IssuerGet.t
  17. 12
      lemonldap-ng-portal/t/90-translations.t
  18. 115
      lemonldap-ng-portal/t/test-lib.pm

@ -6,18 +6,19 @@ require 't/test-lib.pm';
my $res;
init( { logLevel => 'error', useSafeJail => 1 } );
my $client = LLNG::Manager::Test->new(
{ ini => { logLevel => 'error', useSafeJail => 1 } } );
# Test normal first access
# ------------------------
ok( $res = &client->_get('/'), 'Unauth JSON request' );
ok( $res = $client->_get('/'), 'Unauth JSON request' );
ok( $res->[0] == 401, 'Response is 401' ) or explain( $res, 401 );
count(2);
# Test "first access" with good url
ok(
$res =
&client->_get( '/', query => 'url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw==' ),
$client->_get( '/', query => 'url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw==' ),
'Unauth ajax request with good url'
);
ok( $res->[0] == 401, 'Response is 401' ) or explain( $res, 401 );
@ -26,7 +27,7 @@ count(2);
# Try yo authenticate
# -------------------
ok(
$res = &client->_post(
$res = $client->_post(
'/',
IO::String->new('user=dwho&password=dwho'),
length => 23
@ -34,7 +35,7 @@ ok(
'Auth query'
);
ok( $res->[0] == 200, 'Response is 200' ) or explain( $res->[0], 200 );
my $cookies = getCookies($res);
my $cookies = $client->getCookies($res);
my $id;
ok( $id = $cookies->{lemonldap}, 'Get cookie' )
or explain( $res, 'Set-Cookie: something' );
@ -43,7 +44,7 @@ count(3);
# Try to get a redirection for an auth user with a valid url
# ----------------------------------------------------------
ok(
$res = &client->_get(
$res = $client->_get(
'/',
query => 'url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw==',
cookie => "lemonldap=$id",
@ -66,7 +67,7 @@ count(4);
# in manager)
# -------------------------------------------------------------------------
ok(
$res = &client->_get(
$res = $client->_get(
'/',
query => 'url=aHR0cHM6Ly90LmV4YW1wbGUuY29tLw==',
cookie => "lemonldap=$id",
@ -83,7 +84,7 @@ ok( $hdrs{'Content-Type'} eq 'text/html', 'Reponse is HTML' )
count(4);
# Test logout
logout($id);
$client->logout($id);
#print STDERR Dumper($res);

@ -9,18 +9,20 @@ require 't/test-lib.pm';
my $res;
init(
my $client = LLNG::Manager::Test->new(
{
logLevel => 'error',
passwordDB => 'Demo',
portalRequireOldPassword => 1,
ini => {
logLevel => 'error',
passwordDB => 'Demo',
portalRequireOldPassword => 1,
}
}
);
# Try yo authenticate
# -------------------
ok(
$res = &client->_post(
$res = $client->_post(
'/',
IO::String->new('user=dwho&password=dwho'),
length => 23
@ -28,7 +30,7 @@ ok(
'Auth query'
);
ok( $res->[0] == 200, 'Response is 200' ) or explain( $res->[0], 200 );
my $cookies = getCookies($res);
my $cookies = $client->getCookies($res);
my $id;
ok( $id = $cookies->{lemonldap}, 'Get cookie' )
or explain( $res, 'Set-Cookie: something' );
@ -36,7 +38,7 @@ count(3);
# Test mismatch pwd
ok(
$res = &client->_post(
$res = $client->_post(
'/',
IO::String->new('oldpassword=dwho&newpassword=test&confirmpassword=t'),
cookie => "lemonldap=$id",
@ -55,7 +57,7 @@ count(4);
# Test missing old pwd
ok(
$res = &client->_post(
$res = $client->_post(
'/',
IO::String->new('newpassword=test&confirmpassword=test'),
cookie => "lemonldap=$id",
@ -75,7 +77,7 @@ count(4);
# Test bad old pwd
ok(
$res = &client->_post(
$res = $client->_post(
'/',
IO::String->new('oldpassword=dd&newpassword=test&confirmpassword=test'),
cookie => "lemonldap=$id",
@ -91,8 +93,8 @@ ok( $json->{error} == PE_BADOLDPASSWORD, 'Response is PE_BADOLDPASSWORD' )
or explain( $json, "error => 27" );
count(4);
# Test logout
logout($id);
# Test $client->logout
$client->logout($id);
#print STDERR Dumper($res);

@ -4,11 +4,13 @@ use IO::String;
require 't/test-lib.pm';
init(
my $client = LLNG::Manager::Test->new(
{
logLevel => 'error',
useSafeJail => 1,
trustedDomains => 'example3.com *.example2.com'
ini => {
logLevel => 'error',
useSafeJail => 1,
trustedDomains => 'example3.com *.example2.com'
}
}
);
@ -100,7 +102,7 @@ my @tests = (
my $res;
ok(
$res = &client->_post(
$res = $client->_post(
'/',
IO::String->new('user=dwho&password=dwho'),
length => 23
@ -109,7 +111,7 @@ ok(
);
ok( $res->[0] == 200, 'Response is 200' ) or explain( $res->[0], 200 );
my $id;
ok( $id = getCookies($res)->{lemonldap}, 'Get LLNG cookie' )
ok( $id = $client->getCookies($res)->{lemonldap}, 'Get LLNG cookie' )
or explain( $res, 'Set-Cookie: something' );
count(3);
@ -119,7 +121,7 @@ while ( defined( my $url = shift(@tests) ) ) {
my $redir = shift @tests;
my $detail = shift @tests;
ok(
$res = &client->_get(
$res = $client->_get(
'/',
query => "url=$url",
cookie => "lemonldap=$id",
@ -139,7 +141,7 @@ while ( defined( my $url = shift(@tests) ) ) {
my $redir = shift @tests;
my $detail = shift @tests;
ok(
$res = &client->_get(
$res = $client->_get(
'/',
query => "url=$url&logout=1",
cookie => "lemonldap=$id",
@ -153,7 +155,7 @@ while ( defined( my $url = shift(@tests) ) ) {
( $redir ? 'Get redirection' : 'Redirection dropped' ) )
or explain( $res->[0], ( $redir ? 302 : 200 ) );
ok(
$res = &client->_post(
$res = $client->_post(
'/',
IO::String->new('user=dwho&password=dwho'),
length => 23
@ -161,7 +163,7 @@ while ( defined( my $url = shift(@tests) ) ) {
'Auth query'
);
ok( $res->[0] == 200, 'Response is 200' ) or explain( $res->[0], 200 );
ok( $id = getCookies($res)->{lemonldap}, 'Get LLNG cookie' )
ok( $id = $client->getCookies($res)->{lemonldap}, 'Get LLNG cookie' )
or explain( $res, 'Set-Cookie: something' );
count(5);
}

@ -17,23 +17,25 @@ print F '<?xml version="1.0" encoding="UTF-8"?>
</notification></root>';
close F;
init(
my $client = LLNG::Manager::Test->new(
{
logLevel => 'error',
useSafeJail => 1,
notifications => 1,
templatesDir => 'site/templates/',
notificationStorage => 'File',
notificationStorageOptions => {
dirName => 't'
},
ini => {
logLevel => 'error',
useSafeJail => 1,
notifications => 1,
templatesDir => 'site/templates/',
notificationStorage => 'File',
notificationStorageOptions => {
dirName => 't'
},
}
}
);
# Try yo authenticate
# -------------------
ok(
$res = &client->_post(
$res = $client->_post(
'/',
IO::String->new(
'user=dwho&password=dwho&url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw=='),
@ -43,7 +45,7 @@ ok(
'Auth query'
);
ok( $res->[0] == 200, 'Response is 200' ) or explain( $res->[0], 200 );
my $cookies = getCookies($res);
my $cookies = $client->getCookies($res);
my $id;
ok( $id = $cookies->{lemonldap}, 'Get cookie' )
or explain( $res, 'Set-Cookie: something' );
@ -51,7 +53,7 @@ count(3);
# Verify that cookie is ciphered (session unvalid)
ok(
$res = &client->_get(
$res = $client->_get(
'/',
query => 'url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw==',
cookie => "lemonldap=$id",
@ -65,7 +67,7 @@ count(2);
# Try to validate notification without accepting it
my $str = 'reference1x1=testref&url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw==';
ok(
$res = &client->_post(
$res = $client->_post(
'/notifback',
IO::String->new($str),
cookie => "lemonldap=$id",
@ -79,9 +81,10 @@ ok( $res->[0] == 200, "Don't receive redirection" )
count(2);
# Try to validate notification
my $str = 'reference1x1=testref&check1x1x1=accepted&url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw==';
my $str =
'reference1x1=testref&check1x1x1=accepted&url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw==';
ok(
$res = &client->_post(
$res = $client->_post(
'/notifback',
IO::String->new($str),
cookie => "lemonldap=$id",
@ -93,7 +96,7 @@ ok(
ok( $res->[0] == 302, "Get redirection" )
or explain( [ $res->[0], $res->[1] ], 302 );
$file =~ s/xml$/done/;
ok(-e $file,'Notification was deleted');
ok( -e $file, 'Notification was deleted' );
count(3);
#print STDERR Dumper($res);

@ -16,28 +16,30 @@ SKIP: {
my $dbh = DBI->connect("dbi:SQLite:dbname=t/userdb.db");
$dbh->do('CREATE TABLE users (user text,password text,name text)');
$dbh->do("INSERT INTO users VALUES ('dwho','dwho','Doctor who')");
init(
my $client = LLNG::Manager::Test->new(
{
logLevel => 'error',
useSafeJail => 1,
authentication => 'DBI',
userDB => 'DBI',
dbiAuthChain => 'dbi:SQLite:dbname=t/userdb.db',
dbiAuthUser => '',
dbiAuthPassword => '',
dbiAuthTable => 'users',
dbiAuthLoginCol => 'user',
dbiAuthPasswordCol => 'password',
dbiAuthPasswordHash => '',
passwordDB => 'DBI',
portalRequireOldPassword => 1,
ini => {
logLevel => 'error',
useSafeJail => 1,
authentication => 'DBI',
userDB => 'DBI',
dbiAuthChain => 'dbi:SQLite:dbname=t/userdb.db',
dbiAuthUser => '',
dbiAuthPassword => '',
dbiAuthTable => 'users',
dbiAuthLoginCol => 'user',
dbiAuthPasswordCol => 'password',
dbiAuthPasswordHash => '',
passwordDB => 'DBI',
portalRequireOldPassword => 1,
}
}
);
# Try yo authenticate
# -------------------
ok(
$res = &client->_post(
$res = $client->_post(
'/',
IO::String->new('user=dwho&password=dwho'),
length => 23
@ -45,13 +47,13 @@ SKIP: {
'Auth query'
);
ok( $res->[0] == 200, 'Response is 200' ) or explain( $res->[0], 200 );
my $cookies = getCookies($res);
my $cookies = $client->getCookies($res);
my $id;
ok( $id = $cookies->{lemonldap}, 'Get cookie' )
or explain( $res, 'Set-Cookie: something' );
ok(
$res = &client->_post(
$res = $client->_post(
'/',
IO::String->new(
'oldpassword=dwho&newpassword=test&confirmpassword=test'),
@ -62,9 +64,9 @@ SKIP: {
'Change password'
);
ok( $res->[0] == 200, 'Response is 200' ) or explain( $res, 200 );
logout($id);
$client->logout($id);
ok(
$res = &client->_post(
$res = $client->_post(
'/',
IO::String->new('user=dwho&password=test'),
cookie => "lemonldap=$id",
@ -73,11 +75,11 @@ SKIP: {
'Auth query with new password'
);
ok( $res->[0] == 200, 'Response is 200' ) or explain( $res->[0], 200 );
$cookies = getCookies($res);
$cookies = $client->getCookies($res);
ok( $id = $cookies->{lemonldap}, 'Get cookie' )
or explain( $res, 'Set-Cookie: something' );
logout($id);
$client->logout($id);
clean_sessions();
}
eval { unlink 't/userdb.db' };

@ -9,17 +9,19 @@ my $res;
SKIP: {
skip 'No LDAP server given', 3 unless ( $ENV{LDAPSERVER} );
init(
my $client = LLNG::Manager::Test->new(
{
logLevel => 'error',
useSafeJail => 1,
authentication => 'LDAP',
userDB => 'LDAP',
LDAPFilter => $ENV{LDAPFILTER} || '(cn=$user)',
ldapServer => $ENV{LDAPSERVER},
ldapBase => $ENV{LDAPBASE},
managerDn => $ENV{MANAGERDN} || '',
managerPassword => $ENV{MANAGERPASSWORD} || '',
ini => {
logLevel => 'error',
useSafeJail => 1,
authentication => 'LDAP',
userDB => 'LDAP',
LDAPFilter => $ENV{LDAPFILTER} || '(cn=$user)',
ldapServer => $ENV{LDAPSERVER},
ldapBase => $ENV{LDAPBASE},
managerDn => $ENV{MANAGERDN} || '',
managerPassword => $ENV{MANAGERPASSWORD} || '',
}
}
);
my $postString = 'user='
@ -30,19 +32,18 @@ SKIP: {
# Try yo authenticate
# -------------------
ok(
$res = &client->_post(
'/',
IO::String->new($postString),
$res = $client->_post(
'/', IO::String->new($postString),
length => length($postString)
),
'Auth query'
);
ok( $res->[0] == 200, 'Response is 200' ) or explain( $res->[0], 200 );
my $cookies = getCookies($res);
my $cookies = $client->getCookies($res);
my $id;
ok( $id = $cookies->{lemonldap}, 'Get cookie' )
or explain( $res, 'Set-Cookie: something' );
logout($id);
$client->logout($id);
clean_sessions();
}

@ -9,17 +9,19 @@ my $res;
SKIP: {
skip 'No AD server given', 3 unless ( $ENV{ADSERVER} );
init(
my $client = LLNG::Manager::Test->new(
{
logLevel => 'error',
useSafeJail => 1,
authentication => 'AD',
userDB => 'AD',
LDAPFilter => $ENV{ADFILTER} || '(cn=$user)',
ldapServer => $ENV{ADSERVER},
ldapBase => $ENV{ADBASE},
managerDn => $ENV{MANAGERDN} || '',
managerPassword => $ENV{MANAGERPASSWORD} || '',
ini => {
logLevel => 'error',
useSafeJail => 1,
authentication => 'AD',
userDB => 'AD',
LDAPFilter => $ENV{ADFILTER} || '(cn=$user)',
ldapServer => $ENV{ADSERVER},
ldapBase => $ENV{ADBASE},
managerDn => $ENV{MANAGERDN} || '',
managerPassword => $ENV{MANAGERPASSWORD} || '',
}
}
);
my $postString = 'user='
@ -30,19 +32,18 @@ SKIP: {
# Try yo authenticate
# -------------------
ok(
$res = &client->_post(
'/',
IO::String->new($postString),
$res = $client->_post(
'/', IO::String->new($postString),
length => length($postString)
),
'Auth query'
);
ok( $res->[0] == 200, 'Response is 200' ) or explain( $res->[0], 200 );
my $cookies = getCookies($res);
my $cookies = $client->getCookies($res);
my $id;
ok( $id = $cookies->{lemonldap}, 'Get cookie' )
or explain( $res, 'Set-Cookie: something' );
logout($id);
$client->logout($id);
clean_sessions();
}

@ -5,18 +5,20 @@ require 't/test-lib.pm';
my $res;
init(
my $client = LLNG::Manager::Test->new(
{
logLevel => 'error',
useSafeJail => 1,
authentication => 'Null',
userDB => 'Null',
ini => {
logLevel => 'error',
useSafeJail => 1,
authentication => 'Null',
userDB => 'Null',
}
}
);
ok( $res = &client->_get('/'), 'Auth query' );
ok( $res = $client->_get('/'), 'Auth query' );
ok( $res->[0] == 200, 'Response is 200' ) or explain( $res->[0], 200 );
my $cookies = getCookies($res);
my $cookies = $client->getCookies($res);
my $id;
ok( $id = $cookies->{lemonldap}, 'Get cookie' )
or explain( $res, 'Set-Cookie: something' );

@ -5,18 +5,20 @@ require 't/test-lib.pm';
my $res;
init(
my $client = LLNG::Manager::Test->new(
{
logLevel => 'error',
useSafeJail => 1,
authentication => 'Apache',
userDB => 'Null',
ini => {
logLevel => 'error',
useSafeJail => 1,
authentication => 'Apache',
userDB => 'Null',
}
}
);
ok( $res = &client->_get( '/', remote_user => 'dwho' ), 'Auth query' );
ok( $res = $client->_get( '/', remote_user => 'dwho' ), 'Auth query' );
ok( $res->[0] == 200, 'Response is 200' ) or explain( $res->[0], 200 );
my $cookies = getCookies($res);
my $cookies = $client->getCookies($res);
my $id;
ok( $id = $cookies->{lemonldap}, 'Get cookie' )
or explain( $res, 'Set-Cookie: something' );

@ -5,27 +5,29 @@ require 't/test-lib.pm';
my $res;
init(
my $client = LLNG::Manager::Test->new(
{
logLevel => 'error',
useSafeJail => 1,
authentication => 'Slave',
userDB => 'Slave',
slaveUserHeader => 'My-Test',
slaveExportedVars => {
name => 'Name',
ini => {
logLevel => 'error',
useSafeJail => 1,
authentication => 'Slave',
userDB => 'Slave',
slaveUserHeader => 'My-Test',
slaveExportedVars => {
name => 'Name',
}
}
}
);
ok(
$res = &client->_get(
$res = $client->_get(
'/', custom => { HTTP_MY_TEST => 'dwho', HTTP_NAME => 'Dr Who' }
),
'Auth query'
);
ok( $res->[0] == 200, 'Response is 200' ) or explain( $res->[0], 200 );
my $cookies = getCookies($res);
my $cookies = $client->getCookies($res);
my $id;
ok( $id = $cookies->{lemonldap}, 'Get cookie' )
or explain( $res, 'Set-Cookie: something' );

@ -5,24 +5,26 @@ require 't/test-lib.pm';
my $res;
init(
my $client = LLNG::Manager::Test->new(
{
logLevel => 'error',
useSafeJail => 1,
authentication => 'Remote',
userDB => 'Remote',
remoteUserField => 'uid',
remoteGlobalStorage => 'Apache::Session::File',
remoteGlobalStorageOptions => {
Directory => 't/sessions2',
LockDirectory => 't/sessions2/lock',
},
remotePortal => 'http://auth2.example.com',
ini => {
logLevel => 'error',
useSafeJail => 1,
authentication => 'Remote',
userDB => 'Remote',
remoteUserField => 'uid',
remoteGlobalStorage => 'Apache::Session::File',
remoteGlobalStorageOptions => {
Directory => 't/sessions2',
LockDirectory => 't/sessions2/lock',
},
remotePortal => 'http://auth2.example.com',
}
}
);
# Test redirection to remote portal
ok( $res = &client->_get( '/', accept => 'text/html' ), 'First request' );
ok( $res = $client->_get( '/', accept => 'text/html' ), 'First request' );
ok( $res->[0] == 302, 'Response is 302' ) or explain( $res->[0], 302 );
my @tmp = @{ $res->[1] };
while ( @tmp and $tmp[0] ne 'Location' ) {
@ -42,9 +44,16 @@ ok(
);
count(3);
ok( $res = &client->_get( '/',query=>'lemonldap=6e30af4ffa5689b3e49a104d1b160d316db2b2161a0f45776994eed19dbdc101'), 'Auth query');
ok(
$res = $client->_get(
'/',
query =>
'lemonldap=6e30af4ffa5689b3e49a104d1b160d316db2b2161a0f45776994eed19dbdc101'
),
'Auth query'
);
ok( $res->[0] == 200, 'Response is 200' ) or explain( $res->[0], 200 );
my $cookies = getCookies($res);
my $cookies = $client->getCookies($res);
my $id;
ok( $id = $cookies->{lemonldap}, 'Get cookie' )
or explain( $res, 'Set-Cookie: something' );

@ -7,17 +7,19 @@ my $res;
SKIP: {
skip 'REMOTELLNG is not set', 10 unless ( $ENV{REMOTELLNG} );
require 't/test-lib.pm';
init(
my $client = LLNG::Manager::Test->new(
{
logLevel => 'error',
useSafeJail => 1,
authentication => 'Proxy',
userDB => 'Proxy',
soapAuthService => $ENV{REMOTELLNG},
ini => {
logLevel => 'error',
useSafeJail => 1,
authentication => 'Proxy',
userDB => 'Proxy',
soapAuthService => $ENV{REMOTELLNG},
}
}
);
ok(
$res = &client->_post(
$res = $client->_post(
'/',
IO::String->new('user=dwho&password=dwho'),
length => 23
@ -25,12 +27,12 @@ SKIP: {
'Auth query'
);
ok( $res->[0] == 200, 'Response is 200' ) or explain( $res->[0], 200 );
my $cookies = getCookies($res);
my $cookies = $client->getCookies($res);
my $id;
ok( $id = $cookies->{lemonldap}, 'Get cookie' )
or explain( $res, 'Set-Cookie: something' );
logout($id);
$client->logout($id);
clean_sessions();
}
done_testing(10);

@ -20,32 +20,34 @@ SKIP: {
$dbh->do('CREATE TABLE users (user text,password text,name text)');
$dbh->do("INSERT INTO users VALUES ('dwho','dwho','Doctor who')");
init(
my $client = LLNG::Manager::Test->new(
{
logLevel => 'error',
useSafeJail => 1,
authentication => 'Choice',
userDB => 'Choice',
ini => {
logLevel => 'error',
useSafeJail => 1,
authentication => 'Choice',
userDB => 'Choice',
authChoiceParam => 'test',
authChoiceModules => {
ldap => 'LDAP;LDAP;LDAP',
sql => 'DBI;DBI;DBI',
},
authChoiceParam => 'test',
authChoiceModules => {
ldap => 'LDAP;LDAP;LDAP',
sql => 'DBI;DBI;DBI',
},
dbiAuthChain => 'dbi:SQLite:dbname=t/userdb.db',
dbiAuthUser => '',
dbiAuthPassword => '',
dbiAuthTable => 'users',
dbiAuthLoginCol => 'user',
dbiAuthPasswordCol => 'password',
dbiAuthPasswordHash => '',
dbiAuthChain => 'dbi:SQLite:dbname=t/userdb.db',
dbiAuthUser => '',
dbiAuthPassword => '',
dbiAuthTable => 'users',
dbiAuthLoginCol => 'user',
dbiAuthPasswordCol => 'password',
dbiAuthPasswordHash => '',
LDAPFilter => $ENV{LDAPFILTER} || '(cn=$user)',
ldapServer => $ENV{LDAPSERVER},
ldapBase => $ENV{LDAPBASE},
managerDn => $ENV{MANAGERDN} || '',
managerPassword => $ENV{MANAGERPASSWORD} || '',
LDAPFilter => $ENV{LDAPFILTER} || '(cn=$user)',
ldapServer => $ENV{LDAPSERVER},
ldapBase => $ENV{LDAPBASE},
managerDn => $ENV{MANAGERDN} || '',
managerPassword => $ENV{MANAGERPASSWORD} || '',
}
}
);
foreach my $postString (
@ -61,18 +63,18 @@ SKIP: {
# Try yo authenticate
# -------------------
ok(
$res = &client->_post(
$res = $client->_post(
'/', IO::String->new($postString),
length => length($postString)
),
'Auth query'
);
ok( $res->[0] == 200, 'Response is 200' ) or explain( $res->[0], 200 );
my $cookies = getCookies($res);
my $cookies = $client->getCookies($res);
my $id;
ok( $id = $cookies->{lemonldap}, 'Get cookie' )
or explain( $res, 'Set-Cookie: something' );
logout($id);
$client->logout($id);
}
clean_sessions();

@ -5,24 +5,26 @@ require 't/test-lib.pm';
my $res;
init(
my $client = LLNG::Manager::Test->new(
{
logLevel => 'error',
useSafeJail => 1,
authentication => 'SSL',
userDB => 'Null',
SSLVar => 'SSL_CLIENT_S_DN_Custom',
ini => {
logLevel => 'error',
useSafeJail => 1,
authentication => 'SSL',
userDB => 'Null',
SSLVar => 'SSL_CLIENT_S_DN_Custom',
}
}
);
ok(
$res = &client->_get(
$res = $client->_get(
'/', custom => { SSL_CLIENT_S_DN_Custom => 'dwho' }
),
'Auth query'
);
ok( $res->[0] == 200, 'Response is 200' ) or explain( $res->[0], 200 );
my $cookies = getCookies($res);
my $cookies = $client->getCookies($res);
my $id;
ok( $id = $cookies->{lemonldap}, 'Get cookie' )
or explain( $res, 'Set-Cookie: something' );

@ -27,23 +27,25 @@ qq{INSERT INTO notifications VALUES ('dwho','testref','2016-05-30 00:00:00','<?x
</notification></root>',null,null)}
);
init(
my $client = LLNG::Manager::Test->new(
{
logLevel => 'error',
useSafeJail => 1,
notifications => 1,
templatesDir => 'site/templates/',
notificationStorage => 'DBI',
notificationStorageOptions => {
dbiChain => "dbi:SQLite:dbname=$file",
},
ini => {
logLevel => 'error',
useSafeJail => 1,
notifications => 1,
templatesDir => 'site/templates/',
notificationStorage => 'DBI',
notificationStorageOptions => {
dbiChain => "dbi:SQLite:dbname=$file",
},
}
}
);
# Try yo authenticate
# -------------------
ok(
$res = &client->_post(
$res = $client->_post(
'/',
IO::String->new(
'user=dwho&password=dwho&url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw=='
@ -54,14 +56,14 @@ qq{INSERT INTO notifications VALUES ('dwho','testref','2016-05-30 00:00:00','<?x
'Auth query'
);
ok( $res->[0] == 200, 'Response is 200' ) or explain( $res->[0], 200 );
my $cookies = getCookies($res);
my $cookies = $client->getCookies($res);
my $id;
ok( $id = $cookies->{lemonldap}, 'Get cookie' )
or explain( $res, 'Set-Cookie: something' );
# Verify that cookie is ciphered (session unvalid)
ok(
$res = &client->_get(
$res = $client->_get(
'/',
query => 'url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw==',
cookie => "lemonldap=$id",
@ -74,7 +76,7 @@ qq{INSERT INTO notifications VALUES ('dwho','testref','2016-05-30 00:00:00','<?x
# Try to validate notification without accepting it
my $str = 'reference1x1=testref&url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw==';
ok(
$res = &client->_post(
$res = $client->_post(
'/notifback',
IO::String->new($str),
cookie => "lemonldap=$id",
@ -90,7 +92,7 @@ qq{INSERT INTO notifications VALUES ('dwho','testref','2016-05-30 00:00:00','<?x
$str =
'reference1x1=testref&check1x1x1=accepted&url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw==';
ok(
$res = &client->_post(
$res = $client->_post(
'/notifback',
IO::String->new($str),
cookie => "lemonldap=$id",

@ -6,21 +6,23 @@ require 't/test-lib.pm';
my $res;
init(
my $client = LLNG::Manager::Test->new(
{
logLevel => 'error',
useSafeJail => 1,
issuerDBGetActivation => 1,
issuerDBGetPath => '^/test/',
issuerDBGetParameters =>
{ 'test1.example.com' => { ID => '_session_id' } }
ini => {
logLevel => 'error',
useSafeJail => 1,
issuerDBGetActivation => 1,
issuerDBGetPath => '^/test/',
issuerDBGetParameters =>
{ 'test1.example.com' => { ID => '_session_id' } }
}
}
);
# Try yo authenticate
# -------------------
ok(
$res = &client->_post(
$res = $client->_post(
'/',
IO::String->new('user=dwho&password=dwho'),
length => 23
@ -28,7 +30,7 @@ ok(
'Auth query'
);
ok( $res->[0] == 200, 'Response is 200' ) or explain( $res->[0], 200 );
my $cookies = getCookies($res);
my $cookies = $client->getCookies($res);
my $id;
ok( $id = $cookies->{lemonldap}, 'Get cookie' )
or explain( $res, 'Set-Cookie: something' );
@ -36,7 +38,7 @@ count(3);
# Test GET login
ok(
$res = &client->_get(
$res = $client->_get(
'/test',
query => 'url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw==',
cookie => "lemonldap=$id",
@ -55,9 +57,8 @@ count(3);
# Test not logged access
ok(
$res = &client->_get(
'/test',
query => 'url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw==',
$res = $client->_get(
'/test', query => 'url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw==',
),
'Not logged access'
);

@ -62,14 +62,14 @@ foreach my $lang (@langs) {
use File::Find;
my @trspan = ();
my @unTr = ();
my @unTr = ();
find(
sub {
my $f = $File::Find::name;
return unless ( $_ =~ /tpl$/ and -f $_);
return unless ( $_ =~ /tpl$/ and -f $_ );
open F, $_;
while(my $l = <F>) {
push @trspan, ($l =~ /trspan="(\w+)"/g);
while ( my $l = <F> ) {
push @trspan, ( $l =~ /trspan="(\w+)"/g );
}
close F;
},
@ -78,8 +78,8 @@ find(
ok( @trspan > 1, 'Found "trspan" attributes' );
@unTr = ();
my $last='';
foreach (grep {$last ne $_ ? $last = $_ : undef} sort @trspan) {
my $last = '';
foreach ( grep { $last ne $_ ? $last = $_ : undef } sort @trspan ) {
push @unTr, $_ unless ( $keys->{$_} );
}
ok( @unTr == 0,

@ -1,4 +1,5 @@
# Base library for portal tests
package main;
use strict;
use Data::Dumper;
@ -6,31 +7,10 @@ use 5.10.0;
use_ok('Lemonldap::NG::Portal::Main');
our $client;
our $count = 1;
$Data::Dumper::Deparse = 1;
my $ini;
sub init {
$ini = shift;
$ini ||= {};
$ini->{configStorage} ||= { type => 'File', dirName => 't' };
$ini->{localSessionStorage} ||= '';
$ini->{logLevel} ||= 'error';
$ini->{cookieName} ||= 'lemonldap';
$ini->{domain} ||= 'example.com';
$ini->{templateDir} ||= 'site/templates';
$ini->{staticPrefix} ||= '/index.fcgi';
$ini->{securedCookie} //= 0;
$ini->{https} //= 0;
ok( $client = My::Cli->new(), 'Portal app' );
count(1);
}
sub client {
return $client;
}
sub count {
my $c = shift;
$count += $c if ($c);
@ -43,11 +23,60 @@ sub explain {
print STDERR "Expect $ref, get $get\n";
}
sub clean_sessions {
opendir D, 't/sessions' or die $!;
foreach ( grep { /^[^\.]/ } readdir(D) ) {
unlink "t/sessions/$_", "t/sessions/lock/Apache-Session-$_.lock";
}
opendir D, 't/sessions/lock' or die $!;
foreach ( grep { /^[^\.]/ } readdir(D) ) {
unlink "t/sessions/lock/$_";
}
}
package LLNG::Manager::Test;
use strict;
use Mouse;
extends 'Lemonldap::NG::Common::PSGI::Cli::Lib';
our $defaultIni = {
configStorage => { type => 'File', dirName => 't' },
localSessionStorage => '',
logLevel => 'error',
cookieName => 'lemonldap',
domain => 'example.com',
templateDir => 'site/templates',
staticPrefix => '/index.fcgi',
securedCookie => 0,
https => 0,
};
has app => (
is => 'rw',
isa => 'CodeRef',
);
has ini => ( is => 'rw',
default => sub { $defaultIni; },
trigger => sub {
my($self,$ini) = @_;
foreach my $k (keys %$defaultIni) {
$ini->{$k} //= $defaultIni->{$k};
}
$self->{ini} = $ini;
main::ok($self->{app} = Lemonldap::NG::Portal::Main->run($ini),'Portal app');
main::count(1);
$self;
}
);
sub logout {
my ($id) = @_;
my ($self,$id) = @_;
my $res;
ok(
$res = &client->_get(
main::ok(
$res = $self->_get(
'/',
query => 'logout',
cookie => "lemonldap=$id",
@ -55,32 +84,21 @@ sub logout {
),
'Logout'
);
ok( $res->[0] == 200, 'Response is 200' ) or explain( $res->[0], 200 );
main::ok( $res->[0] == 200, 'Response is 200' ) or explain( $res->[0], 200 );
my $c;
ok( ( defined( $c = getCookies($res)->{lemonldap} ) and not $c ),
main::ok( ( defined( $c = $self->getCookies($res)->{lemonldap} ) and not $c ),
'Cookie is deleted' )
or explain( $res->[1], "Set-Cookie => 'lemonldap='" );
ok( $res = &client->_get( '/', cookie => "lemonldap=$id" ),
main::ok( $res = $self->_get( '/', cookie => "lemonldap=$id" ),
'Disconnect request' )
or explain( $res, '[<code>,<hdrs>,<content>]' );
ok( $res->[0] == 401, 'Response is 401' ) or explain( $res, 401 );
count(5);
main::ok( $res->[0] == 401, 'Response is 401' ) or explain( $res, 401 );
main::count(5);
}
sub clean_sessions {
opendir D, 't/sessions' or die $!;
foreach ( grep { /^[^\.]/ } readdir(D) ) {
unlink "t/sessions/$_", "t/sessions/lock/Apache-Session-$_.lock";
}
opendir D, 't/sessions/lock' or die $!;
foreach ( grep { /^[^\.]/ } readdir(D) ) {
unlink "t/sessions/lock/$_";
}
}
sub getCookies {
my $resp = shift;
my ($self,$resp) = @_;
my @hdrs = @{ $resp->[1] };
my $res = {};
while ( my $name = shift @hdrs ) {
@ -94,21 +112,6 @@ sub getCookies {
return $res;
}
package My::Cli;
use strict;
use Mouse;
extends 'Lemonldap::NG::Common::PSGI::Cli::Lib';
has app => (
is => 'ro',
isa => 'CodeRef',
builder => sub {
return Lemonldap::NG::Portal::Main->run($ini);
}
);
sub _get {
my ( $self, $path, %args ) = @_;
return $self->app->(

Loading…
Cancel
Save