Skip captcha tests if missing modules (#595)
This commit is contained in:
parent
f7df1db206
commit
c52bbcb527
|
@ -1,9 +1,6 @@
|
|||
* Doc for token/captcha
|
||||
* login history
|
||||
* Create "csp" in doc
|
||||
* Test for Zero
|
||||
* updateStatus( Main, SOAP server )
|
||||
* replace SOAP calls in Handler/Lib/AuthBasic and Auth/Proxy
|
||||
* replace SOAP by REST for notification creation
|
||||
* "mail" in UserDB/*
|
||||
* checkLogins in SAML
|
||||
|
|
|
@ -7,90 +7,91 @@ BEGIN {
|
|||
require 't/test-lib.pm';
|
||||
}
|
||||
|
||||
my ( $res, $user, $pwd );
|
||||
my $mailSend = 0;
|
||||
my $maintests = 11;
|
||||
my ( $res, $user, $pwd, $host, $url, $query ) = my $mailSend = 0;
|
||||
|
||||
my $client = LLNG::Manager::Test->new(
|
||||
{
|
||||
ini => {
|
||||
logLevel => 'error',
|
||||
useSafeJail => 1,
|
||||
portalDisplayRegister => 1,
|
||||
registerDB => 'Demo',
|
||||
captcha_register_enabled => 1,
|
||||
}
|
||||
SKIP: {
|
||||
eval 'use GD::SecurityImage;use Image::Magick;';
|
||||
if ($@) {
|
||||
skip 'Lasso not found', $maintests;
|
||||
}
|
||||
);
|
||||
|
||||
# Test normal first access
|
||||
# ------------------------
|
||||
ok(
|
||||
$res = $client->_get( '/register', accept => 'text/html' ),
|
||||
'Unauth JSON request',
|
||||
);
|
||||
count(1);
|
||||
my ( $host, $url, $query ) =
|
||||
expectForm( $res, '#', undef, 'firstname', 'lastname', 'mail' );
|
||||
ok(
|
||||
$query =~
|
||||
my $client = LLNG::Manager::Test->new(
|
||||
{
|
||||
ini => {
|
||||
logLevel => 'error',
|
||||
useSafeJail => 1,
|
||||
portalDisplayRegister => 1,
|
||||
registerDB => 'Demo',
|
||||
captcha_register_enabled => 1,
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
# Test normal first access
|
||||
# ------------------------
|
||||
ok(
|
||||
$res = $client->_get( '/register', accept => 'text/html' ),
|
||||
'Unauth JSON request',
|
||||
);
|
||||
( $host, $url, $query ) =
|
||||
expectForm( $res, '#', undef, 'firstname', 'lastname', 'mail' );
|
||||
ok(
|
||||
$query =~
|
||||
s/^.*token=([^&]+).*$/token=$1&firstname=foo&lastname=bar&mail=foobar%40badwolf.org/,
|
||||
'Token found'
|
||||
);
|
||||
my $token;
|
||||
ok( $token = $1, ' Token value is defined' );
|
||||
ok( $res->[2]->[0] =~ m#<img src="data:image/png;base64#,
|
||||
' Captcha image inserted' );
|
||||
count(3);
|
||||
'Token found'
|
||||
);
|
||||
my $token;
|
||||
ok( $token = $1, ' Token value is defined' );
|
||||
ok( $res->[2]->[0] =~ m#<img src="data:image/png;base64#,
|
||||
' Captcha image inserted' );
|
||||
|
||||
# Try to get captcha value
|
||||
# Try to get captcha value
|
||||
|
||||
my ( $ts, $captcha );
|
||||
ok( $ts = $client->p->getApacheSession($token), ' Found token session' );
|
||||
ok( $captcha = $ts->data->{captcha}, ' Found captcha value' );
|
||||
count(2);
|
||||
my ( $ts, $captcha );
|
||||
ok( $ts = $client->p->getApacheSession($token), ' Found token session' );
|
||||
ok( $captcha = $ts->data->{captcha}, ' Found captcha value' );
|
||||
|
||||
$query .= "&captcha=$captcha";
|
||||
$query .= "&captcha=$captcha";
|
||||
|
||||
ok(
|
||||
$res = $client->_post(
|
||||
'/register',
|
||||
IO::String->new($query),
|
||||
length => length($query),
|
||||
accept => 'text/html'
|
||||
),
|
||||
'Ask to create account'
|
||||
);
|
||||
count(1);
|
||||
expectOK($res);
|
||||
ok(
|
||||
$res = $client->_post(
|
||||
'/register',
|
||||
IO::String->new($query),
|
||||
length => length($query),
|
||||
accept => 'text/html'
|
||||
),
|
||||
'Ask to create account'
|
||||
);
|
||||
expectOK($res);
|
||||
|
||||
# $query is set by MIME::Lite::send below
|
||||
ok( $query =~ /register_token=/, 'Found register_token' );
|
||||
count(1);
|
||||
# $query is set by MIME::Lite::send below
|
||||
ok( $query =~ /register_token=/, 'Found register_token' );
|
||||
|
||||
ok(
|
||||
$res = $client->_get( '/register', query => $query, accept => 'text/html' ),
|
||||
'Push register_token'
|
||||
);
|
||||
expectOK($res);
|
||||
count(1);
|
||||
ok(
|
||||
$res =
|
||||
$client->_get( '/register', query => $query, accept => 'text/html' ),
|
||||
'Push register_token'
|
||||
);
|
||||
expectOK($res);
|
||||
|
||||
# $user/$pwd are set by MIME::Lite::send below
|
||||
ok( $user eq 'fbar', 'Get good login' );
|
||||
count(1);
|
||||
# $user/$pwd are set by MIME::Lite::send below
|
||||
ok( $user eq 'fbar', 'Get good login' );
|
||||
|
||||
# Try to authenticate
|
||||
$query = '&user=fbar&password=fbar';
|
||||
# Try to authenticate
|
||||
$query = '&user=fbar&password=fbar';
|
||||
|
||||
ok(
|
||||
$res = $client->_post(
|
||||
'/', IO::String->new($query),
|
||||
length => length($query),
|
||||
accept => 'text/html'
|
||||
),
|
||||
'Try to authenticate'
|
||||
);
|
||||
count(1);
|
||||
expectCookie($res);
|
||||
ok(
|
||||
$res = $client->_post(
|
||||
'/', IO::String->new($query),
|
||||
length => length($query),
|
||||
accept => 'text/html'
|
||||
),
|
||||
'Try to authenticate'
|
||||
);
|
||||
expectCookie($res);
|
||||
}
|
||||
count($maintests);
|
||||
|
||||
clean_sessions();
|
||||
|
||||
|
|
|
@ -6,81 +6,89 @@ require 't/test-lib.pm';
|
|||
|
||||
my $res;
|
||||
|
||||
my $client = LLNG::Manager::Test->new(
|
||||
{
|
||||
ini => {
|
||||
logLevel => 'error',
|
||||
useSafeJail => 1,
|
||||
captcha_login_enabled => 1,
|
||||
}
|
||||
my $maintests = 13;
|
||||
SKIP: {
|
||||
eval 'use GD::SecurityImage;use Image::Magick;';
|
||||
if ($@) {
|
||||
skip 'Lasso not found', $maintests;
|
||||
}
|
||||
);
|
||||
|
||||
# Test normal first access
|
||||
# ------------------------
|
||||
ok( $res = $client->_get('/'), 'Unauth JSON request' );
|
||||
count(1);
|
||||
expectReject($res);
|
||||
my $client = LLNG::Manager::Test->new(
|
||||
{
|
||||
ini => {
|
||||
logLevel => 'error',
|
||||
useSafeJail => 1,
|
||||
captcha_login_enabled => 1,
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
ok( $res = $client->_get( '/', accept => 'text/html' ), 'Unauth request' );
|
||||
my ( $host, $url, $query ) = expectForm( $res, '#', undef, 'token' );
|
||||
$query =~ s/.*\btoken=([^&]+).*/token=$1/;
|
||||
my $token;
|
||||
ok( $token = $1, ' Token value is defined' );
|
||||
ok( $res->[2]->[0] =~ m#<img src="data:image/png;base64#,
|
||||
' Captcha image inserted' );
|
||||
count(3);
|
||||
# Test normal first access
|
||||
# ------------------------
|
||||
ok( $res = $client->_get('/'), 'Unauth JSON request' );
|
||||
expectReject($res);
|
||||
|
||||
# Try to get captcha value
|
||||
ok( $res = $client->_get( '/', accept => 'text/html' ), 'Unauth request' );
|
||||
my ( $host, $url, $query ) = expectForm( $res, '#', undef, 'token' );
|
||||
$query =~ s/.*\btoken=([^&]+).*/token=$1/;
|
||||
my $token;
|
||||
ok( $token = $1, ' Token value is defined' );
|
||||
ok( $res->[2]->[0] =~ m#<img src="data:image/png;base64#,
|
||||
' Captcha image inserted' );
|
||||
|
||||
my ( $ts, $captcha );
|
||||
ok( $ts = $client->p->getApacheSession($token), ' Found token session' );
|
||||
ok( $captcha = $ts->data->{captcha}, ' Found captcha value' );
|
||||
count(2);
|
||||
# Try to get captcha value
|
||||
|
||||
# Try to authenticate
|
||||
$query .= "&user=dwho&password=dwho&captcha=$captcha";
|
||||
ok(
|
||||
$res =
|
||||
$client->_post( '/', IO::String->new($query), length => length($query) ),
|
||||
'Try to auth with captcha value'
|
||||
);
|
||||
count(1);
|
||||
expectOK($res);
|
||||
my $id = expectCookie($res);
|
||||
my ( $ts, $captcha );
|
||||
ok( $ts = $client->p->getApacheSession($token), ' Found token session' );
|
||||
ok( $captcha = $ts->data->{captcha}, ' Found captcha value' );
|
||||
|
||||
# Verify auth
|
||||
ok( $res = $client->_get( '/', cookie => "lemonldap=$id" ), 'Verify auth' );
|
||||
count(1);
|
||||
expectOK($res);
|
||||
# Try to authenticate
|
||||
$query .= "&user=dwho&password=dwho&captcha=$captcha";
|
||||
ok(
|
||||
$res = $client->_post(
|
||||
'/',
|
||||
IO::String->new($query),
|
||||
length => length($query)
|
||||
),
|
||||
'Try to auth with captcha value'
|
||||
);
|
||||
expectOK($res);
|
||||
my $id = expectCookie($res);
|
||||
|
||||
# New try (with bad captcha)
|
||||
ok( $res = $client->_get( '/', accept => 'text/html' ), 'New unauth request' );
|
||||
( $host, $url, $query ) = expectForm( $res, '#', undef, 'token' );
|
||||
$query =~ s/.*\b(token=[^&]+).*/$1/;
|
||||
ok( $token = $1, ' Token value is defined' );
|
||||
count(2);
|
||||
# Verify auth
|
||||
ok( $res = $client->_get( '/', cookie => "lemonldap=$id" ), 'Verify auth' );
|
||||
expectOK($res);
|
||||
|
||||
# Try to auth with bad captcha
|
||||
$query .= '&user=dwho&password=dwho&captcha=00000';
|
||||
ok(
|
||||
$res = $client->_post(
|
||||
'/', IO::String->new($query), length => length($query)
|
||||
),
|
||||
'Try to auth with bad captcha value'
|
||||
);
|
||||
expectReject($res);
|
||||
ok(
|
||||
$res = $client->_post(
|
||||
'/', IO::String->new($query),
|
||||
length => length($query),
|
||||
accept => 'text/html',
|
||||
),
|
||||
'Verify that there is a new captcha image'
|
||||
);
|
||||
ok( $res->[2]->[0] =~ m#<img src="data:image/png;base64#,
|
||||
' New captcha image inserted' );
|
||||
count(3);
|
||||
# New try (with bad captcha)
|
||||
ok( $res = $client->_get( '/', accept => 'text/html' ),
|
||||
'New unauth request' );
|
||||
( $host, $url, $query ) = expectForm( $res, '#', undef, 'token' );
|
||||
$query =~ s/.*\b(token=[^&]+).*/$1/;
|
||||
ok( $token = $1, ' Token value is defined' );
|
||||
|
||||
# Try to auth with bad captcha
|
||||
$query .= '&user=dwho&password=dwho&captcha=00000';
|
||||
ok(
|
||||
$res = $client->_post(
|
||||
'/',
|
||||
IO::String->new($query),
|
||||
length => length($query)
|
||||
),
|
||||
'Try to auth with bad captcha value'
|
||||
);
|
||||
expectReject($res);
|
||||
ok(
|
||||
$res = $client->_post(
|
||||
'/', IO::String->new($query),
|
||||
length => length($query),
|
||||
accept => 'text/html',
|
||||
),
|
||||
'Verify that there is a new captcha image'
|
||||
);
|
||||
ok( $res->[2]->[0] =~ m#<img src="data:image/png;base64#,
|
||||
' New captcha image inserted' );
|
||||
}
|
||||
count($maintests);
|
||||
|
||||
clean_sessions();
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user