Commit ea1b78b1 authored by Yadd's avatar Yadd
Browse files

Prepare tests for SAML (#595)

parent eb127484
......@@ -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 => {