Improve unit test (#1587)
This commit is contained in:
parent
4af167ff9b
commit
f42fbdac16
|
@ -9,20 +9,19 @@ BEGIN {
|
|||
};
|
||||
}
|
||||
|
||||
my $maintests = 14;
|
||||
my $maintests = 24;
|
||||
my ( $res, $user, $pwd, $host, $url, $query );
|
||||
my $mailSend = 0;
|
||||
|
||||
SKIP: {
|
||||
eval
|
||||
'require Email::Sender::Simple;use GD::SecurityImage;use Image::Magick;';
|
||||
'require Email::Sender::Simple;use GD::SecurityImage;use Image::Magick;';
|
||||
if ($@) {
|
||||
skip 'Missing dependencies', $maintests;
|
||||
}
|
||||
|
||||
my $client = LLNG::Manager::Test->new(
|
||||
{
|
||||
ini => {
|
||||
{ ini => {
|
||||
logLevel => 'error',
|
||||
useSafeJail => 1,
|
||||
portalDisplayRegister => 1,
|
||||
|
@ -33,39 +32,81 @@ SKIP: {
|
|||
}
|
||||
);
|
||||
|
||||
# Test normal first access
|
||||
# Try to register with an alredy existing mail address
|
||||
# ------------------------
|
||||
ok(
|
||||
$res = $client->_get( '/register', accept => 'text/html' ),
|
||||
ok( $res = $client->_get( '/register', accept => 'text/html' ),
|
||||
'Unauth request',
|
||||
);
|
||||
( $host, $url, $query ) =
|
||||
expectForm( $res, '#', undef, 'firstname', 'lastname', 'mail' );
|
||||
ok(
|
||||
$query =~
|
||||
s/^.*token=([^&]+).*$/token=$1&firstname=foo&lastname=bar&mail=foobar%40badwolf.org/,
|
||||
( $host, $url, $query )
|
||||
= expectForm( $res, '#', undef, 'firstname', 'lastname', 'mail' );
|
||||
ok( $query
|
||||
=~ s/^.*token=([^&]+).*$/token=$1&firstname=who&lastname=doctor&mail=dwho%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' )
|
||||
or print STDERR Dumper( $res->[2]->[0] );
|
||||
or print STDERR Dumper( $res->[2]->[0] );
|
||||
|
||||
# Try to get captcha value
|
||||
my ( $ts, $captcha );
|
||||
ok( $ts = getCache()->get($token), ' Found token session' );
|
||||
$ts = eval { JSON::from_json($ts) };
|
||||
ok( $captcha = $ts->{captcha}, ' Found captcha value' );
|
||||
ok(
|
||||
$res->[2]->[0] =~ m%<img src="/static/common/logos/logo_llng_old.png"%,
|
||||
ok( $res->[2]->[0]
|
||||
=~ m%<img src="/static/common/logos/logo_llng_old.png"%,
|
||||
'Found custom Main Logo'
|
||||
) or print STDERR Dumper( $res->[2]->[0] );
|
||||
|
||||
$query .= "&captcha=$captcha";
|
||||
|
||||
ok(
|
||||
$res = $client->_post(
|
||||
ok( $res = $client->_post(
|
||||
'/register',
|
||||
IO::String->new($query),
|
||||
length => length($query),
|
||||
accept => 'text/html'
|
||||
),
|
||||
'Ask to create account'
|
||||
);
|
||||
|
||||
ok( $res->[2]->[0] =~ q%<span trmsg="80"></span>%,
|
||||
'Rejected -> Mail already exists' );
|
||||
ok( $res->[2]->[0]
|
||||
!~ m%<form action="#" method="post" class="login" role="form">%,
|
||||
'No form found'
|
||||
);
|
||||
|
||||
# Test normal first access
|
||||
# ------------------------
|
||||
ok( $res = $client->_get( '/register', accept => 'text/html' ),
|
||||
'Unauth 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' )
|
||||
or print STDERR Dumper( $res->[2]->[0] );
|
||||
|
||||
# Try to get captcha value
|
||||
my ( $ts, $captcha );
|
||||
ok( $ts = getCache()->get($token), ' Found token session' );
|
||||
$ts = eval { JSON::from_json($ts) };
|
||||
ok( $captcha = $ts->{captcha}, ' Found captcha value' );
|
||||
ok( $res->[2]->[0]
|
||||
=~ m%<img src="/static/common/logos/logo_llng_old.png"%,
|
||||
'Found custom Main Logo'
|
||||
) or print STDERR Dumper( $res->[2]->[0] );
|
||||
|
||||
$query .= "&captcha=$captcha";
|
||||
|
||||
ok( $res = $client->_post(
|
||||
'/register',
|
||||
IO::String->new($query),
|
||||
length => length($query),
|
||||
|
@ -80,8 +121,7 @@ s/^.*token=([^&]+).*$/token=$1&firstname=foo&lastname=bar&mail=foobar%40badwolf.
|
|||
$query = $1;
|
||||
ok( $query =~ /register_token=/, 'Found register_token' );
|
||||
|
||||
ok(
|
||||
$res = $client->_get(
|
||||
ok( $res = $client->_get(
|
||||
'/register',
|
||||
query => $query,
|
||||
accept => 'text/html'
|
||||
|
@ -90,9 +130,8 @@ s/^.*token=([^&]+).*$/token=$1&firstname=foo&lastname=bar&mail=foobar%40badwolf.
|
|||
);
|
||||
expectOK($res);
|
||||
|
||||
ok(
|
||||
mail() =~
|
||||
m#Your login is.+?<b>(\w+)</b>.*?Your password is.+?<b>(.*?)</b>#s,
|
||||
ok( mail()
|
||||
=~ m#Your login is.+?<b>(\w+)</b>.*?Your password is.+?<b>(.*?)</b>#s,
|
||||
'Found user and password'
|
||||
);
|
||||
$user = $1;
|
||||
|
@ -102,8 +141,7 @@ s/^.*token=([^&]+).*$/token=$1&firstname=foo&lastname=bar&mail=foobar%40badwolf.
|
|||
# Try to authenticate
|
||||
$query = '&user=fbar&password=fbar';
|
||||
|
||||
ok(
|
||||
$res = $client->_post(
|
||||
ok( $res = $client->_post(
|
||||
'/', IO::String->new($query),
|
||||
length => length($query),
|
||||
accept => 'text/html'
|
||||
|
|
Loading…
Reference in New Issue
Block a user